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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
09267d6088e8fc215f82f9a623dee98ddb467dd2 | 12,793 | cpp | C++ | src/dataServer/implementation/VirtualContentFactory_type1.cpp | fmidev/smartmet-library-grid-content | 303483967a1248002369893cf43b4ca03f8385d9 | [
"MIT"
] | null | null | null | src/dataServer/implementation/VirtualContentFactory_type1.cpp | fmidev/smartmet-library-grid-content | 303483967a1248002369893cf43b4ca03f8385d9 | [
"MIT"
] | null | null | null | src/dataServer/implementation/VirtualContentFactory_type1.cpp | fmidev/smartmet-library-grid-content | 303483967a1248002369893cf43b4ca03f8385d9 | [
"MIT"
] | null | null | null | #include "VirtualContentFactory_type1.h"
#include "VirtualMessage.h"
#include <grid-files/common/ShowFunction.h>
#include <macgyver/Exception.h>
#include <grid-files/common/GeneralFunctions.h>
#include <grid-files/identification/GridDef.h>
#define FUNCTION_TRACE FUNCTION_TRACE_OFF
namespace SmartMet
{
namespace DataServer
{
VirtualContentFactory_type1::VirtualContentFactory_type1()
{
FUNCTION_TRACE
try
{
mLastCheck = 0;
}
catch (...)
{
throw Fmi::Exception(BCP,"Operation failed!",nullptr);
}
}
VirtualContentFactory_type1::~VirtualContentFactory_type1()
{
FUNCTION_TRACE
try
{
}
catch (...)
{
Fmi::Exception exception(BCP,"Destructor failed",nullptr);
exception.printError();
}
}
void VirtualContentFactory_type1::init(std::string definitionFileName)
{
FUNCTION_TRACE
try
{
mContentDefinitionFile.init(definitionFileName);
}
catch (...)
{
throw Fmi::Exception(BCP,"Operation failed!",nullptr);
}
}
void VirtualContentFactory_type1::addFile(T::ProducerInfo& producerInfo,T::GenerationInfo& generationInfo,T::FileInfo& fileInfo,T::ContentInfoList& contentInfoList,VirtualGridFilePtr_map& gridFileMap)
{
FUNCTION_TRACE
try
{
time_t tt = time(nullptr);
if ((tt - mLastCheck) > 10)
{
mContentDefinitionFile.checkUpdates();
mLastCheck = tt;
}
uint len = contentInfoList.getLength();
for (uint t=0; t<len; t++)
{
T::ContentInfo *contentInfo = contentInfoList.getContentInfoByIndex(t);
addContent(producerInfo,generationInfo,fileInfo,*contentInfo,gridFileMap);
}
}
catch (...)
{
throw Fmi::Exception(BCP,"Operation failed!",nullptr);
}
}
void VirtualContentFactory_type1::addContent(T::ProducerInfo& producerInfo,T::GenerationInfo& generationInfo,T::FileInfo& fileInfo,T::ContentInfo& contentInfo,VirtualGridFilePtr_map& gridFileMap)
{
FUNCTION_TRACE
try
{
VirtualContentDefinition_vec contentDefinitionList;
mContentDefinitionFile.getContentDefinitions(contentInfo,toLowerString(producerInfo.mName),contentDefinitionList);
time_t minDeletionTime = 0;
if (contentDefinitionList.size() > 0)
{
GRID::GridFile_sptr sourceGridFile = mGridFileManager->getFileByIdNoMapping(fileInfo.mFileId);
if (!sourceGridFile)
{
//printf("*** GRID FILE NOT FOUND %u\n",fileInfo.mFileId);
return; // File not found
}
time_t deletionTime = sourceGridFile->getDeletionTime();
if (deletionTime != 0)
{
if ((time(nullptr) + 300) > deletionTime)
{
// The grid file will be deleted soon. We should not access it anymore.
return;
}
if (minDeletionTime == 0 || deletionTime < minDeletionTime)
minDeletionTime = deletionTime;
}
for (auto contentDef = contentDefinitionList.begin(); contentDef != contentDefinitionList.end(); ++contentDef)
{
char filename[300];
filename[0] = '\0';
sprintf(filename,"%s-%s-%s-%s-%s-%s-%s-%u-%s",
contentDef->mVirtualParameter.mProducerName.c_str(),
contentDef->mVirtualParameter.mParameterName.c_str(),
contentDef->mVirtualParameter.mGeometryId.c_str(),
contentDef->mVirtualParameter.mLevelId.c_str(),
contentDef->mVirtualParameter.mLevel.c_str(),
contentDef->mVirtualParameter.mForecastType.c_str(),
contentDef->mVirtualParameter.mForecastNumber.c_str(),
generationInfo.mGenerationId,
contentInfo.getForecastTime());
if (gridFileMap.find(std::string(filename)) == gridFileMap.end())
{
Identification::FmiParameterDef def;
if (Identification::gridDef.getFmiParameterDefByName(contentDef->mVirtualParameter.mParameterName.c_str(),def))
{
bool componentsFound = true;
bool fileExists = false;
uint virtualFileId = 0;
std::vector<GRID::SourceMessage> sourceMessages;
for (auto sourceParam = contentDef->mSourceParameters.begin(); sourceParam != contentDef->mSourceParameters.end() && componentsFound; ++sourceParam)
{
T::ContentInfoList contentList;
T::ContentInfo *cInfo = nullptr;
if (contentDef->mSourceParameters.size() == 1)
{
cInfo = &contentInfo;
}
else
{
int levelId = contentInfo.mFmiParameterLevelId;
if (sourceParam->mLevelId > " ")
levelId = atoi(sourceParam->mLevelId.c_str());
int level = contentInfo.mParameterLevel;
if (sourceParam->mLevel > " ")
level = atoi(sourceParam->mLevel.c_str());
std::string producerName = producerInfo.mName;
if (sourceParam->mProducerName > " ")
producerName = sourceParam->mProducerName;
int forecastType = contentInfo.mForecastType;
if (sourceParam->mForecastType > " ")
forecastType = atoi(sourceParam->mForecastType.c_str());
int forecastNumber = contentInfo.mForecastNumber;
if (sourceParam->mForecastNumber > " ")
forecastNumber = atoi(sourceParam->mForecastNumber.c_str());
int geometryId = contentInfo.mGeometryId;
if (sourceParam->mGeometryId > " ")
geometryId = atoi(sourceParam->mGeometryId.c_str());
mContentServer->getContentListByParameterGenerationIdAndForecastTime(0,contentInfo.mGenerationId,T::ParamKeyTypeValue::FMI_NAME,sourceParam->mParameterName,
levelId,level,forecastType,forecastNumber,geometryId,contentInfo.getForecastTime(),contentList);
//mContentServer->getContentListByParameterAndProducerName(0,producerName,T::ParamKeyTypeValue::FMI_NAME,sourceParam->mParameterName,T::ParamLevelIdTypeValue::FMI,levelId,level,level,forecastType,forecastNumber,geometryId,contentInfo.mForecastTime,contentInfo.mForecastTime,0,contentList);
uint len = contentList.getLength();
for (uint t = 0; t<len; t++)
{
T::ContentInfo *ci = contentList.getContentInfoByIndex(t);
if (ci->mForecastTimeUTC == contentInfo.mForecastTimeUTC)
{
if (ci->mGeometryId == contentInfo.mGeometryId)
{
T::GenerationInfo gInfo;
mContentServer->getGenerationInfoById(0,ci->mGenerationId,gInfo);
if (ci->mGenerationId == contentInfo.mGenerationId || gInfo.mAnalysisTime == generationInfo.mAnalysisTime)
{
cInfo = ci;
}
}
}
}
}
if (cInfo == nullptr || (contentList.getLength() == 1 && cInfo->mForecastTimeUTC != contentInfo.mForecastTimeUTC))
{
// Not found
componentsFound = false;
}
else
{
if (sourceParam == contentDef->mSourceParameters.begin())
{
// Checking if the virtual file is already registered to the contentServer.
if (gridFileMap.find(std::string(filename)) != gridFileMap.end())
{
fileExists = true;
}
else
{
T::FileInfo tmpFileInfo;
if (mContentServer->getFileInfoByName(0,std::string(filename),tmpFileInfo) == 0)
{
// The content is already registered.
GRID::GridFile_sptr vGridFile = mGridFileManager->getFileByIdNoMapping(tmpFileInfo.mFileId);
if (vGridFile)
{
fileExists = true; // File is already in the file storage
}
else
{
virtualFileId = tmpFileInfo.mFileId;
}
}
}
}
GRID::GridFile_sptr sGridFile = mGridFileManager->getFileByIdNoMapping(cInfo->mFileId);
if (!sGridFile)
componentsFound = false;
else
sourceMessages.emplace_back(GRID::SourceMessage(sGridFile,cInfo->mMessageIndex));
}
}
if (!fileExists && componentsFound && filename[0] != '\0')
{
GRID::VirtualGridFile *virtualGridFile = new GRID::VirtualGridFile();
virtualGridFile->setFileName(filename);
virtualGridFile->setFileId(virtualFileId);
virtualGridFile->setProducerId(contentInfo.mProducerId);
virtualGridFile->setGenerationId(contentInfo.mGenerationId);
virtualGridFile->setSourceId(contentInfo.mSourceId);
virtualGridFile->setDeletionTime(minDeletionTime);
for (auto sm = sourceMessages.begin(); sm != sourceMessages.end(); ++sm)
virtualGridFile->addPhysicalGridFile(sm->first);
GRID::VirtualMessage *virtualMessage = new GRID::VirtualMessage(virtualGridFile,contentDef->mVirtualParameter,sourceMessages);
virtualMessage->setFunction(mFunctionCollection,mLuaFileCollection,contentDef->mFunctionName,contentDef->mFunctionCallMethod,contentDef->mFunctionParameters);
virtualGridFile->addMessage(virtualMessage);
T::ContentInfo *newContentInfo = virtualMessage->getContentInfo();
Identification::NewbaseParameterDef newbaseDef;
Identification::gridDef.getNewbaseParameterDefByFmiId(def.mFmiParameterId,newbaseDef);
newContentInfo->mFileId = 0;
newContentInfo->mFileType = T::FileTypeValue::Virtual;
newContentInfo->mMessageIndex = 0;
newContentInfo->mProducerId = contentInfo.mProducerId;
newContentInfo->mGenerationId = contentInfo.mGenerationId;
newContentInfo->setForecastTime(contentInfo.getForecastTime());
newContentInfo->mFmiParameterId = def.mFmiParameterId;
newContentInfo->setFmiParameterName(def.mParameterName);
//newContentInfo->mGribParameterId = 0;
//newContentInfo->mNewbaseParameterId = newbaseDef.mNewbaseParameterId;
//newContentInfo->setNewbaseParameterName(newbaseDef.mParameterName);
if (contentDef->mVirtualParameter.mLevelId > " ")
newContentInfo->mFmiParameterLevelId = atoi(contentDef->mVirtualParameter.mLevelId.c_str());
else
newContentInfo->mFmiParameterLevelId = contentInfo.mFmiParameterLevelId;
//newContentInfo->mGrib1ParameterLevelId = contentInfo.mGrib1ParameterLevelId;
//newContentInfo->mGrib2ParameterLevelId = contentInfo.mGrib2ParameterLevelId;
if (contentDef->mVirtualParameter.mLevel > " ")
newContentInfo->mParameterLevel = atoi(contentDef->mVirtualParameter.mLevel.c_str());
else
newContentInfo->mParameterLevel = contentInfo.mParameterLevel;
if (contentDef->mVirtualParameter.mForecastType > " ")
newContentInfo->mForecastType = atoi(contentDef->mVirtualParameter.mForecastType.c_str());
else
newContentInfo->mForecastType = contentInfo.mForecastType;
if (contentDef->mVirtualParameter.mForecastNumber > " ")
newContentInfo->mForecastNumber = atoi(contentDef->mVirtualParameter.mForecastNumber.c_str());
else
newContentInfo->mForecastNumber = contentInfo.mForecastNumber;
//newContentInfo->mServerFlags = contentInfo.mServerFlags;
newContentInfo->mFlags = T::ContentInfo::Flags::VirtualContent;
newContentInfo->mSourceId = contentInfo.mSourceId;
newContentInfo->mGeometryId = contentInfo.mGeometryId;
newContentInfo->mModificationTime = contentInfo.mModificationTime;
gridFileMap.insert(std::pair<std::string,GRID::VirtualGridFilePtr>(std::string(filename),virtualGridFile));
}
}
else
{
// UNKNOWN PARAMETER
}
}
}
}
}
catch (...)
{
Fmi::Exception exception(BCP,"Operation failed!",nullptr);
exception.printError();
throw exception;
}
}
}
}
| 36.973988 | 305 | 0.612288 | [
"vector"
] |
092bdd559a5196fd2db608937fccacc3570696f8 | 3,278 | hpp | C++ | src/frovedis/ml/clustering/linkage.hpp | XpressAI/frovedis | bda0f2c688fb832671c5b542dd8df1c9657642ff | [
"BSD-2-Clause"
] | 63 | 2018-06-21T14:11:59.000Z | 2022-03-30T11:24:36.000Z | src/frovedis/ml/clustering/linkage.hpp | XpressAI/frovedis | bda0f2c688fb832671c5b542dd8df1c9657642ff | [
"BSD-2-Clause"
] | 5 | 2018-09-22T14:01:53.000Z | 2021-12-27T16:11:05.000Z | src/frovedis/ml/clustering/linkage.hpp | XpressAI/frovedis | bda0f2c688fb832671c5b542dd8df1c9657642ff | [
"BSD-2-Clause"
] | 12 | 2018-08-23T15:59:44.000Z | 2022-02-20T06:47:22.000Z | #ifndef _LINKAGE_HPP_
#define _LINKAGE_HPP_
namespace frovedis {
// Average linkage
template <class T>
struct average_linkage {
average_linkage() {}
average_linkage(size_t n_): n(n_) {}
void update_distance(std::vector<T>& D,
std::vector<size_t>& size,
size_t x, size_t y) {
size_t x_indx = 0, y_indx = 0;
auto dptr = D.data();
auto szptr = size.data();
//get the original numbers of posize_ts in clusters x and y
auto nx = szptr[x];
auto ny = szptr[y];
szptr[x] = 0; // cluster x will be dropped.
szptr[y] = nx + ny; // cluster y will be replaced with the new cluster
#pragma _NEC ivdep
for(size_t i = 0; i < n; ++i) {
auto ni = szptr[i];
if(ni == 0 || i == y) continue;
if (i < x) x_indx = (n * i - (i * (i + 1) / 2) + (x - i - 1));
else x_indx = (n * x - (x * (x + 1) / 2) + (i - x - 1));
if (i < y) y_indx = (n * i - (i * (i + 1) / 2) + (y - i - 1));
else y_indx = (n * y - (y * (y + 1) / 2) + (i - y - 1));
dptr[y_indx] = ((nx * dptr[x_indx] + ny * dptr[y_indx]) / (nx + ny));
}
}
size_t n;
SERIALIZE(n)
};
template <class T>
struct complete_linkage {
complete_linkage() {}
complete_linkage(size_t n_): n(n_) {}
void update_distance(std::vector<T>& D,
std::vector<size_t>& size,
size_t x, size_t y) {
size_t x_indx = 0, y_indx = 0;
auto dptr = D.data();
auto szptr = size.data();
// cluster y will be replaced with the new cluster
szptr[y] = szptr[x] + szptr[y];
// cluster x will be dropped.
szptr[x] = 0;
#pragma _NEC ivdep
for(size_t i = 0; i < n; ++i){
auto ni = szptr[i];
if(ni == 0 || i == y) continue;
if (i < x) x_indx = (n * i - (i * (i + 1) / 2) + (x - i - 1));
else x_indx = (n * x - (x * (x + 1) / 2) + (i - x - 1));
if (i < y) y_indx = (n * i - (i * (i + 1) / 2) + (y - i - 1));
else y_indx = (n * y - (y * (y + 1) / 2) + (i - y - 1));
dptr[y_indx] = (dptr[x_indx] > dptr[y_indx]) ?
dptr[x_indx] : dptr[y_indx];
}
}
size_t n;
SERIALIZE(n)
};
template <class T>
struct single_linkage {
single_linkage() {}
single_linkage(size_t n_): n(n_) {}
void update_distance(std::vector<T>& D,
std::vector<size_t>& size,
size_t x, size_t y) {
size_t x_indx = 0, y_indx = 0;
auto dptr = D.data();
auto szptr = size.data();
// cluster y will be replaced with the new cluster
szptr[y] = szptr[x] + szptr[y];
// cluster x will be dropped.
szptr[x] = 0;
#pragma _NEC ivdep
for(size_t i = 0; i < n; ++i){
auto ni = szptr[i];
if(ni == 0 || i == y) continue;
if (i < x) x_indx = (n * i - (i * (i + 1) / 2) + (x - i - 1));
else x_indx = (n * x - (x * (x + 1) / 2) + (i - x - 1));
if (i < y) y_indx = (n * i - (i * (i + 1) / 2) + (y - i - 1));
else y_indx = (n * y - (y * (y + 1) / 2) + (i - y - 1));
dptr[y_indx] = (dptr[x_indx] < dptr[y_indx]) ?
dptr[x_indx] : dptr[y_indx];
}
}
size_t n;
SERIALIZE(n)
};
}
#endif
| 32.78 | 76 | 0.471019 | [
"vector"
] |
092f75aba8bd2648a6a3e2274fa974dfc8f364fe | 16,520 | cpp | C++ | widgets/slider/slider_impl.cpp | alecmus/lecui | 080d06533878394c20c65e333dc892afafdbf910 | [
"MIT"
] | 5 | 2021-05-02T12:13:45.000Z | 2022-01-31T19:51:32.000Z | widgets/slider/slider_impl.cpp | alecmus/lecui | 080d06533878394c20c65e333dc892afafdbf910 | [
"MIT"
] | 11 | 2021-05-16T14:56:01.000Z | 2021-08-01T17:47:04.000Z | widgets/slider/slider_impl.cpp | alecmus/lecui | 080d06533878394c20c65e333dc892afafdbf910 | [
"MIT"
] | 2 | 2021-05-15T20:16:46.000Z | 2021-06-20T12:58:51.000Z | //
// slider_impl.cpp - slider_impl implementation
//
// lecui user interface library, part of the liblec library
// Copyright (c) 2019 Alec Musasa (alecmus at live dot com)
//
// Released under the MIT license. For full details see the
// file LICENSE.txt
//
#include "slider_impl.h"
#include "../label/label_impl.h"
namespace liblec {
namespace lecui {
widgets::slider_impl::slider_impl(containers::page& page,
const std::string& alias,
IDWriteFactory* p_directwrite_factory) :
widget_impl(page, alias),
_p_brush(nullptr),
_p_brush_fill(nullptr),
_p_brush_border(nullptr),
_p_brush_knob(nullptr),
_p_brush_knob_hot(nullptr),
_p_brush_knob_border(nullptr),
_p_brush_tick(nullptr),
_p_brush_disabled(nullptr),
_p_brush_selected(nullptr),
_p_text_format(nullptr),
_p_directwrite_factory(p_directwrite_factory),
_p_text_layout(nullptr),
_perc_along(0.f) {}
widgets::slider_impl::~slider_impl() { discard_resources(); }
widgets::widget_type
widgets::slider_impl::type() {
return lecui::widgets::widget_type::slider;
}
HRESULT widgets::slider_impl::create_resources(
ID2D1HwndRenderTarget* p_render_target) {
_specs_old = _specs;
_is_static = (_specs.events().slider == nullptr && _specs.events().click == nullptr && _specs.events().action == nullptr);
_h_cursor = get_cursor(_specs.cursor());
HRESULT hr = S_OK;
if (SUCCEEDED(hr))
hr = p_render_target->CreateSolidColorBrush(convert_color(_specs.color_border()),
&_p_brush_border);
if (SUCCEEDED(hr))
hr = p_render_target->CreateSolidColorBrush(convert_color(_specs.color_knob()),
&_p_brush_knob);
if (SUCCEEDED(hr))
hr = p_render_target->CreateSolidColorBrush(convert_color(_specs.color_knob_hot()),
&_p_brush_knob_hot);
if (SUCCEEDED(hr))
hr = p_render_target->CreateSolidColorBrush(convert_color(_specs.color_knob_border()),
&_p_brush_knob_border);
if (SUCCEEDED(hr))
hr = p_render_target->CreateSolidColorBrush(convert_color(_specs.color_tick()),
&_p_brush_tick);
if (SUCCEEDED(hr))
hr = p_render_target->CreateSolidColorBrush(convert_color(_specs.color_disabled()),
&_p_brush_disabled);
if (SUCCEEDED(hr))
hr = p_render_target->CreateSolidColorBrush(convert_color(_specs.color_selected()),
&_p_brush_selected);
if (SUCCEEDED(hr))
hr = p_render_target->CreateSolidColorBrush(convert_color(_specs.color_text()),
&_p_brush);
if (SUCCEEDED(hr))
hr = p_render_target->CreateSolidColorBrush(convert_color(_specs.color_fill()),
&_p_brush_fill);
if (SUCCEEDED(hr)) {
// Create a DirectWrite text format object.
hr = _p_directwrite_factory->CreateTextFormat(
convert_string(_specs.font()).c_str(),
NULL,
DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
convert_fontsize_to_dip(_specs.font_size()),
L"", //locale
&_p_text_format
);
}
if (SUCCEEDED(hr)) {
_p_text_format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
_p_text_format->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
make_single_line(_p_directwrite_factory, _p_text_format);
}
_resources_created = true;
return hr;
}
void widgets::slider_impl::discard_resources() {
_resources_created = false;
safe_release(&_p_brush);
safe_release(&_p_brush_fill);
safe_release(&_p_brush_border);
safe_release(&_p_brush_knob);
safe_release(&_p_brush_knob_hot);
safe_release(&_p_brush_knob_border);
safe_release(&_p_brush_tick);
safe_release(&_p_brush_disabled);
safe_release(&_p_brush_selected);
safe_release(&_p_text_format);
}
D2D1_RECT_F&
widgets::slider_impl::render(ID2D1HwndRenderTarget* p_render_target,
const D2D1_SIZE_F& change_in_size, const D2D1_POINT_2F& offset, const bool& render) {
if (_specs_old != _specs) {
log("specs changed: " + _alias);
_specs_old = _specs;
discard_resources();
}
if (!_resources_created)
create_resources(p_render_target);
_rect = position(_specs.rect(), _specs.on_resize(), change_in_size.width, change_in_size.height);
_rect.left -= offset.x;
_rect.right -= offset.x;
_rect.top -= offset.y;
_rect.bottom -= offset.y;
if (!render || !_visible)
return _rect;
// function for snapping value to ticks
auto do_snap = [&](float& value) {
std::vector<float> snap_to;
const float major_div = _specs.major_tick_unit();
const float minor_div = _specs.major_tick_unit() / (_specs.minor_tick_count() + 1);
for (float p = _specs.range().minimum; p <= _specs.range().maximum; p += _specs.major_tick_unit()) {
// add major div to snap vector
snap_to.push_back(p);
// add minor divs to snap vector
for (float v = p + minor_div; v < smallest(p + major_div, _specs.range().maximum); v += minor_div)
snap_to.push_back(v);
}
float snap_value = _specs.range().minimum;
for (const auto& v : snap_to) {
auto lower = v;
auto higher = v + minor_div;
if (value >= lower && value <= higher) {
if (value < lower + (minor_div / 2.f))
snap_value = v;
else
snap_value = v + minor_div;
}
}
value = snap_value;
value = largest(value, _specs.range().minimum);
value = smallest(value, _specs.range().maximum);
};
if (abs(_rect.right - _rect.left) > abs(_rect.bottom - _rect.top)) {
// orient horizontally
// starting and ending points of slider
const D2D1_POINT_2F start = { _rect.left + _specs.knob_radius(), _rect.top + _specs.knob_radius() };
const D2D1_POINT_2F end = { _rect.right - _specs.knob_radius(), _rect.top + _specs.knob_radius() };
// draw slide
const D2D1_RECT_F slide_rect = {
start.x - (_specs.slide_thickness() / 2.f),
start.y - (_specs.slide_thickness() / 2.f),
end.x + (_specs.slide_thickness() / 2.f),
end.y + (_specs.slide_thickness() / 2.f)
};
const D2D1_ROUNDED_RECT slide_rect_rounded = { slide_rect, _specs.slide_thickness() / 2.f, _specs.slide_thickness() / 2.f };
p_render_target->FillRoundedRectangle(&slide_rect_rounded, _p_brush_fill);
p_render_target->DrawRoundedRectangle(&slide_rect_rounded, _p_brush_border, _specs.border());
if (_pressed) {
// compute new value
D2D1_RECT_F rect = slide_rect;
rect.left = start.x;
rect.right = end.x;
scale_RECT(rect, get_dpi_scale());
_perc_along = 100.f * (_point.x - rect.left) / (rect.right - rect.left);
_perc_along = largest(_perc_along, 0.f);
_perc_along = smallest(_perc_along, 100.f);
// calculate value
_specs.value((_specs.range().maximum - _specs.range().minimum) * _perc_along / 100.f);
}
// snap the value to ticks
if (_specs.snap_to_ticks())
do_snap(_specs.value());
// draw ticks. to-do: remove magic numbers
const float y = slide_rect.bottom + 5.f;
const float y_major_tick = y + 6.f;
const float y_minor_tick = y + 2.5f;
const float major_div = (_specs.major_tick_unit() / (_specs.range().maximum - _specs.range().minimum)) * (end.x - start.x);
const float minor_div = major_div / (_specs.minor_tick_count() + 1);
auto value = 0.f;
const long major_ticks = static_cast<long>(floor((_specs.range().maximum - _specs.range().minimum) / _specs.major_tick_unit()));
const long minor_ticks = major_ticks * _specs.minor_tick_count();
long minor_tick_count = 0;
for (long n_major = 0; n_major < major_ticks + 1; n_major++) {
const float x_major = start.x + major_div * n_major;
float lower_margin = y;
if (_specs.show_tick_marks()) {
lower_margin = y_major_tick;
// draw major ticks
p_render_target->DrawLine({ x_major, y }, { x_major, y_major_tick }, _p_brush_tick, 0.5f);
for (long n_minor = 1; minor_tick_count < minor_ticks && n_minor < _specs.minor_tick_count() + 1; n_minor++) {
const float x_minor = x_major + minor_div * n_minor;
// draw minor ticks
p_render_target->DrawLine({ x_minor, y }, { x_minor, y_minor_tick }, _p_brush_tick, 0.5f);
minor_tick_count++;
}
}
// draw tick label
if (_specs.show_tick_labels()) {
D2D1_RECT_F max_rect = { 0.f, 0.f, major_div, 20.f };
const auto label = round_off::to_string(value, 0);
value += _specs.major_tick_unit();
auto label_rect = widgets::measure_label(_p_directwrite_factory, label,
_specs.font(), _specs.font_size(), text_alignment::center, paragraph_alignment::middle, max_rect);
D2D1_RECT_F optimal_rect = {
x_major - (label_rect.right - label_rect.left) / 2.f,
lower_margin + .5f,
x_major + (label_rect.right - label_rect.left) / 2.f,
lower_margin + .5f + (label_rect.bottom - label_rect.top)
};
// create a text layout
HRESULT hr = _p_directwrite_factory->CreateTextLayout(convert_string(label).c_str(),
(UINT32)label.length(), _p_text_format, optimal_rect.right - optimal_rect.left,
optimal_rect.bottom - optimal_rect.top, &_p_text_layout);
if (SUCCEEDED(hr)) {
// draw the text layout
p_render_target->DrawTextLayout(D2D1_POINT_2F{ optimal_rect.left, optimal_rect.top },
_p_text_layout, _is_enabled ?
_p_brush : _p_brush_disabled, D2D1_DRAW_TEXT_OPTIONS_CLIP);
}
// release the text layout
safe_release(&_p_text_layout);
}
}
// draw knob
const D2D1_POINT_2F position = {
start.x + (_specs.value() / (_specs.range().maximum - _specs.range().minimum)) * (end.x - start.x),
start.y };
const D2D1_RECT_F knob_rect = {
position.x - _specs.knob_radius(),
position.y - _specs.knob_radius(),
position.x + _specs.knob_radius(),
position.y + _specs.knob_radius(),
};
// draw knob
const D2D1_ROUNDED_RECT _knob_rect_round = { knob_rect, _specs.knob_radius(), _specs.knob_radius() };
p_render_target->FillRoundedRectangle(&_knob_rect_round, (!_is_static && _is_enabled && _hit) ? _p_brush_knob_hot : _p_brush_knob);
p_render_target->DrawRoundedRectangle(&_knob_rect_round, _selected ? _p_brush_selected : _p_brush_knob_border, _specs.border());
}
else {
// orient vertically
// starting and ending points of slider
const D2D1_POINT_2F start = { _rect.left + _specs.knob_radius(), _rect.bottom - _specs.knob_radius() };
const D2D1_POINT_2F end = { _rect.left + _specs.knob_radius(), _rect.top + _specs.knob_radius() };
// draw slide
const D2D1_RECT_F slide_rect = {
start.x - (_specs.slide_thickness() / 2.f),
start.y + (_specs.slide_thickness() / 2.f),
end.x + (_specs.slide_thickness() / 2.f),
end.y - (_specs.slide_thickness() / 2.f)
};
const D2D1_ROUNDED_RECT slide_rect_rounded = { slide_rect, _specs.slide_thickness() / 2.f, _specs.slide_thickness() / 2.f };
p_render_target->FillRoundedRectangle(&slide_rect_rounded, _p_brush_fill);
p_render_target->DrawRoundedRectangle(&slide_rect_rounded, _p_brush_border, _specs.border());
if (_pressed) {
// compute new value
D2D1_RECT_F rect = slide_rect;
rect.bottom = start.y;
rect.top = end.y;
scale_RECT(rect, get_dpi_scale());
_perc_along = 100.f * (rect.bottom - _point.y) / (rect.bottom - rect.top);
_perc_along = largest(_perc_along, 0.f);
_perc_along = smallest(_perc_along, 100.f);
// calculate value
_specs.value() = (_specs.range().maximum - _specs.range().minimum) * _perc_along / 100.f;
}
// snap the value to ticks
if (_specs.snap_to_ticks())
do_snap(_specs.value());
// draw ticks. to-do: remove magic numbers
const float x = slide_rect.right + 5.f;
const float x_major_tick = x + 6.f;
const float x_minor_tick = x + 2.5f;
const float major_div = (_specs.major_tick_unit() / (_specs.range().maximum - _specs.range().minimum)) * (start.y - end.y);
const float minor_div = major_div / (_specs.minor_tick_count() + 1);
auto value = 0.f;
const long major_ticks = static_cast<long>(floor((_specs.range().maximum - _specs.range().minimum) / _specs.major_tick_unit()));
const long minor_ticks = major_ticks * _specs.minor_tick_count();
long minor_tick_count = 0;
for (long n_major = 0; n_major < major_ticks + 1; n_major++) {
const float y_major = start.y - major_div * n_major;
float lower_margin = x;
if (_specs.show_tick_marks()) {
lower_margin = x_major_tick;
// draw major ticks
p_render_target->DrawLine({ x, y_major }, { x_major_tick, y_major }, _p_brush_tick, 0.5f);
for (long n_minor = 1; minor_tick_count < minor_ticks && n_minor < _specs.minor_tick_count() + 1; n_minor++) {
const float y_minor = y_major - minor_div * n_minor;
// draw minor ticks
p_render_target->DrawLine({ x, y_minor }, { x_minor_tick, y_minor }, _p_brush_tick, 0.5f);
minor_tick_count++;
}
}
// draw tick label
if (_specs.show_tick_labels()) {
D2D1_RECT_F max_rect = { 0.f, 0.f, _rect.right - x_minor_tick - .5f, major_div };
const auto label = round_off::to_string(value, 0);
value += _specs.major_tick_unit();
auto label_rect = widgets::measure_label(_p_directwrite_factory, label,
_specs.font(), _specs.font_size(), text_alignment::center, paragraph_alignment::middle, max_rect);
D2D1_RECT_F optimal_rect = {
lower_margin + .5f,
y_major - (label_rect.bottom - label_rect.top) / 2.f,
lower_margin + .5f + (label_rect.right - label_rect.left),
y_major + (label_rect.bottom - label_rect.top) / 2.f
};
// create a text layout
HRESULT hr = _p_directwrite_factory->CreateTextLayout(convert_string(label).c_str(),
(UINT32)label.length(), _p_text_format, optimal_rect.right - optimal_rect.left,
optimal_rect.bottom - optimal_rect.top, &_p_text_layout);
if (SUCCEEDED(hr)) {
// draw the text layout
p_render_target->DrawTextLayout(D2D1_POINT_2F{ optimal_rect.left, optimal_rect.top },
_p_text_layout, _is_enabled ?
_p_brush : _p_brush_disabled, D2D1_DRAW_TEXT_OPTIONS_CLIP);
}
// release the text layout
safe_release(&_p_text_layout);
}
}
// draw knob
const D2D1_POINT_2F position = { start.x,
start.y - (_specs.value() / (_specs.range().maximum - _specs.range().minimum)) * (start.y - end.y)};
const D2D1_RECT_F knob_rect = {
position.x - _specs.knob_radius(),
position.y - _specs.knob_radius(),
position.x + _specs.knob_radius(),
position.y + _specs.knob_radius(),
};
// draw knob
const D2D1_ROUNDED_RECT _knob_rect_round = { knob_rect, _specs.knob_radius(), _specs.knob_radius() };
p_render_target->FillRoundedRectangle(&_knob_rect_round, (!_is_static && _is_enabled && _hit) ? _p_brush_knob_hot : _p_brush_knob);
p_render_target->DrawRoundedRectangle(&_knob_rect_round, _selected ? _p_brush_selected : _p_brush_knob_border, _specs.border());
}
return _rect;
}
void widgets::slider_impl::on_click() {
if (_specs.events().slider)
_specs.events().slider(_specs.value());
if (_specs.events().click)
_specs.events().click();
if (_specs.events().action)
_specs.events().action();
}
void widgets::slider_impl::on_action() {
if (_specs.events().slider)
_specs.events().slider(_specs.value());
if (_specs.events().action)
_specs.events().action();
}
void widgets::slider_impl::on_right_click() {
if (_specs.events().right_click)
_specs.events().right_click();
}
bool widgets::slider_impl::contains(const D2D1_POINT_2F& point) {
// capture the point
_point = point;
if (point.x == 0.f && point.y == 0.f)
return false;
D2D1_RECT_F rect = _rect;
scale_RECT(rect, get_dpi_scale());
if (point.x >= rect.left && point.x <= rect.right &&
point.y >= rect.top && point.y <= rect.bottom)
return contains();
else {
if (_pressed)
return true;
else
return false;
}
}
bool widgets::slider_impl::contains() { return true; }
bool widgets::slider_impl::hit(const bool& hit) {
if (_is_static || hit == _hit) {
if (_pressed)
return true;
else
return false;
}
_hit = hit;
return true;
}
widgets::slider&
widgets::slider_impl::specs() { return _specs; }
widgets::slider&
widgets::slider_impl::operator()() { return specs(); }
}
}
| 34.633124 | 135 | 0.672881 | [
"render",
"object",
"vector"
] |
092fd465bfe90ef4daf858c5894daf86a7a15f02 | 839,367 | cpp | C++ | test/generated/bidi_test_829.cpp | Ryan-rsm-McKenzie/text | 15aaea4297e00ec4c74295e7913ead79c90e1502 | [
"BSL-1.0"
] | 265 | 2017-07-09T23:23:48.000Z | 2022-03-24T10:14:19.000Z | test/generated/bidi_test_829.cpp | Ryan-rsm-McKenzie/text | 15aaea4297e00ec4c74295e7913ead79c90e1502 | [
"BSL-1.0"
] | 185 | 2017-08-30T16:44:51.000Z | 2021-08-13T12:02:46.000Z | test/generated/bidi_test_829.cpp | Ryan-rsm-McKenzie/text | 15aaea4297e00ec4c74295e7913ead79c90e1502 | [
"BSL-1.0"
] | 25 | 2017-08-29T23:07:23.000Z | 2021-09-03T06:31:29.000Z | // Copyright (C) 2020 T. Zachary Laine
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// 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_829_000)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R ET WS LRI; 2 ('LTR') (line 414501)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0020, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET WS RLI; 2 ('LTR') (line 414502)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0020, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET WS FSI; 2 ('LTR') (line 414503)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0020, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET WS PDI; 2 ('LTR') (line 414504)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0020, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON L; 2 ('LTR') (line 414505)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON ES; 2 ('LTR') (line 414506)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON ET; 2 ('LTR') (line 414507)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON CS; 2 ('LTR') (line 414508)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON NSM; 2 ('LTR') (line 414509)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON B; 2 ('LTR') (line 414510)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_001)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R ET ON S; 2 ('LTR') (line 414511)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON WS; 2 ('LTR') (line 414512)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON ON; 2 ('LTR') (line 414513)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON LRI; 2 ('LTR') (line 414514)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON RLI; 2 ('LTR') (line 414515)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON FSI; 2 ('LTR') (line 414516)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET ON PDI; 2 ('LTR') (line 414517)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x0021, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET LRI B; 2 ('LTR') (line 414518)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2066, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET LRI S; 2 ('LTR') (line 414519)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2066, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET LRI WS; 2 ('LTR') (line 414520)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2066, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_002)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R ET LRI LRI; 2 ('LTR') (line 414521)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2066, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET LRI RLI; 2 ('LTR') (line 414522)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2066, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET LRI FSI; 2 ('LTR') (line 414523)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2066, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET LRI PDI; 2 ('LTR') (line 414524)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2066, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET RLI B; 2 ('LTR') (line 414525)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2067, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET RLI S; 2 ('LTR') (line 414526)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2067, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET RLI WS; 2 ('LTR') (line 414527)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2067, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET RLI LRI; 2 ('LTR') (line 414528)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2067, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET RLI RLI; 2 ('LTR') (line 414529)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2067, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET RLI FSI; 2 ('LTR') (line 414530)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2067, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_003)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R ET RLI PDI; 2 ('LTR') (line 414531)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2067, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET FSI B; 2 ('LTR') (line 414532)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2068, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET FSI S; 2 ('LTR') (line 414533)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2068, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET FSI WS; 2 ('LTR') (line 414534)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2068, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET FSI LRI; 2 ('LTR') (line 414535)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2068, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET FSI RLI; 2 ('LTR') (line 414536)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2068, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET FSI FSI; 2 ('LTR') (line 414537)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2068, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET FSI PDI; 2 ('LTR') (line 414538)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2068, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET PDI L; 2 ('LTR') (line 414539)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET PDI ES; 2 ('LTR') (line 414540)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_004)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R ET PDI ET; 2 ('LTR') (line 414541)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET PDI CS; 2 ('LTR') (line 414542)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET PDI NSM; 2 ('LTR') (line 414543)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET PDI B; 2 ('LTR') (line 414544)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET PDI S; 2 ('LTR') (line 414545)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET PDI WS; 2 ('LTR') (line 414546)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET PDI ON; 2 ('LTR') (line 414547)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET PDI LRI; 2 ('LTR') (line 414548)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET PDI RLI; 2 ('LTR') (line 414549)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ET PDI FSI; 2 ('LTR') (line 414550)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_005)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R ET PDI PDI; 2 ('LTR') (line 414551)
std::vector<uint32_t> const cps = { 0x05BE, 0x0023, 0x2069, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L L; 2 ('LTR') (line 414552)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L EN; 2 ('LTR') (line 414553)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x0030 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L ES; 2 ('LTR') (line 414554)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L ET; 2 ('LTR') (line 414555)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L CS; 2 ('LTR') (line 414556)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L NSM; 2 ('LTR') (line 414557)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L B; 2 ('LTR') (line 414558)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L S; 2 ('LTR') (line 414559)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L WS; 2 ('LTR') (line 414560)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_006)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS L ON; 2 ('LTR') (line 414561)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L LRI; 2 ('LTR') (line 414562)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L RLI; 2 ('LTR') (line 414563)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L FSI; 2 ('LTR') (line 414564)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS L PDI; 2 ('LTR') (line 414565)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0041, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES L; 2 ('LTR') (line 414566)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES ES; 2 ('LTR') (line 414567)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES ET; 2 ('LTR') (line 414568)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES CS; 2 ('LTR') (line 414569)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES NSM; 2 ('LTR') (line 414570)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_007)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS ES B; 2 ('LTR') (line 414571)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES S; 2 ('LTR') (line 414572)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES WS; 2 ('LTR') (line 414573)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES ON; 2 ('LTR') (line 414574)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES LRI; 2 ('LTR') (line 414575)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES RLI; 2 ('LTR') (line 414576)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES FSI; 2 ('LTR') (line 414577)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ES PDI; 2 ('LTR') (line 414578)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002B, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ET L; 2 ('LTR') (line 414579)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ET ES; 2 ('LTR') (line 414580)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_008)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS ET ET; 2 ('LTR') (line 414581)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ET CS; 2 ('LTR') (line 414582)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ET NSM; 2 ('LTR') (line 414583)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ET B; 2 ('LTR') (line 414584)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ET S; 2 ('LTR') (line 414585)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ET WS; 2 ('LTR') (line 414586)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ET ON; 2 ('LTR') (line 414587)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ET LRI; 2 ('LTR') (line 414588)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ET RLI; 2 ('LTR') (line 414589)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ET FSI; 2 ('LTR') (line 414590)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_009)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS ET PDI; 2 ('LTR') (line 414591)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0023, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS L; 2 ('LTR') (line 414592)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS ES; 2 ('LTR') (line 414593)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS ET; 2 ('LTR') (line 414594)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS CS; 2 ('LTR') (line 414595)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS NSM; 2 ('LTR') (line 414596)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS B; 2 ('LTR') (line 414597)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS S; 2 ('LTR') (line 414598)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS WS; 2 ('LTR') (line 414599)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS ON; 2 ('LTR') (line 414600)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_010)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS CS LRI; 2 ('LTR') (line 414601)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS RLI; 2 ('LTR') (line 414602)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS FSI; 2 ('LTR') (line 414603)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS CS PDI; 2 ('LTR') (line 414604)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x002C, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM L; 2 ('LTR') (line 414605)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM ES; 2 ('LTR') (line 414606)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM ET; 2 ('LTR') (line 414607)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM CS; 2 ('LTR') (line 414608)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM NSM; 2 ('LTR') (line 414609)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM B; 2 ('LTR') (line 414610)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_011)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS NSM S; 2 ('LTR') (line 414611)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM WS; 2 ('LTR') (line 414612)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM ON; 2 ('LTR') (line 414613)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM LRI; 2 ('LTR') (line 414614)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM RLI; 2 ('LTR') (line 414615)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM FSI; 2 ('LTR') (line 414616)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS NSM PDI; 2 ('LTR') (line 414617)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0300, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S L; 2 ('LTR') (line 414618)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S ES; 2 ('LTR') (line 414619)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S ET; 2 ('LTR') (line 414620)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_012)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS S CS; 2 ('LTR') (line 414621)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S NSM; 2 ('LTR') (line 414622)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S B; 2 ('LTR') (line 414623)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S S; 2 ('LTR') (line 414624)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S WS; 2 ('LTR') (line 414625)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S ON; 2 ('LTR') (line 414626)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S LRI; 2 ('LTR') (line 414627)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S RLI; 2 ('LTR') (line 414628)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S FSI; 2 ('LTR') (line 414629)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS S PDI; 2 ('LTR') (line 414630)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0009, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_013)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS WS L; 2 ('LTR') (line 414631)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS WS ES; 2 ('LTR') (line 414632)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS WS ET; 2 ('LTR') (line 414633)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS WS CS; 2 ('LTR') (line 414634)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS WS NSM; 2 ('LTR') (line 414635)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS WS B; 2 ('LTR') (line 414636)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS WS S; 2 ('LTR') (line 414637)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS WS WS; 2 ('LTR') (line 414638)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS WS ON; 2 ('LTR') (line 414639)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS WS LRI; 2 ('LTR') (line 414640)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_014)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS WS RLI; 2 ('LTR') (line 414641)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS WS FSI; 2 ('LTR') (line 414642)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS WS PDI; 2 ('LTR') (line 414643)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0020, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON L; 2 ('LTR') (line 414644)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON ES; 2 ('LTR') (line 414645)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON ET; 2 ('LTR') (line 414646)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON CS; 2 ('LTR') (line 414647)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON NSM; 2 ('LTR') (line 414648)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON B; 2 ('LTR') (line 414649)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON S; 2 ('LTR') (line 414650)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_015)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS ON WS; 2 ('LTR') (line 414651)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON ON; 2 ('LTR') (line 414652)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON LRI; 2 ('LTR') (line 414653)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON RLI; 2 ('LTR') (line 414654)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON FSI; 2 ('LTR') (line 414655)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS ON PDI; 2 ('LTR') (line 414656)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x0021, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS LRI B; 2 ('LTR') (line 414657)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2066, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS LRI S; 2 ('LTR') (line 414658)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2066, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS LRI WS; 2 ('LTR') (line 414659)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2066, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS LRI LRI; 2 ('LTR') (line 414660)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2066, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_016)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS LRI RLI; 2 ('LTR') (line 414661)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2066, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS LRI FSI; 2 ('LTR') (line 414662)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2066, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS LRI PDI; 2 ('LTR') (line 414663)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2066, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS RLI B; 2 ('LTR') (line 414664)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2067, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS RLI S; 2 ('LTR') (line 414665)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2067, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS RLI WS; 2 ('LTR') (line 414666)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2067, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS RLI LRI; 2 ('LTR') (line 414667)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2067, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS RLI RLI; 2 ('LTR') (line 414668)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2067, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS RLI FSI; 2 ('LTR') (line 414669)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2067, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS RLI PDI; 2 ('LTR') (line 414670)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2067, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_017)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS FSI B; 2 ('LTR') (line 414671)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2068, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS FSI S; 2 ('LTR') (line 414672)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2068, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS FSI WS; 2 ('LTR') (line 414673)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2068, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS FSI LRI; 2 ('LTR') (line 414674)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2068, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS FSI RLI; 2 ('LTR') (line 414675)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2068, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS FSI FSI; 2 ('LTR') (line 414676)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2068, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS FSI PDI; 2 ('LTR') (line 414677)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2068, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI L; 2 ('LTR') (line 414678)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI ES; 2 ('LTR') (line 414679)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI ET; 2 ('LTR') (line 414680)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_018)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R CS PDI CS; 2 ('LTR') (line 414681)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI NSM; 2 ('LTR') (line 414682)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI B; 2 ('LTR') (line 414683)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI S; 2 ('LTR') (line 414684)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI WS; 2 ('LTR') (line 414685)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI ON; 2 ('LTR') (line 414686)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI LRI; 2 ('LTR') (line 414687)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI RLI; 2 ('LTR') (line 414688)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI FSI; 2 ('LTR') (line 414689)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R CS PDI PDI; 2 ('LTR') (line 414690)
std::vector<uint32_t> const cps = { 0x05BE, 0x002C, 0x2069, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_019)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S L L; 2 ('LTR') (line 414691)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L EN; 2 ('LTR') (line 414692)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x0030 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L ES; 2 ('LTR') (line 414693)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L ET; 2 ('LTR') (line 414694)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L CS; 2 ('LTR') (line 414695)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L NSM; 2 ('LTR') (line 414696)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L B; 2 ('LTR') (line 414697)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L S; 2 ('LTR') (line 414698)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L WS; 2 ('LTR') (line 414699)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L ON; 2 ('LTR') (line 414700)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_020)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S L LRI; 2 ('LTR') (line 414701)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L RLI; 2 ('LTR') (line 414702)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L FSI; 2 ('LTR') (line 414703)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S L PDI; 2 ('LTR') (line 414704)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0041, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES L; 2 ('LTR') (line 414705)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES ES; 2 ('LTR') (line 414706)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES ET; 2 ('LTR') (line 414707)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES CS; 2 ('LTR') (line 414708)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES NSM; 2 ('LTR') (line 414709)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES B; 2 ('LTR') (line 414710)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_021)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S ES S; 2 ('LTR') (line 414711)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES WS; 2 ('LTR') (line 414712)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES ON; 2 ('LTR') (line 414713)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES LRI; 2 ('LTR') (line 414714)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES RLI; 2 ('LTR') (line 414715)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES FSI; 2 ('LTR') (line 414716)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ES PDI; 2 ('LTR') (line 414717)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002B, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET L; 2 ('LTR') (line 414718)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET ES; 2 ('LTR') (line 414719)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET ET; 2 ('LTR') (line 414720)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_022)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S ET CS; 2 ('LTR') (line 414721)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET NSM; 2 ('LTR') (line 414722)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET B; 2 ('LTR') (line 414723)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET S; 2 ('LTR') (line 414724)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET WS; 2 ('LTR') (line 414725)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET ON; 2 ('LTR') (line 414726)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET LRI; 2 ('LTR') (line 414727)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET RLI; 2 ('LTR') (line 414728)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET FSI; 2 ('LTR') (line 414729)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ET PDI; 2 ('LTR') (line 414730)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0023, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_023)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S CS L; 2 ('LTR') (line 414731)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S CS ES; 2 ('LTR') (line 414732)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S CS ET; 2 ('LTR') (line 414733)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S CS CS; 2 ('LTR') (line 414734)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S CS NSM; 2 ('LTR') (line 414735)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S CS B; 2 ('LTR') (line 414736)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S CS S; 2 ('LTR') (line 414737)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S CS WS; 2 ('LTR') (line 414738)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S CS ON; 2 ('LTR') (line 414739)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S CS LRI; 2 ('LTR') (line 414740)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_024)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S CS RLI; 2 ('LTR') (line 414741)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S CS FSI; 2 ('LTR') (line 414742)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S CS PDI; 2 ('LTR') (line 414743)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x002C, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM L; 2 ('LTR') (line 414744)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM ES; 2 ('LTR') (line 414745)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM ET; 2 ('LTR') (line 414746)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM CS; 2 ('LTR') (line 414747)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM NSM; 2 ('LTR') (line 414748)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM B; 2 ('LTR') (line 414749)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM S; 2 ('LTR') (line 414750)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_025)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S NSM WS; 2 ('LTR') (line 414751)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM ON; 2 ('LTR') (line 414752)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM LRI; 2 ('LTR') (line 414753)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM RLI; 2 ('LTR') (line 414754)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM FSI; 2 ('LTR') (line 414755)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S NSM PDI; 2 ('LTR') (line 414756)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0300, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S L; 2 ('LTR') (line 414757)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S ES; 2 ('LTR') (line 414758)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S ET; 2 ('LTR') (line 414759)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S CS; 2 ('LTR') (line 414760)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_026)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S S NSM; 2 ('LTR') (line 414761)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S B; 2 ('LTR') (line 414762)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S S; 2 ('LTR') (line 414763)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S WS; 2 ('LTR') (line 414764)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S ON; 2 ('LTR') (line 414765)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S LRI; 2 ('LTR') (line 414766)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S RLI; 2 ('LTR') (line 414767)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S FSI; 2 ('LTR') (line 414768)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S S PDI; 2 ('LTR') (line 414769)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0009, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S WS L; 2 ('LTR') (line 414770)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_027)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S WS ES; 2 ('LTR') (line 414771)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S WS ET; 2 ('LTR') (line 414772)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S WS CS; 2 ('LTR') (line 414773)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S WS NSM; 2 ('LTR') (line 414774)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S WS B; 2 ('LTR') (line 414775)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S WS S; 2 ('LTR') (line 414776)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S WS WS; 2 ('LTR') (line 414777)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S WS ON; 2 ('LTR') (line 414778)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S WS LRI; 2 ('LTR') (line 414779)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S WS RLI; 2 ('LTR') (line 414780)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_028)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S WS FSI; 2 ('LTR') (line 414781)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S WS PDI; 2 ('LTR') (line 414782)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0020, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON L; 2 ('LTR') (line 414783)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON ES; 2 ('LTR') (line 414784)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON ET; 2 ('LTR') (line 414785)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON CS; 2 ('LTR') (line 414786)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON NSM; 2 ('LTR') (line 414787)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON B; 2 ('LTR') (line 414788)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON S; 2 ('LTR') (line 414789)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON WS; 2 ('LTR') (line 414790)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_029)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S ON ON; 2 ('LTR') (line 414791)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON LRI; 2 ('LTR') (line 414792)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON RLI; 2 ('LTR') (line 414793)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON FSI; 2 ('LTR') (line 414794)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S ON PDI; 2 ('LTR') (line 414795)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x0021, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S LRI B; 2 ('LTR') (line 414796)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2066, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S LRI S; 2 ('LTR') (line 414797)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2066, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S LRI WS; 2 ('LTR') (line 414798)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2066, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S LRI LRI; 2 ('LTR') (line 414799)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2066, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S LRI RLI; 2 ('LTR') (line 414800)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2066, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_030)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S LRI FSI; 2 ('LTR') (line 414801)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2066, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S LRI PDI; 2 ('LTR') (line 414802)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2066, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S RLI B; 2 ('LTR') (line 414803)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2067, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S RLI S; 2 ('LTR') (line 414804)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2067, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S RLI WS; 2 ('LTR') (line 414805)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2067, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S RLI LRI; 2 ('LTR') (line 414806)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2067, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S RLI RLI; 2 ('LTR') (line 414807)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2067, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S RLI FSI; 2 ('LTR') (line 414808)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2067, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S RLI PDI; 2 ('LTR') (line 414809)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2067, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S FSI B; 2 ('LTR') (line 414810)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2068, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_031)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S FSI S; 2 ('LTR') (line 414811)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2068, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S FSI WS; 2 ('LTR') (line 414812)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2068, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S FSI LRI; 2 ('LTR') (line 414813)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2068, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S FSI RLI; 2 ('LTR') (line 414814)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2068, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S FSI FSI; 2 ('LTR') (line 414815)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2068, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S FSI PDI; 2 ('LTR') (line 414816)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2068, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI L; 2 ('LTR') (line 414817)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI ES; 2 ('LTR') (line 414818)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI ET; 2 ('LTR') (line 414819)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI CS; 2 ('LTR') (line 414820)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_032)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R S PDI NSM; 2 ('LTR') (line 414821)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI B; 2 ('LTR') (line 414822)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI S; 2 ('LTR') (line 414823)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI WS; 2 ('LTR') (line 414824)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI ON; 2 ('LTR') (line 414825)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI LRI; 2 ('LTR') (line 414826)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI RLI; 2 ('LTR') (line 414827)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI FSI; 2 ('LTR') (line 414828)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R S PDI PDI; 2 ('LTR') (line 414829)
std::vector<uint32_t> const cps = { 0x05BE, 0x0009, 0x2069, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L L; 2 ('LTR') (line 414830)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_033)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS L EN; 2 ('LTR') (line 414831)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x0030 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L ES; 2 ('LTR') (line 414832)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L ET; 2 ('LTR') (line 414833)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L CS; 2 ('LTR') (line 414834)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L NSM; 2 ('LTR') (line 414835)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L B; 2 ('LTR') (line 414836)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L S; 2 ('LTR') (line 414837)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L WS; 2 ('LTR') (line 414838)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L ON; 2 ('LTR') (line 414839)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L LRI; 2 ('LTR') (line 414840)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_034)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS L RLI; 2 ('LTR') (line 414841)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L FSI; 2 ('LTR') (line 414842)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS L PDI; 2 ('LTR') (line 414843)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0041, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES L; 2 ('LTR') (line 414844)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES ES; 2 ('LTR') (line 414845)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES ET; 2 ('LTR') (line 414846)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES CS; 2 ('LTR') (line 414847)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES NSM; 2 ('LTR') (line 414848)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES B; 2 ('LTR') (line 414849)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES S; 2 ('LTR') (line 414850)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_035)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS ES WS; 2 ('LTR') (line 414851)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES ON; 2 ('LTR') (line 414852)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES LRI; 2 ('LTR') (line 414853)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES RLI; 2 ('LTR') (line 414854)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES FSI; 2 ('LTR') (line 414855)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ES PDI; 2 ('LTR') (line 414856)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002B, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET L; 2 ('LTR') (line 414857)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET ES; 2 ('LTR') (line 414858)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET ET; 2 ('LTR') (line 414859)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET CS; 2 ('LTR') (line 414860)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_036)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS ET NSM; 2 ('LTR') (line 414861)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET B; 2 ('LTR') (line 414862)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET S; 2 ('LTR') (line 414863)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET WS; 2 ('LTR') (line 414864)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET ON; 2 ('LTR') (line 414865)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET LRI; 2 ('LTR') (line 414866)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET RLI; 2 ('LTR') (line 414867)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET FSI; 2 ('LTR') (line 414868)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ET PDI; 2 ('LTR') (line 414869)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0023, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS CS L; 2 ('LTR') (line 414870)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_037)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS CS ES; 2 ('LTR') (line 414871)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS CS ET; 2 ('LTR') (line 414872)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS CS CS; 2 ('LTR') (line 414873)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS CS NSM; 2 ('LTR') (line 414874)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS CS B; 2 ('LTR') (line 414875)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS CS S; 2 ('LTR') (line 414876)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS CS WS; 2 ('LTR') (line 414877)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS CS ON; 2 ('LTR') (line 414878)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS CS LRI; 2 ('LTR') (line 414879)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS CS RLI; 2 ('LTR') (line 414880)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_038)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS CS FSI; 2 ('LTR') (line 414881)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS CS PDI; 2 ('LTR') (line 414882)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x002C, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM L; 2 ('LTR') (line 414883)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM ES; 2 ('LTR') (line 414884)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM ET; 2 ('LTR') (line 414885)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM CS; 2 ('LTR') (line 414886)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM NSM; 2 ('LTR') (line 414887)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM B; 2 ('LTR') (line 414888)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM S; 2 ('LTR') (line 414889)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM WS; 2 ('LTR') (line 414890)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_039)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS NSM ON; 2 ('LTR') (line 414891)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM LRI; 2 ('LTR') (line 414892)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM RLI; 2 ('LTR') (line 414893)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM FSI; 2 ('LTR') (line 414894)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS NSM PDI; 2 ('LTR') (line 414895)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0300, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S L; 2 ('LTR') (line 414896)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S ES; 2 ('LTR') (line 414897)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S ET; 2 ('LTR') (line 414898)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S CS; 2 ('LTR') (line 414899)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S NSM; 2 ('LTR') (line 414900)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_040)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS S B; 2 ('LTR') (line 414901)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S S; 2 ('LTR') (line 414902)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S WS; 2 ('LTR') (line 414903)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S ON; 2 ('LTR') (line 414904)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S LRI; 2 ('LTR') (line 414905)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S RLI; 2 ('LTR') (line 414906)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S FSI; 2 ('LTR') (line 414907)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS S PDI; 2 ('LTR') (line 414908)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0009, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS WS L; 2 ('LTR') (line 414909)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS WS ES; 2 ('LTR') (line 414910)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_041)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS WS ET; 2 ('LTR') (line 414911)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS WS CS; 2 ('LTR') (line 414912)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS WS NSM; 2 ('LTR') (line 414913)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS WS B; 2 ('LTR') (line 414914)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS WS S; 2 ('LTR') (line 414915)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS WS WS; 2 ('LTR') (line 414916)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS WS ON; 2 ('LTR') (line 414917)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS WS LRI; 2 ('LTR') (line 414918)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS WS RLI; 2 ('LTR') (line 414919)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS WS FSI; 2 ('LTR') (line 414920)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_042)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS WS PDI; 2 ('LTR') (line 414921)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0020, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON L; 2 ('LTR') (line 414922)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON ES; 2 ('LTR') (line 414923)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON ET; 2 ('LTR') (line 414924)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON CS; 2 ('LTR') (line 414925)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON NSM; 2 ('LTR') (line 414926)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON B; 2 ('LTR') (line 414927)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON S; 2 ('LTR') (line 414928)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON WS; 2 ('LTR') (line 414929)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON ON; 2 ('LTR') (line 414930)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_043)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS ON LRI; 2 ('LTR') (line 414931)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON RLI; 2 ('LTR') (line 414932)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON FSI; 2 ('LTR') (line 414933)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS ON PDI; 2 ('LTR') (line 414934)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x0021, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS LRI B; 2 ('LTR') (line 414935)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2066, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS LRI S; 2 ('LTR') (line 414936)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2066, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS LRI WS; 2 ('LTR') (line 414937)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2066, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS LRI LRI; 2 ('LTR') (line 414938)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2066, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS LRI RLI; 2 ('LTR') (line 414939)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2066, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS LRI FSI; 2 ('LTR') (line 414940)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2066, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_044)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS LRI PDI; 2 ('LTR') (line 414941)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2066, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS RLI B; 2 ('LTR') (line 414942)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2067, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS RLI S; 2 ('LTR') (line 414943)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2067, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS RLI WS; 2 ('LTR') (line 414944)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2067, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS RLI LRI; 2 ('LTR') (line 414945)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2067, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS RLI RLI; 2 ('LTR') (line 414946)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2067, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS RLI FSI; 2 ('LTR') (line 414947)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2067, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS RLI PDI; 2 ('LTR') (line 414948)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2067, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS FSI B; 2 ('LTR') (line 414949)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2068, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS FSI S; 2 ('LTR') (line 414950)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2068, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_045)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS FSI WS; 2 ('LTR') (line 414951)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2068, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS FSI LRI; 2 ('LTR') (line 414952)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2068, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS FSI RLI; 2 ('LTR') (line 414953)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2068, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS FSI FSI; 2 ('LTR') (line 414954)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2068, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS FSI PDI; 2 ('LTR') (line 414955)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2068, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI L; 2 ('LTR') (line 414956)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI ES; 2 ('LTR') (line 414957)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI ET; 2 ('LTR') (line 414958)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI CS; 2 ('LTR') (line 414959)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI NSM; 2 ('LTR') (line 414960)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_046)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R WS PDI B; 2 ('LTR') (line 414961)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI S; 2 ('LTR') (line 414962)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI WS; 2 ('LTR') (line 414963)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI ON; 2 ('LTR') (line 414964)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI LRI; 2 ('LTR') (line 414965)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI RLI; 2 ('LTR') (line 414966)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI FSI; 2 ('LTR') (line 414967)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R WS PDI PDI; 2 ('LTR') (line 414968)
std::vector<uint32_t> const cps = { 0x05BE, 0x0020, 0x2069, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L L; 2 ('LTR') (line 414969)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L EN; 2 ('LTR') (line 414970)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x0030 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_047)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R ON L ES; 2 ('LTR') (line 414971)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L ET; 2 ('LTR') (line 414972)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L CS; 2 ('LTR') (line 414973)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L NSM; 2 ('LTR') (line 414974)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L B; 2 ('LTR') (line 414975)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L S; 2 ('LTR') (line 414976)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L WS; 2 ('LTR') (line 414977)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L ON; 2 ('LTR') (line 414978)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L LRI; 2 ('LTR') (line 414979)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L RLI; 2 ('LTR') (line 414980)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_048)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R ON L FSI; 2 ('LTR') (line 414981)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON L PDI; 2 ('LTR') (line 414982)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0041, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES L; 2 ('LTR') (line 414983)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES ES; 2 ('LTR') (line 414984)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES ET; 2 ('LTR') (line 414985)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES CS; 2 ('LTR') (line 414986)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES NSM; 2 ('LTR') (line 414987)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES B; 2 ('LTR') (line 414988)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x2029 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES S; 2 ('LTR') (line 414989)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x0009 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES WS; 2 ('LTR') (line 414990)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x0020 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)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_829_049)
{
expected_levels = { 1, 0, 0, 0 };
expected_reordered_indices = { 0, 1, 2, 3 };
{
// R ON ES ON; 2 ('LTR') (line 414991)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x0021 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES LRI; 2 ('LTR') (line 414992)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x2066 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES RLI; 2 ('LTR') (line 414993)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x2067 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES FSI; 2 ('LTR') (line 414994)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x2068 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ES PDI; 2 ('LTR') (line 414995)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x002B, 0x2069 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ET L; 2 ('LTR') (line 414996)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0023, 0x0041 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ET ES; 2 ('LTR') (line 414997)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0023, 0x002B };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ET ET; 2 ('LTR') (line 414998)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0023, 0x0023 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ET CS; 2 ('LTR') (line 414999)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0023, 0x002C };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
{
// R ON ET NSM; 2 ('LTR') (line 415000)
std::vector<uint32_t> const cps = { 0x05BE, 0x0021, 0x0023, 0x0300 };
std::vector<int> const levels =
bidi_levels(cps.begin(), cps.end(), 0);
int i = 0;
for (int l : expected_levels) {
if (0 <= l) {
EXPECT_EQ(levels[i], l) << "i=" << i;
++i;
}
}
EXPECT_EQ((int)levels.size(), i);
std::vector<int> const reordered =
bidi_reordered_indices(cps.begin(), cps.end(), 0);
i = 0;
for (int idx : expected_reordered_indices) {
// Skip FSI, LRI, RLI, and PDI.
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
std::vector<int> reordered_2;
for (auto subrange :
boost::text::bidirectional_subranges(cps, 0)) {
for (auto cp : subrange) {
reordered_2.push_back(cp);
}
}
i = 0;
for (int idx : expected_reordered_indices) {
if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
EXPECT_EQ(reordered_2[i], (int)cps[idx])
<< std::hex
<< " 0x" << reordered_2[i]
<< " 0x" << cps[idx]
<< std::dec << " i=" << i;
}
++i;
}
EXPECT_EQ(i, (int)reordered_2.size());
}
}
| 33.085022 | 77 | 0.404837 | [
"vector"
] |
0933389b64443fc9abdc9ea8e1d7f0608547a6aa | 14,903 | hpp | C++ | lipnet/include/lipnet/tensor.hpp | eragon10/train-neural-networks-with-lipschitz-bound | c3e51aa4c315e0e03b913712dad5a1a0e72f67e4 | [
"Apache-2.0"
] | null | null | null | lipnet/include/lipnet/tensor.hpp | eragon10/train-neural-networks-with-lipschitz-bound | c3e51aa4c315e0e03b913712dad5a1a0e72f67e4 | [
"Apache-2.0"
] | null | null | null | lipnet/include/lipnet/tensor.hpp | eragon10/train-neural-networks-with-lipschitz-bound | c3e51aa4c315e0e03b913712dad5a1a0e72f67e4 | [
"Apache-2.0"
] | null | null | null | /*
* Copyright 2020 Niklas Funcke <niklas.funcke@gmail.com>
*
* 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 __LIPNET_TENSOR_HPP__
#define __LIPNET_TENSOR_HPP__
#include <memory>
#include <string>
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <tuple>
#include <functional>
#include <algorithm>
#include <utility>
#include <initializer_list>
#include <deque>
#include <blaze/Blaze.h>
#include <lipnet/traits.hpp>
#include <lipnet/variable.hpp>
namespace lipnet {
/**
* @brief The prod_t struct for blaze::StaticVector.
* @tparam T numerical value type
* @tparam N1 dimension of first argument
* @tparam N2 dimension of second argument
* @see lipnet::prod_t
* @cite balzelib
*/
template<typename T, size_t N1, size_t N2>
struct prod_t<T, blaze::StaticVector<T,N1,blaze::columnVector>,
blaze::StaticVector<T,N2,blaze::columnVector> > {
/**
* @brief The inner method. Implemention of the inner
* product of blaze::StaticVector type. \f$ m_1^\top m_2 \f$
* @param m1 first argument (blaze::StaticVector<T,N1,blaze::columnVector>)
* @param m2 second argument (blaze::StaticVector<T,N2,blaze::columnVector>)
* @return inner product of m1 and m2
*/
static inline T inner( const blaze::StaticVector<T,N1,blaze::columnVector> &m1,
const blaze::StaticVector<T,N2,blaze::columnVector> &m2 ) {
return blaze::inner( m1, m2 );
}
/**
* @brief The outer method. Implemention of the outer
* product of blaze::StaticVector type. \f$ m_1 m_2^\top \f$
* @param m1 first argument (blaze::StaticVector<T,N1,blaze::columnVector>)
* @param m2 second argument (blaze::StaticVector<T,N2,blaze::columnVector>)
* @return outer product of m1 and m2
*/
static inline auto outer( const blaze::StaticVector<T,N1,blaze::columnVector> &m1,
const blaze::StaticVector<T,N2,blaze::columnVector> &m2 ) {
return blaze::outer( m1, m2 );
}
};
/**
* @brief The prod_t struct for blaze::StaticMatrix.
* @tparam T numerical value type
* @tparam N1 row dimension of first argument
* @tparam N2 column dimension of first argument
* @tparam N3 row dimension of second argument
* @tparam N4 column dimension of second argument
* @see lipnet::prod_t
* @cite balzelib
*/
template<typename T, size_t N1, size_t N2, size_t N3, size_t N4>
struct prod_t<T, blaze::StaticMatrix<T,N1,N2,blaze::rowMajor>,
blaze::StaticMatrix<T,N3,N4,blaze::rowMajor> > {
/**
* @brief The inner method. Implemention of the inner
* product of blaze::StaticVector type. \f$ m_1^\top m_2 \f$
* @param m1 first argument (blaze::StaticVector<T,N1,blaze::columnVector>)
* @param m2 second argument (blaze::StaticVector<T,N2,blaze::columnVector>)
* @return inner product of m1 and m2
*/
static inline T inner( const blaze::StaticMatrix<T,N1,N2,blaze::rowMajor> &m1,
const blaze::StaticMatrix<T,N3,N4,blaze::rowMajor> &m2 ) {
return blaze::inner( m1, m2 );
}
/**
* @brief The outer method. Implemention of the outer
* product of blaze::StaticMatrix type.
* @param m1 first argument (blaze::StaticMatrix<T,N1,N2,blaze::rowMajor>)
* @param m2 second argument (blaze::StaticMatrix<T,N3,N4,blaze::rowMajor>)
* @return kronecker product of m1 and m2
*/
static inline auto outer( const blaze::StaticMatrix<T,N1,N2,blaze::rowMajor> &m1,
const blaze::StaticMatrix<T,N3,N4,blaze::rowMajor> &m2 ) {
return blaze::kron( m1, m2 );
}
};
/**
* @brief The equation_system_t struct for blaze::StaticMatrix.
* @tparam T numerical value type
* @tparam N1 row dimension of first argument
* @tparam N2 column dimension of first argument
* @tparam N3 row dimension of second argument
* @tparam N4 column dimension of second argument
* @see lipnet::equation_system_t
* @cite balzelib
*/
template<typename T, size_t N1, size_t N2, size_t N3, size_t N4>
struct equation_system_t< blaze::StaticMatrix<T,N1,N2,blaze::rowMajor>,
blaze::StaticMatrix<T,N3,N4,blaze::rowMajor> > {
/**
* @brief The solve method. Solve system of equations. \f$ A X = A \f$
* @param A matrix \f$ A \f$ (first argument)
* @param B matrix \f$ A \f$ (second argument)
* @return matrix \f$ X \f$
*/
static inline auto solve( const blaze::StaticMatrix<T,N1,N2,blaze::rowMajor> &A,
const blaze::StaticMatrix<T,N3,N4,blaze::rowMajor> &B ) {
return blaze::solve( A, B );
}
};
/**
* @brief The equation_system_t struct for blaze::StaticMatrix and blaze::StaticVector.
* @tparam T numerical value type
* @tparam N1 row dimension of first argument
* @tparam N2 column dimension of first argument
* @tparam N3 dimension of second argument
* @see lipnet::equation_system_t
* @cite balzelib
*/
template<typename T, size_t N1, size_t N2, size_t N3>
struct equation_system_t< blaze::StaticMatrix<T,N1,N2,blaze::rowMajor>,
blaze::StaticVector<T,N3,blaze::columnVector> > {
/**
* @brief The solve method. Solve system of equations. \f$ A x = b \f$
* @param A matrix \f$ A \f$ (first argument)
* @param B vector \f$ b \f$ (second argument)
* @return vector \f$ x \f$
*/
static inline auto solve( const blaze::StaticMatrix<T,N1,N2,blaze::rowMajor> &A,
const blaze::StaticVector<T,N3,blaze::columnVector> &B ) {
return blaze::solve( A, B );
}
};
/**
* @brief The generator_t struct for blaze::StaticMatrix.
* @tparam T numerical value type
* @tparam N1 row dimension of return matrix
* @tparam N2 column dimension of return matrix
* @see lipnet::generator_t
* @cite balzelib
*/
template<typename T, size_t N1, size_t N2>
struct generator_t< blaze::StaticMatrix<T,N1,N2,blaze::rowMajor> > {
/// uniform distribution constructor \f$ \sim \mathcal{U}(-val,val) \f$
static inline auto make( const T &val ) {
return blaze::uniform(N1, N2, val);
}
/// uniform distribution constructor \f$ \sim \mathcal{U}(-val,val) \f$
static inline auto unifrom( const T &val ) {
return blaze::uniform(N1, N2, val);
}
/// identity constructor \f$ I \f$
static inline auto identity() {
static_assert ( N1 == N2, "have to provide square matrix");
return blaze::IdentityMatrix<T>(N1);
}
};
/**
* @brief The generator_t struct for blaze::StaticVector.
* @tparam T numerical value type
* @tparam N dimension of return vector
* @see lipnet::generator_t
* @cite balzelib
*/
template<typename T, size_t N>
struct generator_t< blaze::StaticVector<T,N,blaze::columnVector> > {
/// uniform distribution constructor \f$ \sim \mathcal{U}(-val,val) \f$
static inline auto make( const T &val ) {
return blaze::uniform(N, val);
}
/// uniform distribution constructor \f$ \sim \mathcal{U}(-val,val) \f$
static inline auto unifrom( const T &val ) {
return blaze::uniform(N, val);
}
};
/**
* @brief The norm_t struct for blaze::StaticVector.
* @tparam T numerical value type
* @tparam N dimension of argument
* @see lipnet::norm_t
* @cite balzelib
*/
template<typename T, size_t N >
struct norm_t<T, blaze::StaticVector<T,N,blaze::columnVector> > {
/**
* @brief The norm method. Compute norm of vector m. \f$ ||m||_2 \f$
* @param m input vector
* @return norm of vector m
*/
static inline T norm( const blaze::StaticVector<T,N,blaze::columnVector> &m ) {
return blaze::norm( m );
}
};
/**
* @brief The norm_t struct for blaze::StaticMatrix.
* @tparam T numerical value type
* @tparam N1 row dimension of argument
* @tparam N2 column dimension of argument
* @see lipnet::norm_t
* @cite balzelib
*/
template<typename T, size_t N1, size_t N2 >
struct norm_t<T, blaze::StaticMatrix<T,N1,N2,blaze::rowMajor> > {
/**
* @brief The norm method. Compute norm of vector m. \f$ ||m||_{2\mathrm{-ind.}} \f$
* @param m input matrix
* @return norm of matrix m
*/
static inline T norm( const blaze::StaticMatrix<T,N1,N2,blaze::rowMajor> &m ) {
return blaze::norm( m );
}
};
/**
* @brief The function_t struct for blaze::StaticVector.
* @tparam T numerical value type
* @tparam N dimension of argument
* @see lipnet::function_t
* @cite balzelib
*/
template<typename T, size_t N>
struct function_t<blaze::StaticVector<T,N,blaze::columnVector>> {
/// transpose vector \f$ v^\top \f$
static inline auto trans( const blaze::StaticVector<T,N,blaze::columnVector> &vec ) {
return blaze::trans(vec);
}
/// square vector elementwise
static inline auto square( const blaze::StaticVector<T,N,blaze::columnVector> &vec ) {
return blaze::pow( vec, 2 );
}
/// take square root of vector elementwise
static inline auto sqrt( const blaze::StaticVector<T,N,blaze::columnVector> &vec ) {
return blaze::sqrt( vec );
}
};
/**
* @brief The function_t struct for blaze::StaticMatrix.
* @tparam T numerical value type
* @tparam N1 row dimension of argument
* @tparam N2 column dimension of argument
* @see lipnet::function_t
* @cite balzelib
*/
template<typename T, size_t N1, size_t N2>
struct function_t<blaze::StaticMatrix<T,N1,N2,blaze::rowMajor>> {
/// transpose matrix \f$ M^\top \f$
static inline auto trans( const blaze::StaticMatrix<T,N1,N2,blaze::rowMajor> &m ) {
return blaze::trans(m);
}
};
}
namespace blaze {
/**
* @brief The flatten function. Flatten matrix to vector.
* @tparam T numerical value type
* @tparam N1 row dimension of argument
* @tparam N2 column dimension of argument
* @return vector of dimension \f$ N_1 N_2 \f$
* @cite balzelib
*/
template<typename T, size_t N1, size_t N2>
inline auto flatten( const blaze::StaticMatrix<T,N1,N2,blaze::rowMajor> &mat ) {
typedef blaze::StaticVector<T,N1*N2,blaze::columnVector> vecor_t;
vecor_t result;
std::for_range<0,N1>([&]<auto I>(){
blaze::subvector<I*N2,N2>( result )
= blaze::trans( blaze::row<I>( mat ) );
});
return std::move(result);
}
/**
* @brief The tomatrix function. Reshape vector to matrix.
* Input vector is of dimension \f$ N_1 N_2 \f$.
* @tparam T numerical value type
* @tparam N1 row dimension of return matrix
* @tparam N2 column dimension of return matrix
* @return matrix
* @cite balzelib
*/
template<typename T, size_t N1, size_t N2>
inline auto tomatrix( const blaze::StaticVector<T,N1*N2,blaze::columnVector> &vec ) {
typedef blaze::StaticMatrix<T,N1,N2,blaze::rowMajor> matrix_t;
matrix_t result;
std::for_range<0,N1>([&]<auto I>(){
blaze::row<I>( result ) = blaze::trans(
blaze::subvector<I*N2,N2>( vec ) );
});
return std::move(result);
}
}
template<class Archive, typename T, size_t R, size_t C, bool SO>
void serialize(Archive & archive, blaze::StaticMatrix<T, R, C, SO> & m );
template<class Archive, typename T, size_t N>
void serialize(Archive & archive, blaze::StaticVector<T, N, blaze::columnVector> & m );
template<class Archive, typename T, bool SO>
void serialize(Archive & archive, blaze::DynamicMatrix<T, SO> & m );
template<class Archive, typename T>
void serialize(Archive & archive, blaze::DynamicVector<T, blaze::columnVector> & m );
#include <cereal/cereal.hpp>
/// @brief serialize blaze::StaticMatrix
/// @cite cereallib
/// @cite balzelib
template<class Archive, typename T, size_t R, size_t C, bool SO>
void serialize(Archive & archive, blaze::StaticMatrix<T, R, C, SO> & m )
{
archive( cereal::make_size_tag(static_cast<cereal::size_type>(R*C)) );
for( size_t i=0UL; i<m.rows(); ++i )
for( size_t j=0UL; j<m.columns(); ++j ) {
archive( m(i,j) );
}
}
/// @brief serialize blaze::StaticVector
/// @cite cereallib
/// @cite balzelib
template<class Archive, typename T, size_t N>
void serialize(Archive & archive, blaze::StaticVector<T, N, blaze::columnVector> & m )
{
archive( cereal::make_size_tag(static_cast<cereal::size_type>(N)) );
for( size_t i=0UL; i<m.size(); ++i ) {
archive( m.at(i) );
}
}
/// @brief serialize blaze::DynamicMatrix
/// @cite cereallib
/// @cite balzelib
template<class Archive, typename T, bool SO>
void serialize(Archive & archive, blaze::DynamicMatrix<T, SO> & m )
{
archive( cereal::make_size_tag(static_cast<cereal::size_type>(
m.rows() * m.columns() )) );
for( size_t i=0UL; i<m.rows(); ++i )
for( size_t j=0UL; j<m.columns(); ++j ) {
archive( m(i,j) );
}
}
/// @brief serialize blaze::DynamicVector
/// @cite cereallib
/// @cite balzelib
template<class Archive, typename T>
void serialize(Archive & archive, blaze::DynamicVector<T, blaze::columnVector> & m )
{
archive( cereal::make_size_tag(static_cast<cereal::size_type>( m.size() )) );
for( size_t i=0UL; i<m.size(); ++i ) {
archive( m.at(i) );
}
}
#endif // __LIPNET_TENSOR_HPP__
| 30.919087 | 94 | 0.602295 | [
"vector"
] |
0940ccc76850f50c0181a454cdbbe553dc0a8bbb | 17,806 | cpp | C++ | src/src_pestpp/libs/pestpp_common/Jacobian_1to1.cpp | jtwhite79/worked_example | cae16f633073f82fa09c45ed37a080a902c59097 | [
"BSD-3-Clause"
] | 1 | 2021-02-23T20:47:29.000Z | 2021-02-23T20:47:29.000Z | src/src_pestpp/libs/pestpp_common/Jacobian_1to1.cpp | jtwhite79/worked_example | cae16f633073f82fa09c45ed37a080a902c59097 | [
"BSD-3-Clause"
] | null | null | null | src/src_pestpp/libs/pestpp_common/Jacobian_1to1.cpp | jtwhite79/worked_example | cae16f633073f82fa09c45ed37a080a902c59097 | [
"BSD-3-Clause"
] | 2 | 2020-01-03T17:14:39.000Z | 2020-03-04T14:21:27.000Z | /*
This file is part of PEST++.
PEST++ is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PEST++ 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 PEST++. If not, see<http://www.gnu.org/licenses/>.
*/
#include <cstdlib>
#include <vector>
#include <set>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include "Jacobian_1to1.h"
#include "Transformable.h"
#include "ParamTransformSeq.h"
#include "pest_error.h"
#include "pest_data_structs.h"
#include "ModelRunPP.h"
#include "RunManagerAbstract.h"
#include "ObjectiveFunc.h"
#include "utilities.h"
#include "FileManager.h"
#include "PriorInformation.h"
#include "debug.h"
#include "OutputFileWriter.h"
using namespace std;
using namespace pest_utils;
Jacobian_1to1::Jacobian_1to1(FileManager &_file_manager, OutputFileWriter &_output_file_writer) : Jacobian(_file_manager)
{
output_file_writer_ptr = &_output_file_writer;
}
Jacobian_1to1::~Jacobian_1to1() {
}
bool Jacobian_1to1::build_runs(Parameters &ctl_pars, Observations &ctl_obs, vector<string> numeric_par_names, ParamTransformSeq &par_transform,
const ParameterGroupInfo &group_info, const ParameterInfo &ctl_par_info,
RunManagerAbstract &run_manager, set<string> &out_of_bound_par, bool phiredswh_flag, bool calc_init_obs)
{
Parameters model_parameters(par_transform.ctl2model_cp(ctl_pars));
base_numeric_parameters = par_transform.ctl2numeric_cp(ctl_pars);
run_manager.reinitialize(file_manager.build_filename("rnj"));
debug_msg("Jacobian_1to1::build_runs begin");
failed_parameter_names.clear();
failed_ctl_parameters.clear();
// add base run
int run_id = run_manager.add_run(model_parameters, "", 0);
//if base run is has already been complete, update it and mark it as complete
// compute runs for to jacobain calculation as it is influenced by derivative type( forward or central)
if (!calc_init_obs) {
const Observations &init_obs = ctl_obs;
run_manager.update_run(run_id, model_parameters, init_obs);
}
Parameters new_derivative_pars;
bool success;
Parameters base_derivative_parameters = par_transform.numeric2active_ctl_cp(base_numeric_parameters);
Parameters base_model_parameters = par_transform.numeric2model_cp(base_numeric_parameters);
//Loop through derivative parameters and build the parameter sets necessary for computing the jacobian
std::map<string, vector<int>> par_run_map;
for (auto &i_name : numeric_par_names)
{
assert(base_derivative_parameters.find(i_name) != base_derivative_parameters.end());
vector<double> tmp_del_numeric_par_vec;
double derivative_par_value = base_derivative_parameters.get_rec(i_name);
success = get_derivative_parameters(i_name, derivative_par_value, par_transform, group_info, ctl_par_info,
tmp_del_numeric_par_vec, phiredswh_flag);
if (success && !tmp_del_numeric_par_vec.empty())
{
// update changed model parameters in model_parameters
for (const auto &par : tmp_del_numeric_par_vec)
{
Parameters new_pars;
new_pars.insert(make_pair(i_name, par));
par_transform.active_ctl2model_ip(new_pars);
for (auto &ipar : new_pars)
{
model_parameters[ipar.first] = ipar.second;
}
int id = run_manager.add_run(model_parameters, i_name, par);
if (par_run_map.count(i_name) == 0)
par_run_map[i_name] = vector<int>{ id };
else
par_run_map[i_name].push_back(id);
//reset the perturbed parameters back to the values associated with the base condition
for (const auto &ipar : new_pars)
{
model_parameters[ipar.first] = base_model_parameters[ipar.first];
}
}
}
else
{
cout << endl << " warning: failed to compute parameter deriviative for " << i_name << endl;
file_manager.rec_ofstream() << " warning: failed to compute parameter deriviative for " << i_name << endl;
failed_parameter_names.insert(i_name);
failed_to_increment_parmaeters.insert(i_name, derivative_par_value);
}
}
output_file_writer_ptr->write_jco_run_id(run_manager.get_cur_groupid(), par_run_map);
ofstream &fout_restart = file_manager.get_ofstream("rst");
debug_print(failed_parameter_names);
debug_msg("Jacobian_1to1::build_runs end");
if (failed_parameter_names.size() > 0)
return false;
return true;
}
bool Jacobian_1to1::build_runs(ModelRun &init_model_run, vector<string> numeric_par_names, ParamTransformSeq &par_transform,
const ParameterGroupInfo &group_info, const ParameterInfo &ctl_par_info,
RunManagerAbstract &run_manager, set<string> &out_of_bound_par, bool phiredswh_flag, bool calc_init_obs)
{
//Parameters pars = init_model_run.get_ctl_pars();
//Observations obs = init_model_run.get_obs_template();
//return build_runs(pars, obs, numeric_par_names, par_transform, group_info, ctl_par_info, run_manager, out_of_bound_par, phiredswh_flag, calc_init_obs);
Parameters model_parameters(par_transform.ctl2model_cp(init_model_run.get_ctl_pars()));
base_numeric_parameters = par_transform.ctl2numeric_cp(init_model_run.get_ctl_pars());
run_manager.reinitialize(file_manager.build_filename("rnj"));
debug_msg("Jacobian_1to1::build_runs begin");
failed_parameter_names.clear();
failed_ctl_parameters.clear();
// add base run
int run_id = run_manager.add_run(model_parameters, "", 0);
//if base run is has already been complete, update it and mark it as complete
// compute runs for to jacobain calculation as it is influenced by derivative type( forward or central)
if (!calc_init_obs) {
const Observations &init_obs = init_model_run.get_obs();
run_manager.update_run(run_id, model_parameters, init_obs);
}
Parameters new_derivative_pars;
bool success;
Parameters base_derivative_parameters = par_transform.numeric2active_ctl_cp(base_numeric_parameters);
Parameters base_model_parameters = par_transform.numeric2model_cp(base_numeric_parameters);
//Loop through derivative parameters and build the parameter sets necessary for computing the jacobian
std::map<string, vector<int>> par_run_map;
for (auto &i_name : numeric_par_names)
{
assert(base_derivative_parameters.find(i_name) != base_derivative_parameters.end());
vector<double> tmp_del_numeric_par_vec;
double derivative_par_value = base_derivative_parameters.get_rec(i_name);
success = get_derivative_parameters(i_name, derivative_par_value, par_transform, group_info, ctl_par_info,
tmp_del_numeric_par_vec, phiredswh_flag);
if (success && !tmp_del_numeric_par_vec.empty())
{
// update changed model parameters in model_parameters
for (const auto &par : tmp_del_numeric_par_vec)
{
Parameters new_pars;
new_pars.insert(make_pair(i_name, par));
par_transform.active_ctl2model_ip(new_pars);
for (auto &ipar : new_pars)
{
model_parameters[ipar.first] = ipar.second;
}
int id = run_manager.add_run(model_parameters, i_name, par);
if (par_run_map.count(i_name) == 0)
par_run_map[i_name] = vector<int>{ id };
else
par_run_map[i_name].push_back(id);
//reset the perturbed parameters back to the values associated with the base condition
for (const auto &ipar : new_pars)
{
model_parameters[ipar.first] = base_model_parameters[ipar.first];
}
}
}
else
{
cout << endl << " warning: failed to compute parameter deriviative for " << i_name << endl;
file_manager.rec_ofstream() << " warning: failed to compute parameter deriviative for " << i_name << endl;
failed_parameter_names.insert(i_name);
failed_to_increment_parmaeters.insert(i_name, derivative_par_value);
}
}
output_file_writer_ptr->write_jco_run_id(run_manager.get_cur_groupid(), par_run_map);
ofstream &fout_restart = file_manager.get_ofstream("rst");
debug_print(failed_parameter_names);
debug_msg("Jacobian_1to1::build_runs end");
output_file_writer_ptr->write_jco_run_id(run_manager.get_cur_groupid(), par_run_map);
if (failed_parameter_names.size() > 0)
return false;
return true;
}
void Jacobian_1to1::make_runs(RunManagerAbstract &run_manager)
{
// make model runs
run_manager.run();
}
bool Jacobian_1to1::process_runs(ParamTransformSeq &par_transform,
const ParameterGroupInfo &group_info,
RunManagerAbstract &run_manager, const PriorInformation &prior_info, bool splitswh_flag)
{
debug_msg("Jacobian_1to1::process_runs begin");
base_sim_obs_names = run_manager.get_obs_name_vec();
vector<string> prior_info_name = prior_info.get_keys();
base_sim_obs_names.insert(base_sim_obs_names.end(), prior_info_name.begin(), prior_info_name.end());
std::vector<Eigen::Triplet<double> > triplet_list;
unordered_map<string, int> par2col_map = get_par2col_map();
unordered_map<string, int>::iterator found;
unordered_map<string, int>::iterator not_found = par2col_map.end();
JacobianRun base_run;
int i_run = 0;
// get base run parameters and observation for initial model run from run manager storage
run_manager.get_model_parameters(i_run, base_run.ctl_pars);
bool success = run_manager.get_observations_vec(i_run, base_run.obs_vec);
if (!success)
{
throw(PestError("Error: Base parameter run failed. Can not compute the Jacobian"));
}
par_transform.model2ctl_ip(base_run.ctl_pars);
base_numeric_parameters = par_transform.ctl2numeric_cp(base_run.ctl_pars);
++i_run;
// process the parameter pertubation runs
int nruns = run_manager.get_nruns();
base_numeric_par_names.clear();
int icol = 0;
int r_status;
vector<string>par_name_vec;
string cur_par_name;
string par_name_next;
int run_status_next;
double par_value_next;
double cur_numeric_par_value;
list<JacobianRun> run_list;
for(; i_run<nruns; ++i_run)
{
run_list.push_back(JacobianRun());
run_manager. get_info(i_run, r_status, cur_par_name, cur_numeric_par_value);
run_manager.get_model_parameters(i_run, run_list.back().ctl_pars);
bool success = run_manager.get_observations_vec(i_run, run_list.back().obs_vec);
run_list.back().numeric_derivative_par = cur_numeric_par_value;
if (success)
{
par_transform.model2ctl_ip(run_list.back().ctl_pars);
// get the updated parameter value which reflects roundoff errors
par_name_vec.clear();
par_name_vec.push_back(cur_par_name);
Parameters numeric_pars(run_list.back().ctl_pars, par_name_vec);
par_transform.ctl2numeric_ip(numeric_pars);
run_list.back().numeric_derivative_par = numeric_pars.get_rec(cur_par_name);
}
else
{
run_list.pop_back();
}
// read information associated with the next model run;
if (i_run+1<nruns)
{
run_manager.get_info(i_run+1, run_status_next, par_name_next, par_value_next);
}
if( i_run+1>=nruns || (cur_par_name !=par_name_next) )
{
if (!run_list.empty())
{
base_numeric_par_names.push_back(cur_par_name);
base_run.numeric_derivative_par = base_numeric_parameters.get_rec(cur_par_name);
double cur_numeric_value = base_run.numeric_derivative_par;
run_list.push_front(base_run);
std::vector<Eigen::Triplet<double> > tmp_triplet_vec = calc_derivative(cur_par_name, cur_numeric_value, icol, run_list, group_info, prior_info, splitswh_flag);
triplet_list.insert( triplet_list.end(), tmp_triplet_vec.begin(), tmp_triplet_vec.end() );
icol++;
}
else
{
failed_parameter_names.insert(cur_par_name);
failed_ctl_parameters.insert(cur_par_name, cur_numeric_par_value);
}
run_list.clear();
}
}
matrix.resize(base_sim_obs_names.size(), base_numeric_par_names.size());
matrix.setZero();
matrix.setFromTriplets(triplet_list.begin(), triplet_list.end());
// clean up
ofstream &fout_restart = file_manager.get_ofstream("rst");
run_manager.free_memory();
debug_print(failed_parameter_names);
debug_msg("Jacobian_1to1::process_runs end");
return true;
}
bool Jacobian_1to1::get_derivative_parameters(const string &par_name, double par_value, const ParamTransformSeq &par_trans, const ParameterGroupInfo &group_info, const ParameterInfo &ctl_par_info,
vector<double> &delta_numeric_par_vec, bool phiredswh_flag)
{
bool success = false;
const ParameterGroupRec *g_rec = group_info.get_group_rec_ptr(par_name);
if (g_rec->forcen != "ALWAYS_2" && (g_rec->forcen == "ALWAYS_3" || phiredswh_flag == true) ) {
// Central Difference
vector<double> new_par_vec;
vector<Parameters> dir_numeric_pars_vec;
success = central_diff(par_name, par_value, group_info, ctl_par_info, par_trans, new_par_vec, dir_numeric_pars_vec);
if (success)
{
for (auto & ipar : new_par_vec)
{
delta_numeric_par_vec.push_back(ipar);
}
}
}
if (!success) {
// Forward Difference
success = forward_diff(par_name, par_value, group_info, ctl_par_info, par_trans, par_value);
if(success)
{
delta_numeric_par_vec.push_back(par_value);
}
}
return success;
}
bool Jacobian_1to1::forward_diff(const string &par_name, double base_derivative_val,
const ParameterGroupInfo &group_info, const ParameterInfo &ctl_par_info, const ParamTransformSeq &par_trans, double &new_par_val)
{
const ParameterRec *par_info_ptr = ctl_par_info.get_parameter_rec_ptr(par_name);
Parameters new_par;
bool out_of_bound_forward;
bool out_of_bound_backward;
vector<string> out_of_bound__forward_par_vec;
vector<string> out_of_bound__backard_par_vec;
string tmp_name;
// perturb derivative parameters
double incr = derivative_inc(par_name, group_info, base_derivative_val, false);
if (incr == 0.0) return false;
new_par_val = new_par[par_name] = base_derivative_val + incr;
// try forward derivative
out_of_bound_forward = out_of_bounds(new_par, par_info_ptr);
if (!out_of_bound_forward) {
return true;
}
// try backward derivative if forward derivative didn't work
new_par.clear();
new_par_val = new_par[par_name] = base_derivative_val - incr;
out_of_bound_backward = out_of_bounds(new_par, par_info_ptr);
if (!out_of_bound_backward)
{
return true;
}
return false;
}
bool Jacobian_1to1::central_diff(const string &par_name, double base_derivative_val,
const ParameterGroupInfo &group_info, const ParameterInfo &ctl_par_info, const ParamTransformSeq &par_trans, vector<double> &new_par_vec,
vector<Parameters> &perturb_derivative_par_vec)
{
double new_par;
bool out_of_bnds_forward, out_of_bnds_back, out_of_bnds;
Parameters perturb_derivative_pars;
string tmp_name;
const ParameterRec *par_info_ptr = ctl_par_info.get_parameter_rec_ptr(par_name);
double incr = derivative_inc(par_name, group_info, base_derivative_val, true);
if (incr == 0.0) return false;
// try backward difference
new_par = perturb_derivative_pars[par_name] = base_derivative_val - incr;
out_of_bnds_back = out_of_bounds(perturb_derivative_pars, par_info_ptr);
if (!out_of_bnds_back) {
new_par_vec.push_back(new_par);
perturb_derivative_par_vec.push_back(perturb_derivative_pars);
}
// try forward derivative
new_par = perturb_derivative_pars[par_name] = base_derivative_val + incr;
out_of_bnds_forward = out_of_bounds(perturb_derivative_pars, par_info_ptr);
if (!out_of_bnds_forward) {
new_par_vec.push_back(new_par);
perturb_derivative_par_vec.push_back(perturb_derivative_pars);
}
// if backward difference was out of bounds do a second forward derivative
if (out_of_bnds_back) {
new_par = perturb_derivative_pars[par_name] = base_derivative_val + 2.0 * incr;
out_of_bnds = out_of_bounds(perturb_derivative_pars, par_info_ptr);
if (!out_of_bnds) {
new_par_vec.push_back(new_par);
perturb_derivative_par_vec.push_back(perturb_derivative_pars);
}
else
{
return false; // can't do central difference without going out of bounds
}
}
// if forward difference was out of bounds do a second backward derivative
if (out_of_bnds_forward) {
new_par = perturb_derivative_pars[par_name] = base_derivative_val - 2.0 * incr;
out_of_bnds = out_of_bounds(perturb_derivative_pars, par_info_ptr);
if (!out_of_bnds) {
new_par_vec.insert(new_par_vec.begin(), new_par);
perturb_derivative_par_vec.push_back(perturb_derivative_pars);
}
else
{
return false; // can't do central difference without going out of bounds
}
}
return true;
}
bool Jacobian_1to1::out_of_bounds(const Parameters &ctl_parameters,
const ParameterRec *par_info_ptr) const
{
bool out_of_bounds=false;
// This will always only contain one entry one 1 to 1 Jacobians
for (auto &p : ctl_parameters)
{
double max = par_info_ptr->ubnd;
double min = par_info_ptr->lbnd;
if (p.second > max || p.second < min) {
out_of_bounds = true;
}
}
return out_of_bounds;
}
void Jacobian_1to1::report_errors(std::ostream &fout)
{
if (failed_to_increment_parmaeters.size() > 0)
{
fout << " Parameters that went out of bounds while comuting jacobian" << endl;
fout << " Parameter" << endl;
fout << " Name" << endl;
fout << " ----------" << endl;
}
for (const auto & ipar : failed_to_increment_parmaeters)
{
fout << right;
fout << " " << setw(12) << ipar.first << endl;
}
if (failed_to_increment_parmaeters.size() > 0)
{
fout << endl;
}
if (failed_ctl_parameters.size() > 0)
{
fout << " Parameters whose perturbation runs failed while computing jacobian" << endl;
fout << " Parameter Failed" << endl;
fout << " Name Value" << endl;
fout << " ---------- ------------" << endl;
}
for (const auto & ipar : failed_ctl_parameters)
{
fout << right;
fout << " " << setw(12) << ipar.first;
fout << right;
fout << " " << setw(12) << ipar.second << endl;
}
}
| 36.562628 | 196 | 0.76171 | [
"vector",
"model"
] |
09418236779cc5f2ddfda98dbb60702de20b065f | 1,063 | cpp | C++ | aws-cpp-sdk-lakeformation/source/model/DeleteDataCellsFilterRequest.cpp | perfectrecall/aws-sdk-cpp | fb8cbebf2fd62720b65aeff841ad2950e73d8ebd | [
"Apache-2.0"
] | 1 | 2022-02-12T08:09:30.000Z | 2022-02-12T08:09:30.000Z | aws-cpp-sdk-lakeformation/source/model/DeleteDataCellsFilterRequest.cpp | perfectrecall/aws-sdk-cpp | fb8cbebf2fd62720b65aeff841ad2950e73d8ebd | [
"Apache-2.0"
] | 1 | 2022-01-03T23:59:37.000Z | 2022-01-03T23:59:37.000Z | aws-cpp-sdk-lakeformation/source/model/DeleteDataCellsFilterRequest.cpp | ravindra-wagh/aws-sdk-cpp | 7d5ff01b3c3b872f31ca98fb4ce868cd01e97696 | [
"Apache-2.0"
] | 1 | 2021-11-09T11:58:03.000Z | 2021-11-09T11:58:03.000Z | /**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/lakeformation/model/DeleteDataCellsFilterRequest.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <utility>
using namespace Aws::LakeFormation::Model;
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
DeleteDataCellsFilterRequest::DeleteDataCellsFilterRequest() :
m_tableCatalogIdHasBeenSet(false),
m_databaseNameHasBeenSet(false),
m_tableNameHasBeenSet(false),
m_nameHasBeenSet(false)
{
}
Aws::String DeleteDataCellsFilterRequest::SerializePayload() const
{
JsonValue payload;
if(m_tableCatalogIdHasBeenSet)
{
payload.WithString("TableCatalogId", m_tableCatalogId);
}
if(m_databaseNameHasBeenSet)
{
payload.WithString("DatabaseName", m_databaseName);
}
if(m_tableNameHasBeenSet)
{
payload.WithString("TableName", m_tableName);
}
if(m_nameHasBeenSet)
{
payload.WithString("Name", m_name);
}
return payload.View().WriteReadable();
}
| 18.649123 | 69 | 0.74318 | [
"model"
] |
09420b2ac78bd0752600b866b4f2daca8b85f480 | 13,008 | cpp | C++ | FSM.cpp | mohamedashraftaha/MultiFSM | 328d49f6f4507a201ba2d299eb3a08c0d46b30af | [
"MIT"
] | null | null | null | FSM.cpp | mohamedashraftaha/MultiFSM | 328d49f6f4507a201ba2d299eb3a08c0d46b30af | [
"MIT"
] | null | null | null | FSM.cpp | mohamedashraftaha/MultiFSM | 328d49f6f4507a201ba2d299eb3a08c0d46b30af | [
"MIT"
] | null | null | null | //
// Created by mohamedashraf on 10/24/21.
//
#include "FSM.h"
#include "out.h"
#include <ios>
#include <mutex>
#include <sstream>
#include<fstream>
#include <stdexcept>
#include <string>
#define debug 0 // set to 1 in case of debugging
FSM::FSM(){};
//##############################################
FSM::FSM(string name,vector<var>* v, mutex * m, mutex* m1) : machineName(name), commonvars(v), outWaitmtx(m), exprMutex(m1){
};
//##############################################
void FSM::parser(const string filename,const string& outFile, mutex* m, mutex*m1) {
// getting filename from the filename path
// getting index of the . , then extracting substring from the start till the
// . to get the file name
ifstream file(filename.c_str());
bool statesExists(false),transitionsExists(false);
vector<string> linesVector;
if (!file) {
cout << "Cannot Open " << filename << endl;
throw runtime_error("File Cannot be opened \n");
}
// get all the lines to make it easier to read specific block
// for example read from the line after the one that contains states
// until the transitions
getLineByLine(linesVector, file);
if (debug)
for(auto x : linesVector){
cout<<x<<endl;
}
int indexOfStates(0);
for (int i(0); i < linesVector.size(); ++i) {
string token = linesVector[i].substr(0, linesVector[i].find(' '));
if (token == "FSM")
{
// FSM fsmOne then we get FSM alone and fsmOne alone
machineName = linesVector[i].substr(linesVector[i].find(' ') + 1);
}
if (token == "VAR") {
int StringStartIndex = 0;
int StringEndIndex = linesVector[i].find(' ');
if (debug)
cout << linesVector[i].substr(StringStartIndex,StringEndIndex - StringStartIndex)<< endl;
// Extracting the variables names
StringStartIndex = linesVector[i].find(' ') + 1;
string varsNames;
varsNames = linesVector[i].substr(StringStartIndex, linesVector[i].size());
parseVars(varsNames);
}
if (token == "States:") {
string tempToken;
// getting the block after states * The definition of the states *
int j(i + 1);
while (tempToken != "Transitions:") {
// now we have all the states
parseStates(linesVector[j],outFile, m,m1);
++j;
tempToken = linesVector[j].substr(0, linesVector[j].find(' '));
}
statesExists = true;
}
if (token == "Transitions:") {
if(!statesExists)
throw runtime_error("File is corrupted: No States Exist!\n");
string tempToken;
int j(i + 1);
while (j < linesVector.size()) {
parseTransitions(linesVector[j]);
++j;
tempToken = linesVector[j].substr(0, linesVector[j].find(' '));
}
transitionsExists = true;
}
}
if(!transitionsExists)
throw runtime_error("File is corrupted: No Transitions Exist!\n");
file.close();
}
//#############################################
void FSM::getLineByLine(vector<string> & v, ifstream & f){
string line;
while (getline(f, line)) {
// if there is an empty line in the file between states and transitions for example
// to avoid any errors in parsing because of empty lines
if(!line.empty()){
v.push_back(line);
}
}
};
//##############################################
void FSM::parseVars(const string varString) {
string vs = varString;
if (debug)
// trying a string with more than one 2 Vars to make sure that it is generic
vs = "X, Y, Z";
// extracting variable by variable
// Remove all commas for easy parsing
vs.erase(remove(vs.begin(), vs.end(), ','),vs.end());
stringstream ss(vs);
string singleVar;
while (ss >> singleVar) {
// 0 is initial value
var x(singleVar, 0);
variablesVec.push_back(x);
}
}
//##############################################
void FSM::parseStates(const string stateDefinition, const string& outFile, mutex * m, mutex* m1) {
string sd;
string NameOfState;
int endIndex = stateDefinition.find(':');
// Extracting the name of the state
NameOfState = stateDefinition.substr(0, endIndex);
// get actions
string actions = stateDefinition.substr(endIndex + 2);
string actionstemp = "";
state s;
vector<statesActions *> vecActions;
s.setName(NameOfState);
// used specifically to handle the case of the last action
actions.append(",");
// get states by looping over char by char until reaching a delimiter ','
for (int i = 0; i < actions.length(); ++i) {
if (actions[i] != ',')
actionstemp += actions[i];
else {
string Type, Def;
if (actionstemp[0] == ' ')
actionstemp.erase(0, 1);
// extracting type and definition
// my logic is when there is no space between type and definition
// then it is addition i.e X=X+1 or wait or end
if (actionstemp.find(' ') < actionstemp.length()) {
int endIndex = actionstemp.find_first_of(' ');
Type = actionstemp.substr(0, endIndex);
Def = actionstemp.substr(endIndex + 1);
// case where we want to output the value of variable X for example
if (Type == "out") {
int val, idx_of_VariableName, idx_of_COMVARname; // store idx of the VAR
string VAR_Char;
bool is_VAR = false; // if VAR
for (int i(0); i < variablesVec.size(); ++i) {
if (variablesVec[i].getName() == Def) {
idx_of_VariableName = i;
val = variablesVec[i].getValue();
VAR_Char = Def;
Def = to_string(val);
is_VAR = true;
}
}
// if it is a variable and is not defined in variables vector i.e. is_VAR = false
// then we are trying to output a variable that was not defined
/* for MFSM added a checker for COMVAR as well*/
bool is_COMVAR = false;
for(int i{0}; i < commonvars->size();++i){
if((*commonvars)[i].getName() == Def){
idx_of_COMVARname = i;
val = (*commonvars)[i].getValue();
VAR_Char = Def;
Def = to_string(val);
is_COMVAR = true;
}
}
/* if no comvar or var then it is an error*/
if (Def[0] >= 'A' && Def[0] <='Z' && !is_VAR /*&& !is_COMVAR*/){
string ErrString = "Error!: VAR "+Def+" is not defined in the VAR section!";
throw runtime_error(ErrString);
}
// remove quotes
Def.erase(remove(Def.begin(), Def.end(), '"'), Def.end());
// pusshing object of type out action to vector of type actions
// passing address of object of type var -> containint VarName,Value:
// e.g. X,1 so that we can print the updated value
out *outOp = new out(&(*commonvars)[idx_of_COMVARname],&variablesVec[idx_of_VariableName],\
Type, Def,VAR_Char, is_VAR,is_COMVAR,outFile,outWaitmtx, machineName);
vecActions.push_back(outOp);
s.setStateActions(vecActions);
// to avoid adding old output to new output
vecActions.pop_back();
}
if (Type == "sleep") {
int secs = stoi(Def);
sleep *sleepOp = new sleep(Type, actionstemp, secs,outFile);
vecActions.push_back(sleepOp);
s.setStateActions(vecActions);
// to avoid adding old output to new output
vecActions.pop_back();
}
} else {
if (actionstemp == "wait") {
// call wait
WaitAct.setCurrState(NameOfState);
WaitAct.setNextState("");
WaitAct.setGoToVal(0);
wait *waitOp = new wait(actionstemp, &WaitAct, NameOfState,&transitionsVec,machineName,outFile, outWaitmtx );
vecActions.push_back(waitOp);
s.setStateActions(vecActions);
// to avoid adding old output to new output
vecActions.pop_back();
}
if (actionstemp == "end") {
// call endAction
endAction *endOp = new endAction(actionstemp,outFile);
vecActions.push_back(endOp);
s.setStateActions(vecActions);
// to avoid adding old output to new output
vecActions.pop_back();
}
if (actionstemp.find('+') <= actionstemp.size()) {
Type = "add";
int operand1(-1), operand2(-1);
string actionVarOp1(""), actionVarOp2("");
// fixed the issue of having variables with more than 1 number -> i.e
// X=100+100
int EqualIdx = actionstemp.find('=');
int plusIdx = actionstemp.find('+');
for (int i(EqualIdx + 1); i < plusIdx; ++i)
actionVarOp1 += actionstemp[i];
for (int i(plusIdx + 1); i < actionstemp.size(); ++i)
actionVarOp2 += actionstemp[i];
string resultName = "";
resultName += actionstemp[0];
pair<string, int> o1, o2;
int idx_of_resultVar(0);
// pusshing object of type out action to vector of type actions
// passing address of the vector var -> containint VarName,Value: e.g.
// X,1 so that we can update the value already in X(as an example)
// with the other operand
add *addOp = new add(commonvars,&variablesVec, Type,
actionstemp,idx_of_resultVar, actionVarOp1, actionVarOp2,outFile,resultName, m1);
vecActions.push_back(addOp);
s.setStateActions(vecActions);
// to avoid adding old output to new output
vecActions.pop_back();
}
}
if (debug)
cout << actionstemp << endl;
actionstemp = "";
}
}
// push the state
statesVec.push_back(s);
}
//##############################################
void FSM::parseTransitions(const string transitionString) {
string ts = transitionString;
// remove all commas for easier parsing
ts.erase(remove(ts.begin(), ts.end(), ','),ts.end());
// remove all spaces for easier parsing
ts.erase(remove(ts.begin(), ts.end(), ' '),ts.end());
string currS = "";
currS += ts[0]; // convert to string
string nextS = "";
nextS += ts[1]; // convert to string
int gotoS = ts[2] - '0'; // convert to int
transition t(currS, nextS, gotoS);
transitionsVec.push_back(t);
}
//##############################################
void FSM::runFSM() {
// parsing the file to get
// -> 1. machine name
// -> 2. Var
// -> 3. states
// -> 4. Transition
// creating an output file
string mName = machineName.substr(machineName.find('/')+1);
string outFileName = "testfiles/outputFiles/OUT"+mName;
parser(machineName,outFileName, outWaitmtx,exprMutex);
ofstream outFile;
outFile.open(outFileName);
transition transitionTrack; // keep track of transitions;
transitionTrack.setCurrState(statesVec[0].getName()); // initially state A
vector<statesActions *> sActions; // get actions in each state
ofstream f;
outFile << "########## FSM RUNNING ##########\n\n";
outFile << "FSM Name: " << machineName << "\n\n";
outFile <<"############# ACTIVE STATE: "+ statesVec[0].getName()+" ################\n";
outFile.close();
// infinite loop
for (;;) {
for (auto stateInst:statesVec) {
if (transitionTrack.getCurrState() == stateInst.getName()) {
sActions = stateInst.getStateActions();
for (auto ActionsInst : sActions) {
if (ActionsInst->getActionType() == "wait") {
ActionsInst->runAction();
int toWhichState;
// now we have the value by which we know how to go to next state
// now we loop over transitions vector to identify what is the next
// state based on the current state and the goto value
toWhichState = WaitAct.getGoToVal();
for (auto transitionInst: transitionsVec) {
if (transitionInst.getCurrState() == transitionTrack.getCurrState() && transitionInst.getGoToVal() == toWhichState) {
string nextState = transitionInst.getNextState();
transitionTrack.setCurrState(nextState);
f.open(outFileName,ios::app);
f << "\n~~~~~~~~~ Moving to the Next State: \""<< transitionTrack.getCurrState()<< "\"~~~~~~~~~~~~~~~~~~~~~~~~~~\n"<< endl;
f <<"############# ACTIVE STATE: "+ transitionTrack.getCurrState()+" ################\n";
f.close();
break;
}
}
break;
}
ActionsInst->runAction();
if (ActionsInst->getActionType() =="end"){
return;
}
}
}
}
}
}
//###################################################
FSM::~FSM() {
if (debug)
cout << "FSM::~FSM()";
}; | 34.503979 | 139 | 0.560424 | [
"object",
"vector"
] |
0942137f2f84aa19aced68b5a51c39db1f440684 | 6,807 | hpp | C++ | 3rdparty/ofdis/include/litiv/3rdparty/ofdis/oflow.hpp | jpjodoin/litiv | 435556bea20d60816aff492f50587b1a2d748b21 | [
"BSD-3-Clause"
] | 97 | 2015-10-16T04:32:33.000Z | 2022-03-29T07:04:02.000Z | 3rdparty/ofdis/include/litiv/3rdparty/ofdis/oflow.hpp | jpjodoin/litiv | 435556bea20d60816aff492f50587b1a2d748b21 | [
"BSD-3-Clause"
] | 19 | 2016-07-01T16:37:02.000Z | 2020-09-10T06:09:39.000Z | 3rdparty/ofdis/include/litiv/3rdparty/ofdis/oflow.hpp | jpjodoin/litiv | 435556bea20d60816aff492f50587b1a2d748b21 | [
"BSD-3-Clause"
] | 41 | 2015-11-17T05:59:23.000Z | 2022-02-16T09:30:28.000Z |
#pragma once
#ifndef OFDIS_INTERNAL
#error "must only include 'ofdis.hpp' header for API"
#endif //ndef(OFDIS_INTERNAL)
#include "litiv/3rdparty/ofdis/utils.hpp"
namespace ofdis {
struct camparam {
int width; // image width, does not include '2*imgpadding', but includes original padding to ensure integer divisible image width and height
int height; // image height, does not include '2*imgpadding', but includes original padding to ensure integer divisible image width and height
int imgpadding; // image padding in pixels at all sides, images padded with replicated border, gradients padded with zero, ADD THIS ONLY WHEN ADDRESSING THE IMAGE OR GRADIENT
float tmp_lb; // lower bound for valid image region, pre-compute for image padding to avoid border check
float tmp_ubw; // upper width bound for valid image region, pre-compute for image padding to avoid border check
float tmp_ubh; // upper height bound for valid image region, pre-compute for image padding to avoid border check
int tmp_w; // width + 2*imgpadding
int tmp_h; // height + 2*imgpadding
float sc_fct; // scaling factor at current scale
int curr_lv; // current level
int camlr; // 0: left camera, 1: right camera, used only for depth, to restrict sideways patch motion
};
struct optparam {
// Explicitly set parameters:
int sc_f; // first (coarsest) scale
int sc_l; // last (finest) scale
int p_samp_s; // patch size (edge length in pixels)
int max_iter; // max. iterations on one scale
int min_iter; // min. iterations on one scale
float dp_thresh; // minimum rate of change of delta_p before descending one level, e.g. .1 : change scales when norm(delta_p_last)/norm(delta_p_init) < .1
float dr_thresh; // minimum rate of change of residual within 3-iterations-window before descending one level, e.g. .8 : res_new/res_old > * .8, SET HIGH (1e10) TO DISABLE
float res_thresh; // if (mean absolute) residual falls below this threshold, terminate iterations on current scale, IGNORES MIN_ITER , SET TO LOW (1e-10) TO DISABLE
int patnorm; // Use patch mean-normalization
int verbosity; // Verbosity, 0: plot nothing, 1: final internal timing 2: complete iteration timing, (UNCOMMENTED -> 3: Display flow scales, 4: Display flow scale iterations)
bool usefbcon; // use forward-backward flow merging
int costfct; // Cost function: 0: L2-Norm, 1: L1-Norm, 2: PseudoHuber-Norm
bool usetvref; // TV parameters
float tv_alpha;
float tv_gamma;
float tv_delta;
int tv_innerit;
int tv_solverit;
float tv_sor; // Successive-over-relaxation weight
// Automatically set parameters / fixed parameters
int nop; // number of parameters per pixel, 1 for depth, 2 for optical flow, 4 for scene flow
float patove; // point/line padding to all sides (px)
float outlierthresh; // displacement threshold (in px) before a patch is flagged as outlier
int steps; // horizontal and vertical distance (in px) between patch centers
int novals; // number of points in patch (=p_samp_s*p_samp_s)
int noc; // number of channels in image and gradients
int noscales; // total number of scales
float minerrval = 2.0f; // 1/max(this, error) for pixel averaging weight
float normoutlier = 5.0f; // norm error threshold for huber norm
// Helper variables
v4sf zero = (v4sf){0.0f,0.0f,0.0f,0.0f};
v4sf negzero = (v4sf){-0.0f,-0.0f,-0.0f,-0.0f};
v4sf half = (v4sf){0.5f,0.5f,0.5f,0.5f};
v4sf ones = (v4sf){1.0f,1.0f,1.0f,1.0f};
v4sf twos = (v4sf){2.0f,2.0f,2.0f,2.0f};
v4sf fours = (v4sf){4.0f,4.0f,4.0f,4.0f};
v4sf normoutlier_tmpbsq;
v4sf normoutlier_tmp2bsq;
v4sf normoutlier_tmp4bsq;
};
template<ofdis::FlowInputType eInput, ofdis::FlowOutputType eOutput>
class OFClass {
public:
OFClass(
// expects #sc_f_in pointers to float arrays for images and gradients.
// E.g. im_ao[sc_f_in] will be used as coarsest coarsest, im_ao[sc_l_in] as finest scale
// im_ao[ (sc_l_in-1) : 0 ] can be left as nullptr pointers
// IMPORTANT assumption: mod(width,2^sc_f_in)==0 AND mod(height,2^sc_f_in)==0,
const std::vector<const float*>& im_ao_in,
const std::vector<const float*>& im_ao_dx_in,
const std::vector<const float*>& im_ao_dy_in,
const std::vector<const float*>& im_bo_in,
const std::vector<const float*>& im_bo_dx_in,
const std::vector<const float*>& im_bo_dy_in,
const int imgpadding_in,
// Output-flow:
// has to be of size to fit the last computed OF scale
// [width/2^(last scale), height/2^(last scale)], 1 channel depth / 2 for OF
float* outflow,
// Initialization-flow:
// has to be of size to fit the first computed OF scale
// [width/2^(first scale+1), height/2^(first scale+1)], 1 channel depth / 2 for OF
const float* initflow,
const int width_in,
const int height_in,
const int sc_f_in,
const int sc_l_in,
const int max_iter_in,
const int min_iter_in,
const float dp_thresh_in,
const float dr_thresh_in,
const float res_thresh_in,
const int padval_in,
const float patove_in,
const bool usefbcon_in,
const int costfct_in,
const int noc_in,
const int patnorm_in,
const bool usetvref_in,
const float tv_alpha_in,
const float tv_gamma_in,
const float tv_delta_in,
const int tv_innerit_in,
const int tv_solverit_in,
const float tv_sor_in,
const int verbosity_in
);
private:
const std::vector<const float*>& im_ao,im_ao_dx,im_ao_dy;
const std::vector<const float*>& im_bo,im_bo_dx,im_bo_dy;
optparam op; // Struct for pptimization parameters
std::vector<camparam> cpl,cpr; // Struct (for each scale) for camera/image parameter
};
} // namespace ofdis
| 53.179688 | 192 | 0.599824 | [
"vector"
] |
094aed0323acc30a943df5ac6df3d0498d70cd55 | 25,915 | cc | C++ | app/oxs/ext/uniaxialanisotropy.cc | ViennaNovoFlop/ViennaNovoFlop-dev | f8c4d6c06590a0d9a3890d81e9b0b4dcb7ea9e00 | [
"TCL",
"SWL",
"MIT",
"X11",
"BSD-3-Clause"
] | null | null | null | app/oxs/ext/uniaxialanisotropy.cc | ViennaNovoFlop/ViennaNovoFlop-dev | f8c4d6c06590a0d9a3890d81e9b0b4dcb7ea9e00 | [
"TCL",
"SWL",
"MIT",
"X11",
"BSD-3-Clause"
] | null | null | null | app/oxs/ext/uniaxialanisotropy.cc | ViennaNovoFlop/ViennaNovoFlop-dev | f8c4d6c06590a0d9a3890d81e9b0b4dcb7ea9e00 | [
"TCL",
"SWL",
"MIT",
"X11",
"BSD-3-Clause"
] | null | null | null | /* FILE: uuanisotropy.cc -*-Mode: c++-*-
*
* Uniform Uniaxial Anisotropy, derived from Oxs_Energy class.
*
*/
#include <string>
#include "oc.h"
#include "nb.h"
#include "threevector.h"
#include "director.h"
#include "simstate.h"
#include "ext.h"
#include "key.h"
#include "mesh.h"
#include "meshvalue.h"
#include "uniformscalarfield.h"
#include "uniformvectorfield.h"
#include "rectangularmesh.h" // For QUAD-style integration
#include "uniaxialanisotropy.h"
#include "energy.h" // Needed to make MSVC++ 5 happy
OC_USE_STRING;
// Oxs_Ext registration support
OXS_EXT_REGISTER(Oxs_UniaxialAnisotropy);
/* End includes */
// Constructor
Oxs_UniaxialAnisotropy::Oxs_UniaxialAnisotropy(
const char* name, // Child instance id
Oxs_Director* newdtr, // App director
const char* argstr) // MIF input block parameters
: Oxs_ChunkEnergy(name,newdtr,argstr), mesh_id(0),
K1_is_uniform(0),axis_is_uniform(0),uniform_K1_value(0.0),
integration_method(UNKNOWN_INTEG)
{
// Process arguments
OXS_GET_INIT_EXT_OBJECT("K1",Oxs_ScalarField,K1_init);
Oxs_UniformScalarField* tmpK1ptr
= dynamic_cast<Oxs_UniformScalarField*>(K1_init.GetPtr());
if(tmpK1ptr) {
// Initialization is via a uniform field; set up uniform
// K1 variables.
K1_is_uniform = 1;
uniform_K1_value = tmpK1ptr->SoleValue();
}
OXS_GET_INIT_EXT_OBJECT("axis",Oxs_VectorField,axis_init);
Oxs_UniformVectorField* tmpaxisptr
= dynamic_cast<Oxs_UniformVectorField*>(axis_init.GetPtr());
if(tmpaxisptr) {
// Initialization is via a uniform field. For convenience,
// modify the size of the field components to norm 1, as
// required for the axis specification. This allows the
// user to specify the axis direction as, for example, {1,1,1},
// as opposed to {0.57735027,0.57735027,0.57735027}, or
//
// Specify Oxs_UniformVectorField {
// norm 1
// vector { 1 1 1 }
// }
// Also setup uniform axis variables
tmpaxisptr->SetMag(1.0);
axis_is_uniform = 1;
uniform_axis_value = tmpaxisptr->SoleValue();
}
String integration_request = GetStringInitValue("integration","rect");
if(integration_request.compare("rect")==0) {
integration_method = RECT_INTEG;
} else if(integration_request.compare("quad")==0) {
integration_method = QUAD_INTEG;
} else {
String msg=String("Invalid integration request: ")
+ integration_request
+ String("\n Should be either \"rect\" or \"quad\".");
throw Oxs_ExtError(this,msg.c_str());
}
VerifyAllInitArgsUsed();
}
OC_BOOL Oxs_UniaxialAnisotropy::Init()
{
mesh_id = 0;
K1.Release();
axis.Release();
return Oxs_ChunkEnergy::Init();
}
void Oxs_UniaxialAnisotropy::RectIntegEnergy
(const Oxs_SimState& state,
Oxs_ComputeEnergyDataThreaded& ocedt,
Oxs_ComputeEnergyDataThreadedAux& ocedtaux,
OC_INDEX node_start,OC_INDEX node_stop
) const
{
const Oxs_Mesh* mesh = state.mesh;
const Oxs_MeshValue<OC_REAL8m>& Ms_inverse = *(state.Ms_inverse);
const Oxs_MeshValue<ThreeVector>& spin = state.spin;
Nb_Xpfloat energy_sum = 0;
OC_REAL8m k = 0.0;
if(K1_is_uniform) k = uniform_K1_value;
ThreeVector unifaxis;
if(axis_is_uniform) unifaxis = uniform_axis_value;
for(OC_INDEX i=node_start;i<node_stop;++i) {
if(!K1_is_uniform) k = K1[i];
OC_REAL8m field_mult = (2.0/MU0)*k*Ms_inverse[i];
if(field_mult==0.0) {
if(ocedt.energy) (*ocedt.energy)[i] = 0.0;
if(ocedt.H) (*ocedt.H)[i].Set(0.,0.,0.);
if(ocedt.mxH) (*ocedt.mxH)[i].Set(0.,0.,0.);
continue;
}
const ThreeVector& axisi = (axis_is_uniform ? unifaxis : axis[i]);
if(k<=0) {
// Easy plane (hard axis)
OC_REAL8m dot = spin[i].x*axisi.x
+ spin[i].y*axisi.y + spin[i].z*axisi.z;
ThreeVector H = (field_mult*dot)*axisi;
OC_REAL8m ei = -k*dot*dot;
OC_REAL8m tx = spin[i].y*H.z - spin[i].z*H.y; // mxH
OC_REAL8m ty = spin[i].z*H.x - spin[i].x*H.z;
OC_REAL8m tz = spin[i].x*H.y - spin[i].y*H.x;
energy_sum += ei * mesh->Volume(i);
if(ocedt.energy) (*ocedt.energy)[i] = ei;
if(ocedt.energy_accum) (*ocedt.energy_accum)[i] += ei;
if(ocedt.H) (*ocedt.H)[i] = H;
if(ocedt.H_accum) (*ocedt.H_accum)[i] += H;
if(ocedt.mxH) (*ocedt.mxH)[i] = ThreeVector(tx,ty,tz);
if(ocedt.mxH_accum) (*ocedt.mxH_accum)[i] += ThreeVector(tx,ty,tz);
} else {
// Easy axis case. For improved accuracy, we want to report
// energy as -k*(dot*dot-1), where dot = axis * spin. But
// dot*dot-1 suffers from bad loss of precision if spin is
// nearly parallel to axis. The are a couple of ways around
// this. Recall that both spin and axis are unit vectors.
// Then from the cross product:
// (axis x spin)^2 = 1 - dot*dot
// The cross product requires 6 mults and 3 adds, and
// the norm squared takes 3 mult and 2 adds
// => 9 mults + 5 adds.
// Another option is to use
// (axis - spin)^2 = 2*(1-dot)
// so 1 - dot*dot = t*(2-t)
// where t = 0.5*(axis-spin)^2.
// The op count here is
// => 5 mults + 6 adds.
// Another advantage to the second approach is you get 'dot', as
// opposed to dot*dot, which saves a sqrt if dot is needed. The
// downside is that if axis and spin are anti-parallel, then you
// want to use (axis+spin)^2 rather than (axis-spin)^2. I did
// some single-spin test runs and the performance of the two
// methods was about the same. Below we use the cross-product
// formulation. -mjd, 28-Jan-2001
OC_REAL8m dot = spin[i].x*axisi.x
+ spin[i].y*axisi.y + spin[i].z*axisi.z;
OC_REAL8m scale = field_mult*dot;
OC_REAL8m tx = spin[i].y*axisi.z - spin[i].z*axisi.y;
OC_REAL8m ty = spin[i].z*axisi.x - spin[i].x*axisi.z;
OC_REAL8m tz = spin[i].x*axisi.y - spin[i].y*axisi.x;
OC_REAL8m ei = k*(tx*tx+ty*ty+tz*tz);
energy_sum += ei * mesh->Volume(i);
if(ocedt.energy) (*ocedt.energy)[i] = ei;
if(ocedt.energy_accum) (*ocedt.energy_accum)[i] += ei;
if(ocedt.H) (*ocedt.H)[i] = scale*axisi;
if(ocedt.H_accum) (*ocedt.H_accum)[i] += scale*axisi;
if(ocedt.mxH) (*ocedt.mxH)[i]
= ThreeVector(scale*tx,scale*ty,scale*tz);
if(ocedt.mxH_accum) (*ocedt.mxH_accum)[i]
+= ThreeVector(scale*tx,scale*ty,scale*tz);
}
}
ocedtaux.energy_total_accum += energy_sum.GetValue();
}
void Oxs_UniaxialAnisotropy::ComputeEnergyChunk
(const Oxs_SimState& state,
Oxs_ComputeEnergyDataThreaded& ocedt,
Oxs_ComputeEnergyDataThreadedAux& ocedtaux,
OC_INDEX node_start,OC_INDEX node_stop,
int threadnumber
) const
{
if(node_stop>state.mesh->Size() || node_start>node_stop) {
throw Oxs_ExtError(this,"Programming error:"
" Invalid node_start/node_stop values");
}
if(mesh_id != state.mesh->Id()) {
// This is either the first pass through, or else mesh
// has changed. Initialize/update data fields.
// NB: At a lower level, this may potentially involve calls back
// into the Tcl interpreter. Per Tcl spec, only the thread
// originating the interpreter is allowed to make calls into it, so
// only threadnumber == 0 can do this processing. Any other thread
// must block until that processing is complete.
thread_control.Lock();
if(Oxs_ThreadError::IsError()) {
if(thread_control.count>0) {
// Release a blocked thread
thread_control.Notify();
}
thread_control.Unlock();
return; // What else?
}
if(threadnumber != 0) {
if(mesh_id != state.mesh->Id()) {
// If above condition is false, then the main thread came
// though and initialized everything between the time of
// the previous check and this thread's acquiring of the
// thread_control mutex; in which case, "never mind".
// Otherwise:
++thread_control.count; // Multiple threads may progress to this
/// point before the main thread (threadnumber == 0) grabs the
/// thread_control mutex. Keep track of how many, so that
/// afterward they may be released, one by one. (The main
/// thread will Notify control_wait.cond once; after that
/// as each waiting thread is released, the newly released
/// thread sends a Notify to wake up the next one.
thread_control.Wait(0);
--thread_control.count;
int condcheckerror=0;
if(mesh_id != state.mesh->Id()) {
// Error?
condcheckerror=1;
Oxs_ThreadPrintf(stderr,"Invalid condition in"
" Oxs_UniaxialAnisotropy::ComputeEnergyChunk(),"
" thread number %d\n",threadnumber);
}
if(thread_control.count>0) {
// Free a waiting thread.
thread_control.Notify();
}
thread_control.Unlock();
if(condcheckerror || Oxs_ThreadError::IsError()) {
return; // What else?
}
} else {
if(thread_control.count>0) {
// Free a waiting thread. (Actually, it can occur that the
// thread_control will be grabbed by another thread that is
// blocked at the first thread_control mutex Lock() call above
// rather than on the ConditionWait, in which case this
// ConditionNotify will be effectively lost. But that is
// okay, because then *that* thread will Notify when it
// releases the mutex.)
thread_control.Notify();
}
thread_control.Unlock();
}
} else {
// Main thread (threadnumber == 0)
try {
K1_init->FillMeshValue(state.mesh,K1);
axis_init->FillMeshValue(state.mesh,axis);
const OC_INDEX size = state.mesh->Size();
for(OC_INDEX i=0;i<size;i++) {
// Check that axis is a unit vector:
const OC_REAL8m eps = 1e-14;
if(axis[i].MagSq()<eps*eps) {
throw Oxs_ExtError(this,"Invalid initialization detected:"
" Zero length anisotropy axis");
} else {
axis[i].MakeUnit();
}
}
mesh_id = state.mesh->Id();
} catch(Oxs_ExtError& err) {
// Leave unmatched mesh_id as a flag to check
// Oxs_ThreadError for an error.
Oxs_ThreadError::SetError(String(err));
if(thread_control.count>0) {
thread_control.Notify();
}
thread_control.Unlock();
throw;
} catch(String& serr) {
// Leave unmatched mesh_id as a flag to check
// Oxs_ThreadError for an error.
Oxs_ThreadError::SetError(serr);
if(thread_control.count>0) {
thread_control.Notify();
}
thread_control.Unlock();
throw;
} catch(const char* cerr) {
// Leave unmatched mesh_id as a flag to check
// Oxs_ThreadError for an error.
Oxs_ThreadError::SetError(String(cerr));
if(thread_control.count>0) {
thread_control.Notify();
}
thread_control.Unlock();
throw;
} catch(...) {
// Leave unmatched mesh_id as a flag to check
// Oxs_ThreadError for an error.
Oxs_ThreadError::SetError(String("Error in "
"Oxs_UniaxialAnisotropy::ComputeEnergyChunk"));
if(thread_control.count>0) {
thread_control.Notify();
}
thread_control.Unlock();
throw;
}
if(thread_control.count>0) {
// Free a waiting thread. (Actually, it can occur that the
// thread_control will be grabbed by another thread that is
// blocked at the first thread_control mutex Lock() call above
// rather than on the ConditionWait, in which case this
// ConditionNotify will be effectively lost. But that is
// okay, because then *that* thread will Notify when it
// releases the mutex.)
thread_control.Notify();
}
thread_control.Unlock();
}
}
if(integration_method != QUAD_INTEG) {
RectIntegEnergy(state,ocedt,ocedtaux,node_start,node_stop);
return;
}
// Otherwise, use QUAD_INTEG. This implementation is not especially
// efficient, and could presumably be sped up by a good bit if
// needed.
// The QUAD_INTEG code requires a rectangular mesh
const Oxs_RectangularMesh* mesh
= dynamic_cast<const Oxs_RectangularMesh*>(state.mesh);
if(mesh==NULL) {
throw Oxs_ExtError(this,
"Import mesh to Oxs_UniaxialAnisotropy::GetEnergy()"
" is not an Oxs_RectangularMesh object. Quad integration"
" method requires a rectangular mesh.");
}
// Do base evaluations, writing results into scratch space
Oxs_ComputeEnergyDataThreaded work_ocedt(state);
Oxs_ComputeEnergyDataThreadedAux work_ocedtaux;
if(ocedt.energy) {
work_ocedt.energy = work_ocedt.scratch_energy = ocedt.energy;
} else {
ocedt.scratch_energy->AdjustSize(state.mesh); // Thread-safe
work_ocedt.energy = work_ocedt.scratch_energy = ocedt.scratch_energy;
}
if(ocedt.H) {
work_ocedt.H = work_ocedt.scratch_H = ocedt.H;
} else {
ocedt.scratch_H->AdjustSize(state.mesh); // Thread-safe
work_ocedt.H = work_ocedt.scratch_H = ocedt.scratch_H;
}
RectIntegEnergy(state,work_ocedt,work_ocedtaux,node_start,node_stop);
// Edge correction if higher-order integration method requested.
// See mjd's NOTES II, pp 178-181, Aug-2002.
// NOTE: For short dimension lengths, all cells are modified.
Oxs_MeshValue<OC_REAL8m>& energy = *work_ocedt.energy;
Oxs_MeshValue<ThreeVector>& field = *work_ocedt.H;
const OC_INDEX xdim = mesh->DimX();
const OC_INDEX ydim = mesh->DimY();
const OC_INDEX zdim = mesh->DimZ();
const OC_INDEX xydim = xdim*ydim;
OC_INDEX x,y,z;
OC_INDEX xstart,ystart,zstart;
mesh->GetCoords(node_start,xstart,ystart,zstart);
OC_INDEX xstop,ystop,zstop;
mesh->GetCoords(node_stop-1,xstop,ystop,zstop);
// x-axis. Note special case handling for short lengths. Also note
// very lazy handling of node start/stop conditions. With luck, the
// compiler can figure it out. Otherwise, if we ever care to have
// this code run fast, the condition handling should be re-written.
if(xdim>=6) {
for(z=zstart;z<=zstop;++z) {
OC_INDEX ya = (z==zstart ? ystart : 0);
OC_INDEX yb = (z==zstop ? ystop : ydim-1);
for(y=ya;y<=yb;++y) {
OC_INDEX i = mesh->Index(0,y,z); // Get base linear address
if(node_start<=i && i<node_stop) {
energy[i] *= 26./24.; // Left face
field[i] *= 26./24.;
}
if(node_start<=i+1 && i+1<node_stop) {
energy[i+1] *= 21./24.;
field[i+1] *= 21./24.;
}
if(node_start<=i+2 && i+2<node_stop) {
energy[i+2] *= 25./24.;
field[i+2] *= 25./24.;
}
i += xdim-3;
if(node_start<=i && i<node_stop) {
energy[i] *= 25./24.;
field[i] *= 25./24.;
}
if(node_start<=i+1 && i+1<node_stop) {
energy[i+1] *= 21./24.;
field[i+1] *= 21./24.;
}
if(node_start<=i+2 && i+2<node_stop) {
energy[i+2] *= 26./24.; // Right face
field[i+2] *= 26./24.;
}
}
}
} else if(xdim==5) {
for(z=zstart;z<=zstop;++z) {
OC_INDEX ya = (z==zstart ? ystart : 0);
OC_INDEX yb = (z==zstop ? ystop : ydim-1);
OC_INDEX i = mesh->Index(0,ya,z); // Get base linear address
for(y=ya;y<=yb;++y) {
if(node_start<=i && i<node_stop) {
energy[i] *= 26./24.;
field[i] *= 26./24.;
}
if(node_start<=i+1 && i+1<node_stop) {
energy[i+1] *= 21./24.;
field[i+1] *= 21./24.;
}
if(node_start<=i+2 && i+2<node_stop) {
energy[i+2] *= 26./24.;
field[i+2] *= 26./24.;
}
if(node_start<=i+3 && i+3<node_stop) {
energy[i+3] *= 21./24.;
field[i+3] *= 21./24.;
}
if(node_start<=i+4 && i+4<node_stop) {
energy[i+4] *= 26./24.;
field[i+4] *= 26./24.;
}
i += 5;
}
}
} else if(xdim==4) {
for(z=zstart;z<=zstop;++z) {
OC_INDEX ya = (z==zstart ? ystart : 0);
OC_INDEX yb = (z==zstop ? ystop : ydim-1);
OC_INDEX i = mesh->Index(0,ya,z); // Get base linear address
for(y=ya;y<=yb;++y) {
if(node_start<=i && i<node_stop) {
energy[i] *= 26./24.;
field[i] *= 26./24.;
}
if(node_start<=i+1 && i+1<node_stop) {
energy[i+1] *= 22./24.;
field[i+1] *= 22./24.;
}
if(node_start<=i+2 && i+2<node_stop) {
energy[i+2] *= 22./24.;
field[i+2] *= 22./24.;
}
if(node_start<=i+3 && i+3<node_stop) {
energy[i+3] *= 26./24.;
field[i+3] *= 26./24.;
}
i += 4;
}
}
} else if(xdim==3) {
for(z=zstart;z<=zstop;++z) {
OC_INDEX ya = (z==zstart ? ystart : 0);
OC_INDEX yb = (z==zstop ? ystop : ydim-1);
OC_INDEX i = mesh->Index(0,ya,z); // Get base linear address
for(y=ya;y<=yb;++y) {
if(node_start<=i && i<node_stop) {
energy[i] *= 27./24.;
field[i] *= 27./24.;
}
if(node_start<=i+1 && i+1<node_stop) {
energy[i+1] *= 18./24.;
field[i+1] *= 18./24.;
}
if(node_start<=i+2 && i+2<node_stop) {
energy[i+2] *= 27./24.;
field[i+2] *= 27./24.;
}
i += 3;
}
}
}
// Quadratic fit requires 3 points, so no higher order method
// available if xdim<3.
// y-axis. Note special case handling for short lengths.
if(ydim>=6) {
for(z=zstart;z<=zstop;++z) {
// Front face
OC_INDEX i = mesh->Index(0,0,z); // Get base linear address
for(x=0;x<xdim;x++) { // y==0
if(node_start<=i && i<node_stop) {
energy[i] *= 26./24.;
field[i] *= 26./24.;
}
++i;
} // NB: At end of loop, i wraps around to next x-row.
for(x=0;x<xdim;x++) { // y==1
if(node_start<=i && i<node_stop) {
energy[i] *= 21./24.;
field[i] *= 21./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==2
if(node_start<=i && i<node_stop) {
energy[i] *= 25./24.;
field[i] *= 25./24.;
}
++i;
}
// Back face
i = mesh->Index(0,ydim-3,z);
for(x=0;x<xdim;x++) { // y==ydim-3
if(node_start<=i && i<node_stop) {
energy[i] *= 25./24.;
field[i] *= 25./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==ydim-2
if(node_start<=i && i<node_stop) {
energy[i] *= 21./24.;
field[i] *= 21./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==ydim-1
if(node_start<=i && i<node_stop) {
energy[i] *= 26./24.;
field[i] *= 26./24.;
}
++i;
}
}
} else if(ydim==5) {
for(z=zstart;z<=zstop;++z) {
OC_INDEX i = mesh->Index(0,0,z); // Get base linear address
for(x=0;x<xdim;x++) { // y==0
if(node_start<=i && i<node_stop) {
energy[i] *= 26./24.;
field[i] *= 26./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==1
if(node_start<=i && i<node_stop) {
energy[i] *= 21./24.;
field[i] *= 21./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==2
if(node_start<=i && i<node_stop) {
energy[i] *= 26./24.;
field[i] *= 26./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==3
if(node_start<=i && i<node_stop) {
energy[i] *= 21./24.;
field[i] *= 21./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==4
if(node_start<=i && i<node_stop) {
energy[i] *= 26./24.;
field[i] *= 26./24.;
}
++i;
}
}
} else if(ydim==4) {
for(z=zstart;z<=zstop;++z) {
OC_INDEX i = mesh->Index(0,0,z); // Get base linear address
for(x=0;x<xdim;x++) { // y==0
if(node_start<=i && i<node_stop) {
energy[i] *= 26./24.;
field[i] *= 26./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==1
if(node_start<=i && i<node_stop) {
energy[i] *= 22./24.;
field[i] *= 22./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==2
if(node_start<=i && i<node_stop) {
energy[i] *= 22./24.;
field[i] *= 22./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==3
if(node_start<=i && i<node_stop) {
energy[i] *= 26./24.;
field[i] *= 26./24.;
}
++i;
}
}
} else if(ydim==3) {
for(z=zstart;z<=zstop;++z) {
OC_INDEX i = mesh->Index(0,0,z); // Get base linear address
for(x=0;x<xdim;x++) { // y==0
if(node_start<=i && i<node_stop) {
energy[i] *= 27./24.;
field[i] *= 27./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==1
if(node_start<=i && i<node_stop) {
energy[i] *= 18./24.;
field[i] *= 18./24.;
}
++i;
}
for(x=0;x<xdim;x++) { // y==2
if(node_start<=i && i<node_stop) {
energy[i] *= 27./24.;
field[i] *= 27./24.;
}
++i;
}
}
}
// Quadratic fit requires 3 points, so no higher order method
// available if ydim<3.
// z-axis. Note special case handling for short lengths.
if(zdim>=6) {
// Bottom face, z==0
OC_INDEX i = node_start;
while(i<xydim && i<node_stop) { // z==0
energy[i] *= 26./24.;
field[i] *= 26./24.;
++i;
} // NB: At end of loop, i wraps around to next xy-plane.
while(i<2*xydim && i<node_stop) { // z==1
energy[i] *= 21./24.;
field[i] *= 21./24.;
++i;
}
while(i<3*xydim && i<node_stop) { // z==2
energy[i] *= 25./24.;
field[i] *= 25./24.;
++i;
}
// Top face, z==zdim-1
OC_INDEX itop = mesh->Index(0,0,zdim-3);
i = (node_start<itop ? itop : node_start);
while(i<itop+xydim && i<node_stop) { // z==zdim-3
energy[i] *= 25./24.;
field[i] *= 25./24.;
++i;
}
while(i<itop+2*xydim && i<node_stop) { // z==zdim-2
energy[i] *= 21./24.;
field[i] *= 21./24.;
++i;
}
while(i<node_stop) { // z==zdim-1
energy[i] *= 26./24.;
field[i] *= 26./24.;
++i;
}
} else if(zdim==5) {
OC_INDEX i = node_start;
while(i<xydim && i<node_stop) { // z==0; bottom face
energy[i] *= 26./24.;
field[i] *= 26./24.;
++i;
}
while(i<2*xydim && i<node_stop) { // z==1
energy[i] *= 21./24.;
field[i] *= 21./24.;
++i;
}
while(i<3*xydim && i<node_stop) { // z==2
energy[i] *= 26./24.;
field[i] *= 26./24.;
++i;
}
while(i<4*xydim && i<node_stop) { // z==3
energy[i] *= 21./24.;
field[i] *= 21./24.;
++i;
}
while(i<node_stop) { // z==4; top face
energy[i] *= 26./24.;
field[i] *= 26./24.;
++i;
}
} else if(zdim==4) {
OC_INDEX i = node_start;
while(i<xydim && i<node_stop) { // z==0; bottom face
energy[i] *= 26./24.;
field[i] *= 26./24.;
++i;
}
while(i<2*xydim && i<node_stop) { // z==1
energy[i] *= 22./24.;
field[i] *= 22./24.;
++i;
}
while(i<3*xydim && i<node_stop) { // z==2
energy[i] *= 22./24.;
field[i] *= 22./24.;
++i;
}
while(i<node_stop) { // z==3; top face
energy[i] *= 26./24.;
field[i] *= 26./24.;
++i;
}
} else if(zdim==3) {
OC_INDEX i = node_start;
while(i<xydim && i<node_stop) { // z==0; bottom face
energy[i] *= 27./24.;
field[i] *= 27./24.;
++i;
}
while(i<2*xydim && i<node_stop) { // z==1
energy[i] *= 18./24.;
field[i] *= 18./24.;
++i;
}
while(i<node_stop) { // z==2; top face
energy[i] *= 27./24.;
field[i] *= 27./24.;
++i;
}
}
// Quadratic fit requires 3 points, so no higher order method
// available if zdim<3.
// Copy from scratch to real buffers.
Nb_Xpfloat energy_sum = 0.0;
if(ocedt.energy_accum) {
for(OC_INDEX i=node_start;i<node_stop;i++) {
(*ocedt.energy_accum)[i] += energy[i];
energy_sum += energy[i];
}
} else {
for(OC_INDEX i=node_start;i<node_stop;i++) {
energy_sum += energy[i];
}
}
ocedtaux.energy_total_accum += energy_sum.GetValue() * mesh->Volume(0); // All cells
/// have same volume in an Oxs_RectangularMesh.
const Oxs_MeshValue<ThreeVector>& spin = state.spin;
if(ocedt.mxH_accum && ocedt.H_accum) {
for(OC_INDEX i=node_start; i<node_stop; ++i) {
(*ocedt.H_accum)[i] += field[i];
ThreeVector temp = spin[i];
temp ^= field[i];
(*ocedt.mxH_accum)[i] += temp;
}
} else if(ocedt.mxH_accum) {
for(OC_INDEX i=node_start; i<node_stop; ++i) {
ThreeVector temp = spin[i];
temp ^= field[i];
(*ocedt.mxH_accum)[i] += temp;
}
} else if(ocedt.H_accum) {
for(OC_INDEX i=node_start; i<node_stop; ++i) {
(*ocedt.H_accum)[i] += field[i];
}
}
if(ocedt.mxH) {
for(OC_INDEX i=node_start; i<node_stop; ++i) {
ThreeVector temp = spin[i];
temp ^= field[i];
(*ocedt.mxH)[i] = temp;
}
}
}
| 32.112763 | 86 | 0.544627 | [
"mesh",
"object",
"vector"
] |
094e37c4266a65da8af3b05d883865ec78c56878 | 4,624 | h++ | C++ | core/slot.h++ | 1094387012/SKUI | c85dd7fb9d30ff15d5d6de184670cb47e46df6de | [
"MIT"
] | 309 | 2017-05-06T02:15:43.000Z | 2022-03-23T08:27:05.000Z | core/slot.h++ | qdtroy/skui | 201707d06bd29c9ec4b05350b25b777493d5362e | [
"MIT"
] | 20 | 2018-05-11T20:56:45.000Z | 2022-03-11T06:10:12.000Z | core/slot.h++ | qdtroy/skui | 201707d06bd29c9ec4b05350b25b777493d5362e | [
"MIT"
] | 48 | 2017-06-27T06:04:15.000Z | 2022-03-01T12:56:32.000Z | /**
* The MIT License (MIT)
*
* Copyright © 2017-2020 Ruben Van Boxem
*
* 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.
**/
/*
* Slot
* Wrapper for functions connected to slots.
* This provides a uniform interface across all callables for e.g. signals.
*/
#ifndef SKUI_CORE_SLOT_H
#define SKUI_CORE_SLOT_H
#include <functional>
#include <utility>
#include "core/traits/arity.h++"
namespace skui::core::implementation
{
// interface
template<typename ReturnType, typename... ArgTypes>
class slot
{
public:
virtual ~slot() = default;
virtual ReturnType operator()(const void* object, ArgTypes...) const = 0;
protected:
slot() = default;
};
// Implementation for function pointers and functors (including lambdas)
template<typename Callable, typename ReturnType = void, typename... ArgTypes>
class callable_slot : public slot<ReturnType, ArgTypes...>
{
public:
callable_slot(Callable function_pointer_or_lambda)
: callable{function_pointer_or_lambda}
{}
ReturnType operator()(const void*, ArgTypes... args) const override
{
return call(std::make_index_sequence<arity_v<Callable>>{},
std::forward<ArgTypes>(args)...);
}
private:
template<std::size_t... Indices>
ReturnType call(const std::index_sequence<Indices...>&,
ArgTypes&&... args) const
{
((void)args, ...);
return callable(std::get<Indices>(std::make_tuple(args...))...);
}
Callable callable;
};
// Implementation for member functions
template<typename Class, typename MemberFunctionPointer, typename ReturnType, typename... ArgTypes>
class member_function_slot : public slot<ReturnType, ArgTypes...>
{
public:
member_function_slot(MemberFunctionPointer member_function)
: member_function_ptr{member_function}
{}
ReturnType operator()(const void* object, ArgTypes... args) const override
{
return call(std::make_index_sequence<arity_v<MemberFunctionPointer>>{},
const_cast<Class*>(static_cast<const Class*>(object)),
std::forward<ArgTypes>(args)...);
}
private:
template<std::size_t ... Indices>
ReturnType call(const std::index_sequence<Indices...>&,
Class* object,
ArgTypes&&... args) const
{
((void)args, ...);
return (object->*member_function_ptr)(std::get<Indices>(std::make_tuple(args...))...);
}
MemberFunctionPointer member_function_ptr;
};
// Implementation for const member functions
template<typename Class, typename ConstMemberFunctionPointer, typename ReturnType, typename... ArgTypes>
class const_member_function_slot : public slot<ReturnType, ArgTypes...>
{
public:
const_member_function_slot(ConstMemberFunctionPointer const_member_function)
: const_member_function_ptr{const_member_function}
{}
ReturnType operator()(const void* object, ArgTypes... args) const override
{
return call(std::make_index_sequence<arity_v<ConstMemberFunctionPointer>>{},
static_cast<const Class*>(object),
std::forward<ArgTypes>(args)...);
}
private:
template<std::size_t... Indices>
ReturnType call(const std::index_sequence<Indices...>&,
const Class* object,
ArgTypes&&... args) const
{
((void)args, ...);
return (object->*const_member_function_ptr)(std::get<Indices>(std::make_tuple(args...))...);
}
ConstMemberFunctionPointer const_member_function_ptr;
};
}
#endif
| 32.111111 | 106 | 0.685554 | [
"object"
] |
094e37cc68ce9e6013b8ee56ce873a851b163c8b | 4,142 | cpp | C++ | zbus/Consumer.cpp | rushmore/zbus-cpp | 61a1c020b1ce03926c4fef0af3fd7e6246ecfe94 | [
"MIT"
] | 2 | 2017-06-28T07:33:25.000Z | 2021-01-07T12:32:26.000Z | zbus/Consumer.cpp | rushmore/zbus-cpp | 61a1c020b1ce03926c4fef0af3fd7e6246ecfe94 | [
"MIT"
] | null | null | null | zbus/Consumer.cpp | rushmore/zbus-cpp | 61a1c020b1ce03926c4fef0af3fd7e6246ecfe94 | [
"MIT"
] | null | null | null | #include "Consumer.h"
namespace zbus {
ConsumeThread::ConsumeThread(MqClientPool* pool, std::function<void(Message*, MqClient*)> messageHander,
int connectionCount, int timeout) :
pool(pool), messageHander(messageHander),
connectionCount(connectionCount),
consumeTimeout(timeout) {
}
ConsumeThread::~ConsumeThread() {
this->close();
}
void ConsumeThread::start() {
if (clientThreads.size() > 0) return;
if (this->messageHander == NULL) {
throw std::exception("Missing message handler");
}
for (int i = 0; i < this->connectionCount; i++) {
MqClient* client = pool->makeClient();
clients.push_back(client);
std::thread* t = new std::thread(&ConsumeThread::run, this, client);
clientThreads.push_back(t);
}
}
void ConsumeThread::join() {
for (std::thread* t : clientThreads) {
t->join();
}
}
void ConsumeThread::close() {
running = false;
for (MqClient* client : clients) {
client->close();
}
for (std::thread* t : clientThreads) {
t->join();
delete t;
}
clientThreads.clear();
for (MqClient* client : clients) {
delete client;
}
clients.clear();
}
Message* ConsumeThread::take(MqClient* client) {
Message* res = client->consume(topic, consumeGroup.groupName, consumeWindow, consumeTimeout);
if (res->status == "404") {
client->declareTopic(topic, topicMask);
client->declareGroup(topic, consumeGroup);
delete res;
return take(client);
}
if (res->status == "200") {
res->setId(res->getOriginId());
res->removeHeader(PROTOCOL_ORIGIN_ID);
if (res->getOriginUrl() != "") {
res->url = res->getOriginUrl();
res->removeHeader(PROTOCOL_ORIGIN_URL);
res->status = "";
}
}
return res;
}
void ConsumeThread::run(MqClient* client) {
while (running) {
try {
Message* msg = take(client);
messageHander(msg, client);
}
catch (MqException& e) {
if (e.code == ERR_NET_RECV_FAILED) { //timeout?
continue;
}
client->close();
logger->error("%d, %s", e.code, e.message.c_str());
break;
}
}
}
Consumer::Consumer(Broker* broker, std::string topic) : MqAdmin(broker) {
consumeSelector = [](BrokerRouteTable& routeTable, Message& msg) {
std::vector<ServerAddress> res;
for (auto& kv : routeTable.getServerTable()) {
res.push_back(kv.second.serverAddress);
}
return res;
};
this->topic = topic;
}
Consumer::~Consumer() {
this->close();
}
void Consumer::close() {
for (auto& kv : consumeThreadTable) {
ConsumeThread* ct = kv.second;
delete ct;
}
}
void Consumer::start() {
broker->onServerJoin = [this](MqClientPool* pool) {
this->startConsumeThread(pool);
};
broker->onServerLeave = [this](ServerAddress serverAddress) {
this->stopConsumeThread(serverAddress);
};
Message msgCtrl;
msgCtrl.setTopic(this->topic);
msgCtrl.setToken(this->token);
consumeGroup.writeTo(msgCtrl);
std::vector<MqClientPool*> pools = broker->select(this->consumeSelector, msgCtrl);
for (MqClientPool* pool : pools) {
this->startConsumeThread(pool);
}
}
void Consumer::join() {
for (auto& kv : consumeThreadTable) {
kv.second->join();
}
}
void Consumer::startConsumeThread(MqClientPool* pool) {
std::unique_lock<std::mutex> lock(threadMutex);
ServerAddress serverAddress = pool->getServerAddress();
if (consumeThreadTable.count(serverAddress) > 0) {
return;
}
ConsumeThread* ct = new ConsumeThread(pool);
ct->connectionCount = this->connectionCount;
ct->consumeGroup = this->consumeGroup;
ct->consumeTimeout = this->consumeTimeout;
ct->consumeWindow = this->consumeWindow;
ct->messageHander = this->messageHander;
ct->token = this->token;
ct->topic = this->topic;
ct->topicMask = this->topicMask;
consumeThreadTable[serverAddress] = ct;
ct->start();
}
void Consumer::stopConsumeThread(ServerAddress serverAddress) {
std::unique_lock<std::mutex> lock(threadMutex);
if (consumeThreadTable.count(serverAddress) <= 0) {
return;
}
ConsumeThread* ct = consumeThreadTable[serverAddress];
delete ct;
consumeThreadTable.erase(serverAddress);
}
}//namespace | 24.951807 | 106 | 0.668035 | [
"vector"
] |
0954271f4ee9e24f2513203ffc49d21711efd10b | 3,170 | hpp | C++ | pynger/fingerprint/angafris_segmentation/Headers/ImageMaskSimplify.hpp | DottD/pynger | 9a24b43a2170234e5059a54ed20329e036260b0a | [
"MIT"
] | 1 | 2021-11-10T16:37:28.000Z | 2021-11-10T16:37:28.000Z | pynger/fingerprint/angafris_segmentation/Headers/ImageMaskSimplify.hpp | DottD/pynger | 9a24b43a2170234e5059a54ed20329e036260b0a | [
"MIT"
] | null | null | null | pynger/fingerprint/angafris_segmentation/Headers/ImageMaskSimplify.hpp | DottD/pynger | 9a24b43a2170234e5059a54ed20329e036260b0a | [
"MIT"
] | null | null | null | /*
In questo header file vengono definite alcune operazioni sulle maschere
*/
#ifndef ImageMaskSimplify_hpp
#define ImageMaskSimplify_hpp
#include <opencv2/opencv.hpp>
#include <vector>
#include <map>
#include "myMathFunc.hpp"
namespace fm {
enum struct holesFilling {
THICKNESS, // max distance of an internal point to the perimeter of a component
AREA // area of a component
}; // never used ... to be implemented
/*
MaskSimplify(mask, maxCompNum, minCompThickness, maxHolesNum, minHolesThickness)
Questa funzione è un alias per
MaskComponentsReduce (mask, maxCompNum, minCompThickness);
MaskHolesFill (mask, maxHolesNum, minHolsThickness);
*/
void MaskSimplify(Mask__& mask,
const int& maxCompNum,
const int& minCompThickness,
const int& maxHolesNum,
const int& minHolesThickness);
/*
MaskComponentsReduce (mask, maxCompNum, minThickness)
Questa funzione riduce il numero di componenti connesse della maschera data in input;
le componenti con massima distanza dal perimetro troppo piccola vengono eliminate a priori,
quindi le rimanenti vengono ordinate in base alla loro area e si scartano quelle
più piccole.
Argomenti:
- mask la maschera su cui si vuole operare
- maxCompNum numero massimo di componenti che si vogliono tenere (inserire un numero negativo per non forzare un numero massimo di componenti)
- minThickness spessore minimo che deve avere una componente
*/
void MaskComponentsReduce(Mask__& mask, // la maschera su cui si vuole operare
const int& maxCompNum, // maxCompNum numero massimo di componenti che si vogliono tenere
const int& minThickness); // spessore minimo che deve avere una componente
/*
MaskHolesFill (mask, maxCompNum, minThickness)
Questa funzione elimina i buchi nella maschera passata in input: vengono preservati
solamente i maxCompNum buchi con maggiore distanza dal baricentro e
che hanno una massima distanza dal perimetro sufficiente.
Argomenti:
- mask la maschera su cui si vuole operare
- maxCompNum numero massimo di componenti che si vogliono tenere (inserire un numero negativo per non forzare un numero massimo di buchi)
- minThickness spessore minimo che deve avere una componente
*/
void MaskHolesFill(Mask__& mask, // la maschera su cui si vuole operare
const int& maxCompNum, // maxCompNum numero massimo di componenti che si vogliono tenere
const int& maxPerimeterDistance); // minThickness spessore minimo che deve avere una componente
void MaskHolesFillArea(cv::InputOutputArray& mask, // la maschera su cui si vuole operare
const int& maxCompNum, // maxCompNum numero massimo di componenti che si vogliono tenere
const int& maxArea); // maxArea massima area di un buco per essere colmato
}
#endif /* ImageMaskSimplify_hpp */
| 43.424658 | 147 | 0.680757 | [
"vector"
] |
09543e9e31a4a835f664748495e49ae27bda3ab6 | 15,509 | hxx | C++ | Modules/Feature/Textures/include/otbSFSTexturesImageFilter.hxx | heralex/OTB | c52b504b64dc89c8fe9cac8af39b8067ca2c3a57 | [
"Apache-2.0"
] | 317 | 2015-01-19T08:40:58.000Z | 2022-03-17T11:55:48.000Z | Modules/Feature/Textures/include/otbSFSTexturesImageFilter.hxx | guandd/OTB | 707ce4c6bb4c7186e3b102b2b00493a5050872cb | [
"Apache-2.0"
] | 18 | 2015-07-29T14:13:45.000Z | 2021-03-29T12:36:24.000Z | Modules/Feature/Textures/include/otbSFSTexturesImageFilter.hxx | guandd/OTB | 707ce4c6bb4c7186e3b102b2b00493a5050872cb | [
"Apache-2.0"
] | 132 | 2015-02-21T23:57:25.000Z | 2022-03-25T16:03:16.000Z | /*
* Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* 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 otbSFSTexturesImageFilter_hxx
#define otbSFSTexturesImageFilter_hxx
#include "otbSFSTexturesImageFilter.h"
#include "itkProgressReporter.h"
#include "itkImageRegionIterator.h"
#include "itkNeighborhoodAlgorithm.h"
#include "otbMath.h"
namespace otb
{
template <class TInputImage, class TOutputImage>
SFSTexturesImageFilter<TInputImage, TOutputImage>::SFSTexturesImageFilter()
{
this->SetNumberOfRequiredInputs(1);
this->SetNumberOfRequiredInputs(1);
this->SetNumberOfRequiredOutputs(6);
this->SetNumberOfRequiredOutputs(1);
this->SetNthOutput(0, OutputImageType::New());
this->SetNthOutput(1, OutputImageType::New());
this->SetNthOutput(2, OutputImageType::New());
this->SetNthOutput(3, OutputImageType::New());
this->SetNthOutput(4, OutputImageType::New());
this->SetNthOutput(5, OutputImageType::New());
m_Radius = this->GetSpatialThreshold();
m_FunctorList.clear();
}
/************************************************************
*
* OUTPUTS MANIPULATION
*
************************************************************/
// Return output length image
template <class TInputImage, class TOutputImage>
const typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetLengthOutput() const
{
if (this->GetNumberOfOutputs() < 1)
{
return 0;
}
if (this->GetTexturesStatus()[0] == false)
{
itkExceptionMacro(<< "Impossible to create length image : texture not selected");
}
return static_cast<const OutputImageType*>(this->itk::ProcessObject::GetOutput(0));
}
template <class TInputImage, class TOutputImage>
typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetLengthOutput()
{
if (this->GetNumberOfOutputs() < 1)
{
return nullptr;
}
if (this->GetTexturesStatus()[0] == false)
{
itkExceptionMacro(<< "Impossible to create length image : texture not selected");
}
return static_cast<OutputImageType*>(this->itk::ProcessObject::GetOutput(0));
}
// Return output width image
template <class TInputImage, class TOutputImage>
const typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetWidthOutput() const
{
if (this->GetNumberOfOutputs() < 2)
{
return 0;
}
if (this->GetTexturesStatus()[1] == false)
{
itkExceptionMacro(<< "Impossible to create width image : texture not selected");
}
return static_cast<const OutputImageType*>(this->itk::ProcessObject::GetOutput(1));
}
template <class TInputImage, class TOutputImage>
typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetWidthOutput()
{
if (this->GetNumberOfOutputs() < 2)
{
return nullptr;
}
if (this->GetTexturesStatus()[1] == false)
{
itkExceptionMacro(<< "Impossible to create width image : texture not selected");
}
return static_cast<OutputImageType*>(this->itk::ProcessObject::GetOutput(1));
}
// Return output PSI image
template <class TInputImage, class TOutputImage>
const typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetPSIOutput() const
{
if (this->GetNumberOfOutputs() < 3)
{
return 0;
}
if (this->GetTexturesStatus()[2] == false)
{
itkExceptionMacro(<< "Impossible to create PSI image : texture not selected");
}
return static_cast<const OutputImageType*>(this->itk::ProcessObject::GetOutput(2));
}
template <class TInputImage, class TOutputImage>
typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetPSIOutput()
{
if (this->GetNumberOfOutputs() < 3)
{
return nullptr;
}
if (this->GetTexturesStatus()[2] == false)
{
itkExceptionMacro(<< "Impossible to create PSI image : texture not selected");
}
return static_cast<OutputImageType*>(this->itk::ProcessObject::GetOutput(2));
}
// Return output WMean image
template <class TInputImage, class TOutputImage>
const typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetWMeanOutput() const
{
if (this->GetNumberOfOutputs() < 4)
{
return 0;
}
if (this->GetTexturesStatus()[3] == false)
{
itkExceptionMacro(<< "Impossible to create W-Mean image : texture not selected");
}
return static_cast<const OutputImageType*>(this->itk::ProcessObject::GetOutput(3));
}
template <class TInputImage, class TOutputImage>
typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetWMeanOutput()
{
if (this->GetNumberOfOutputs() < 4)
{
return nullptr;
}
if (this->GetTexturesStatus()[3] == false)
{
itkExceptionMacro(<< "Impossible to create W-Mean image : texture not selected");
}
return static_cast<OutputImageType*>(this->itk::ProcessObject::GetOutput(3));
}
// Return output ratio image
template <class TInputImage, class TOutputImage>
const typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetRatioOutput() const
{
if (this->GetNumberOfOutputs() < 5)
{
return 0;
}
if (this->GetTexturesStatus()[4] == false)
{
itkExceptionMacro(<< "Impossible to create Ratio image : texture not selected");
}
return static_cast<const OutputImageType*>(this->itk::ProcessObject::GetOutput(4));
}
template <class TInputImage, class TOutputImage>
typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetRatioOutput()
{
if (this->GetNumberOfOutputs() < 5)
{
return nullptr;
}
if (this->GetTexturesStatus()[4] == false)
{
itkExceptionMacro(<< "Impossible to create Ratio image : texture not selected");
}
return static_cast<OutputImageType*>(this->itk::ProcessObject::GetOutput(4));
}
// Return output SD image
template <class TInputImage, class TOutputImage>
const typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetSDOutput() const
{
if (this->GetNumberOfOutputs() < 6)
{
return 0;
}
if (this->GetTexturesStatus()[5] == false)
{
itkExceptionMacro(<< "Impossible to create SD image : texture not selected");
}
return static_cast<const OutputImageType*>(this->itk::ProcessObject::GetOutput(5));
}
template <class TInputImage, class TOutputImage>
typename SFSTexturesImageFilter<TInputImage, TOutputImage>::OutputImageType* SFSTexturesImageFilter<TInputImage, TOutputImage>::GetSDOutput()
{
if (this->GetNumberOfOutputs() < 6)
{
return nullptr;
}
if (this->GetTexturesStatus()[5] == false)
{
itkExceptionMacro(<< "Impossible to create SD image : texture not selected");
}
return static_cast<OutputImageType*>(this->itk::ProcessObject::GetOutput(5));
}
template <class TInputImage, class TOutputImage>
void SFSTexturesImageFilter<TInputImage, TOutputImage>::BeforeThreadedGenerateData()
{
Superclass::BeforeThreadedGenerateData();
if (this->GetSpatialThreshold() < this->GetRatioMaxConsiderationNumber())
{
itkExceptionMacro(<< "Spatial Threshold (" << this->GetSpatialThreshold() << ") is lower than Ration Max Consideration Number ("
<< this->GetRatioMaxConsiderationNumber() << ") what is not allowed.");
}
for (unsigned int i = 0; i < this->GetNumberOfThreads(); ++i)
{
m_FunctorList.push_back(m_Functor);
}
this->InitFeatureStatus(true);
}
template <class TInputImage, class TOutputImage>
void SFSTexturesImageFilter<TInputImage, TOutputImage>::GenerateInputRequestedRegion()
{
// call the superclass' implementation of this method
Superclass::GenerateInputRequestedRegion();
// get pointers to the input and output
typename Superclass::InputImagePointer inputPtr = const_cast<TInputImage*>(this->GetInput());
typename Superclass::OutputImagePointer outputPtr1 = this->GetOutput(0); // this->GetLengthOutput();
typename Superclass::OutputImagePointer outputPtr2 = this->GetOutput(1); // this->GetWidthOutput();
typename Superclass::OutputImagePointer outputPtr3 = this->GetOutput(2); // this->GetPSIOutput();
typename Superclass::OutputImagePointer outputPtr4 = this->GetOutput(3); // this->GetWMeanOutput();
typename Superclass::OutputImagePointer outputPtr5 = this->GetOutput(4); // this->GetRatioOutput();
typename Superclass::OutputImagePointer outputPtr6 = this->GetOutput(5); // this->GetSDOutput();
if (!inputPtr || !outputPtr1 || !outputPtr2 || !outputPtr3 || !outputPtr4 || !outputPtr5 || !outputPtr6)
{
return;
}
// get a copy of the input requested region (should equal the output
// requested region)
typename TInputImage::RegionType inputRequestedRegion;
inputRequestedRegion = inputPtr->GetRequestedRegion();
// pad the input requested region by the operator radius
InputImageSizeType rad;
rad[0] = m_Radius;
rad[1] = m_Radius;
inputRequestedRegion.PadByRadius(rad);
// crop the input requested region at the input's largest possible region
if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
{
inputPtr->SetRequestedRegion(inputRequestedRegion);
return;
}
else
{
// Couldn't crop the region (requested region is outside the largest
// possible region). Throw an exception.
// store what we tried to request (prior to trying to crop)
inputPtr->SetRequestedRegion(inputRequestedRegion);
// build an exception
itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
std::ostringstream msg;
msg << this->GetNameOfClass() << "::GenerateInputRequestedRegion()";
e.SetLocation(msg.str());
e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
e.SetDataObject(inputPtr);
throw e;
}
}
template <class TInputImage, class TOutputImage>
void SFSTexturesImageFilter<TInputImage, TOutputImage>::GenerateOutputInformation()
{
Superclass::GenerateOutputInformation();
// this->GetOutput()->SetNumberOfComponentsPerPixel(6);
}
template <class TInputImage, class TOutputImage>
void SFSTexturesImageFilter<TInputImage, TOutputImage>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId)
{
itk::ZeroFluxNeumannBoundaryCondition<TInputImage> nbc;
// We use dynamic_cast since inputs are stored as DataObjects. The
// ImageToImageFilter::GetInput(int) always returns a pointer to a
// TInputImage so it cannot be used for the second input.
InputImagePointerType inputPtr = dynamic_cast<const TInputImage*>(ProcessObjectType::GetInput(0));
OutputImagePointerType outputPtr1 = this->GetOutput(0);
OutputImagePointerType outputPtr2 = this->GetOutput(1);
OutputImagePointerType outputPtr3 = this->GetOutput(2);
OutputImagePointerType outputPtr4 = this->GetOutput(3);
OutputImagePointerType outputPtr5 = this->GetOutput(4);
OutputImagePointerType outputPtr6 = this->GetOutput(5);
RadiusType r;
r.Fill(this->GetRadius());
NeighborhoodIteratorType neighInputIt;
itk::ImageRegionIterator<TOutputImage> outputIt1, outputIt2, outputIt3, outputIt4, outputIt5, outputIt6;
FunctorOutputType outputFunctor;
// Find the data-set boundary "faces"
typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType faceList;
typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage> bC;
faceList = bC(inputPtr, outputRegionForThread, r);
typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType::iterator fit;
// support progress methods/callbacks
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
// Process each of the boundary faces. These are N-d regions which border
// the edge of the buffer.
std::vector<bool> textStatus = this->GetTexturesStatus();
for (fit = faceList.begin(); fit != faceList.end(); ++fit)
{
neighInputIt = itk::ConstNeighborhoodIterator<TInputImage>(r, inputPtr, *fit);
outputIt1 = itk::ImageRegionIterator<TOutputImage>(outputPtr1, *fit);
outputIt2 = itk::ImageRegionIterator<TOutputImage>(outputPtr2, *fit);
outputIt3 = itk::ImageRegionIterator<TOutputImage>(outputPtr3, *fit);
outputIt4 = itk::ImageRegionIterator<TOutputImage>(outputPtr4, *fit);
outputIt5 = itk::ImageRegionIterator<TOutputImage>(outputPtr5, *fit);
outputIt6 = itk::ImageRegionIterator<TOutputImage>(outputPtr6, *fit);
std::vector<itk::ImageRegionIterator<TOutputImage>*> outItList;
outItList.push_back(&outputIt1);
outItList.push_back(&outputIt2);
outItList.push_back(&outputIt3);
outItList.push_back(&outputIt4);
outItList.push_back(&outputIt5);
outItList.push_back(&outputIt6);
neighInputIt.OverrideBoundaryCondition(&nbc);
neighInputIt.GoToBegin();
for (unsigned int i = 0; i < outItList.size(); ++i)
{
(*outItList[i]).GoToBegin();
}
while (!outputIt1.IsAtEnd())
{
outputFunctor = m_FunctorList[threadId](neighInputIt);
for (unsigned int i = 0; i < outItList.size(); ++i)
{
if (textStatus[i] == true)
(*outItList[i]).Set(outputFunctor[i]);
}
++neighInputIt;
for (unsigned int i = 0; i < outItList.size(); ++i)
{
++(*outItList[i]);
}
progress.CompletedPixel();
}
}
}
template <class TInputImage, class TOutputImage>
void SFSTexturesImageFilter<TInputImage, TOutputImage>::InitFeatureStatus(bool status)
{
for (FeatureType id = LENGTH; id <= SD; id = static_cast<FeatureType>(id + 1))
{
this->SetFeatureStatus(static_cast<FeatureType>(id), status);
}
}
/**
* Standard "PrintSelf" method
*/
template <class TInputImage, class TOutputImage>
void SFSTexturesImageFilter<TInputImage, TOutputImage>::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
// os << indent << "Spatial Threshold : " << this->GetSpatialThreshold() << std::endl;
// os << indent << "Spectral Threshold : " << this->GetSpectralThreshold() << std::endl;
// os << indent << "Ratio Max Consideration Number: " << this->GetRatioMaxConsiderationNumber() << std::endl;
// os << indent << "Alpha : " << this->GetAlpha() << std::endl;
// os << indent << "Number Of Directions : " << this->GetNumberOfDirections() << std::endl;
}
} // end namespace otb
#endif
| 37.191847 | 157 | 0.725966 | [
"vector"
] |
095a893f1fe8c3f2950b9f4d69323ed9c8e80580 | 5,789 | cpp | C++ | test/Mesh/Test_PolyMesh.cpp | carlostapiarq/TopoLite | d6eb9125518a88ea546917df5217978f34661b2c | [
"MIT"
] | 17 | 2020-06-10T08:28:32.000Z | 2021-12-07T02:55:35.000Z | test/Mesh/Test_PolyMesh.cpp | carlostapiarq/TopoLite | d6eb9125518a88ea546917df5217978f34661b2c | [
"MIT"
] | 4 | 2020-06-08T12:21:49.000Z | 2020-06-10T07:56:42.000Z | test/Mesh/Test_PolyMesh.cpp | carlostapiarq/TopoLite | d6eb9125518a88ea546917df5217978f34661b2c | [
"MIT"
] | 3 | 2020-06-22T10:07:31.000Z | 2021-10-04T06:02:33.000Z | //
// Created by ziqwang on 2020-02-20.
//
#include <catch2/catch.hpp>
#include "Mesh/PolyMesh.h"
#if defined(GCC_VERSION_LESS_8)
#include <experimental/filesystem>
using namespace std::experimental::filesystem;
#else
#include <filesystem>
using namespace std::filesystem;
#endif
TEST_CASE("PolyMesh - Four Quad with index as input") {
// Setup
shared_ptr<InputVarList> varList = make_shared<InputVarList>();
InitVar(varList.get());
PolyMesh<double> polyMesh(varList);
vector<shared_ptr<_Polygon<double>>> polyLists;
int dXY[4][2] = {{0, 0},
{1, 0},
{1, 1},
{0, 1}}; // 0---3---8
int verIDs[4][4] = {{0, 1, 2, 3}, // | 0 | 3 |
{1, 4, 5, 2}, // 1---2---7
{2, 5, 6, 7}, // | 1 | 2 |
{3, 2, 7, 8}}; // 4---5---6
for (int id = 0; id < 4; id++) {
shared_ptr<_Polygon<double>> poly = make_shared<_Polygon<double>>(_Polygon<double>());
poly->push_back(Vector3d(0 + dXY[id][0], 0 + dXY[id][1], 0));
poly->push_back(Vector3d(1 + dXY[id][0], 0 + dXY[id][1], 0));
poly->push_back(Vector3d(1 + dXY[id][0], 1 + dXY[id][1], 0));
poly->push_back(Vector3d(0 + dXY[id][0], 1 + dXY[id][1], 0));
poly->vers[0]->verID = verIDs[id][0];
poly->vers[1]->verID = verIDs[id][1];
poly->vers[2]->verID = verIDs[id][2];
poly->vers[3]->verID = verIDs[id][3];
polyLists.push_back(poly);
}
polyMesh.setPolyLists(polyLists);
SECTION("Test computeVertexList") {
REQUIRE((polyMesh.vertexList[4]->pos - Vector3d(2, 0, 0)).norm() == Approx(0.0));
REQUIRE((polyMesh.vertexList[5]->pos - Vector3d(2, 1, 0)).norm() == Approx(0.0));
}
SECTION("Test Box PolyMesh bbox") {
Box<double> bbox = polyMesh.bbox();
REQUIRE((bbox.minPt - Vector3d(0, 0, 0)).norm() == Approx(0.0));
REQUIRE((bbox.maxPt - Vector3d(2, 2, 0)).norm() == Approx(0.0));
REQUIRE((bbox.cenPt - Vector3d(1, 1, 0)).norm() == Approx(0.0));
REQUIRE((bbox.size - Vector3d(2, 2, 0)).norm() == Approx(0.0));
}
SECTION("Test centroid") {
REQUIRE((polyMesh.centroid() - Vector3d(0, 0, 0)).norm() == Approx(0.0));
}
SECTION("Test volume") {
REQUIRE(polyMesh.volume() == Approx(0.0));
}
SECTION("Test lowest point") {
REQUIRE((polyMesh.lowestPt() - Vector3d(0.5, 0, 0)).norm() == Approx(0.0));
}
}
TEST_CASE("PolyMesh - Cube") {
shared_ptr<InputVarList> varList = make_shared<InputVarList>();
InitVar(varList.get());
PolyMesh<double> polyMesh(varList);
SECTION("Cube") {
vector<shared_ptr<_Polygon<double>>> polyLists;
int XYZ[8][3] = {{0, 0, 0},
{1, 0, 0},
{1, 1, 0},
{0, 1, 0},
{0, 0, 1},
{1, 0, 1},
{1, 1, 1},
{0, 1, 1}};
int face[6][4] = {{0, 3, 2, 1},
{6, 5, 1, 2},
{2, 3, 7, 6},
{0, 4, 7, 3},
{0, 1, 5, 4},
{4, 5, 6, 7}};
for (int id = 0; id < 6; id++) {
shared_ptr<_Polygon<double>> poly = make_shared<_Polygon<double>>(_Polygon<double>());
for (int jd = 0; jd < 4; jd++) {
Vector3d pt(XYZ[face[id][jd]][0], XYZ[face[id][jd]][1], XYZ[face[id][jd]][2]);
poly->push_back(pt);
}
polyLists.push_back(poly);
}
polyMesh.setPolyLists(polyLists);
REQUIRE((polyMesh.centroid() - Vector3d(0.5, 0.5, 0.5)).norm() == Approx(0.0).margin(1e-6));
REQUIRE(polyMesh.volume() == Approx(1).margin(1e-6));
//the reason for 8 is that the setPolyLists function will merge vertices with same position into one vertex
//a cube only has 8 vertices
REQUIRE(polyMesh.vertexList.size() == 8);
REQUIRE((polyMesh.centroid() - Vector3d(0.5, 0.5, 0.5)).norm() == Approx(0.0).margin(1e-6));
REQUIRE(polyMesh.volume() == Approx(1).margin(1e-6));
// Eigen Matrix Mesh
PolyMesh<double>::MatrixX V;
PolyMesh<double>::MatrixXi F;
Eigen::VectorXi C;
polyMesh.convertPosToEigenMesh(V, F, C);
REQUIRE(V.rows() == 8);
REQUIRE(F.rows() == 12);
}
SECTION("read polyhedron") {
path dataFolder(UNITTEST_DATAPATH);
path filepath = dataFolder / "Mesh/primitives/Icosphere.obj";
polyMesh.readOBJModel(filepath.c_str(), true);
REQUIRE(polyMesh.texturedModel == true);
polyMesh.rotateMesh(Vector3d(0, 0, 0), Vector3d(0, 0, 1), 10);
polyMesh.translateMesh(Vector3d(1, 1, 1));
polyMesh.scaleMesh(Vector3d(2, 2, 2));
path outputfile = dataFolder / "Mesh/primitives/Icosphere2.obj";
polyMesh.getTextureMesh()->writeOBJModel(outputfile.c_str(), false);
SECTION("Test copy and construct function") {
PolyMesh<double> newmesh = polyMesh;
REQUIRE(newmesh.vertexList[0]->pos == polyMesh.vertexList[0]->pos);
REQUIRE(newmesh.vertexList[0] != polyMesh.vertexList[0]);
REQUIRE(newmesh.textureList[0]->texCoord == polyMesh.textureList[0]->texCoord);
REQUIRE(newmesh.textureList[0] != polyMesh.textureList[0]);
REQUIRE(newmesh.polyList[0] != polyMesh.polyList[0]);
REQUIRE((newmesh.polyList[0]->normal() - polyMesh.polyList[0]->normal()).norm() == Approx(0.0));
}
}
} | 36.408805 | 115 | 0.516497 | [
"mesh",
"vector"
] |
095aae826c55e43dd8e1ad5a5ae9b95f8497a425 | 234 | hpp | C++ | Include/Aspen/Python/Discard.hpp | andrei-sa/aspen | 6644663fc19a83fba0603dc4bbd6dbe71cfd55aa | [
"Apache-2.0"
] | 2 | 2020-10-16T19:41:19.000Z | 2021-02-01T04:55:51.000Z | Include/Aspen/Python/Discard.hpp | andrei-sa/aspen | 6644663fc19a83fba0603dc4bbd6dbe71cfd55aa | [
"Apache-2.0"
] | 1 | 2020-04-24T18:17:39.000Z | 2020-04-24T18:37:01.000Z | Include/Aspen/Python/Discard.hpp | andrei-sa/aspen | 6644663fc19a83fba0603dc4bbd6dbe71cfd55aa | [
"Apache-2.0"
] | 2 | 2020-04-17T13:24:29.000Z | 2020-04-24T18:12:29.000Z | #ifndef ASPEN_PYTHON_DISCARD_HPP
#define ASPEN_PYTHON_DISCARD_HPP
#include <pybind11/pybind11.h>
namespace Aspen {
/** Exports a Discard evaluating to a Python object. */
void export_discard(pybind11::module& module);
}
#endif
| 19.5 | 57 | 0.773504 | [
"object"
] |
82361670cb853210583d65a3b12481bf33738a71 | 2,543 | hpp | C++ | scripts/deploy/cpp_infer/include/ocr_rec.hpp | Davids929/gluon-ocr | 5ac697cc030058cb9ae9f4b1f4e85f901d4d1c40 | [
"Apache-2.0"
] | 2 | 2021-07-27T23:55:39.000Z | 2022-02-02T15:20:34.000Z | scripts/deploy/cpp_infer/include/ocr_rec.hpp | Davids929/gluon-ocr | 5ac697cc030058cb9ae9f4b1f4e85f901d4d1c40 | [
"Apache-2.0"
] | null | null | null | scripts/deploy/cpp_infer/include/ocr_rec.hpp | Davids929/gluon-ocr | 5ac697cc030058cb9ae9f4b1f4e85f901d4d1c40 | [
"Apache-2.0"
] | 3 | 2021-05-07T03:56:13.000Z | 2021-07-27T23:55:27.000Z | #pragma once
#include <chrono>
#include <iomanip>
#include <iostream>
#include <ostream>
#include <vector>
#include <cstring>
#include <fstream>
#include <numeric>
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "mxnet-cpp/MxNetCpp.h"
#include "include/common.hpp"
#include "include/utils.hpp"
using namespace mxnet::cpp;
class CRNNRecognizer{
public:
CRNNRecognizer(const std::string &model_path,
const std::string ¶ms_path,
const std::string &dict_path,
const int &gpu_id,
const int max_side_len,
const int short_side,
const int num_buckets){
if (gpu_id >= 0)
this->ctx_ = Context::gpu(gpu_id);
this->max_side_len_ = max_side_len;
this->short_side_ = short_side;
this->step_ = max_side_len / num_buckets;
for (int i=0; i<num_buckets; i++){
int bucket = this->step_ * (i+1);
if (i == num_buckets-1)
this->bucket_keys_.push_back(max_side_len);
else
this->bucket_keys_.push_back(bucket);
}
this->voc_dict_ = ReadFile(dict_path);
this->voc_size_ = this->voc_dict_.size();
LoadCheckpoint(model_path, params_path, &net_, &args_map_, &auxs_map_, ctx_);
InitModel();
}
~CRNNRecognizer(){
for (auto bucket : this->exec_buckets_) {
Executor* executor = bucket.second;
delete executor;
}
}
public:
Symbol net_;
void InitModel();
std::string Run(cv::Mat &image);
void Run(cv::Mat &img, std::vector<std::vector<std::vector<int>>> &boxes,
std::vector<std::string> &texts);
private:
int max_side_len_;
int short_side_;
int voc_size_;
int step_;
Context ctx_ = Context::cpu();
std::map<std::string, NDArray> args_map_, auxs_map_;
std::vector<int> bucket_keys_;
std::map<int, Executor*> exec_buckets_;
std::vector<std::string> voc_dict_;
private:
cv::Mat GetRotateCropImage(const cv::Mat &image,
std::vector<std::vector<int>> box);
int GetBucketKey(int img_w);
std::string PostProcess(std::vector<float> &pred_id, int blank);
}; | 31.012195 | 89 | 0.547385 | [
"vector"
] |
82462a8627f5f4c5320531ca2c4743d3b2d94a29 | 5,638 | cpp | C++ | pizjuce/cpuram/src/CpuRam.cpp | nonameentername/pizmidi | a985e3d2bf8f02e3c0a87300dfbb82c35608bbd2 | [
"BSD-Source-Code"
] | null | null | null | pizjuce/cpuram/src/CpuRam.cpp | nonameentername/pizmidi | a985e3d2bf8f02e3c0a87300dfbb82c35608bbd2 | [
"BSD-Source-Code"
] | null | null | null | pizjuce/cpuram/src/CpuRam.cpp | nonameentername/pizmidi | a985e3d2bf8f02e3c0a87300dfbb82c35608bbd2 | [
"BSD-Source-Code"
] | 1 | 2021-01-26T12:25:01.000Z | 2021-01-26T12:25:01.000Z | //#include "CpuRam.h"
#include "CpuRamEditor.h"
//==============================================================================
/**
This function must be implemented to create the actual plugin object that
you want to use.
*/
PizAudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new CpuRam();
}
//==============================================================================
CpuRam::CpuRam()
{
if (!loadDefaultFxb())
resetToDefaultSettings();
}
void CpuRam::resetToDefaultSettings()
{
interval = 0.12f;
minimize = 0.0f;
showGraph = true;
lastUIWidth = 230;
lastUIHeight = 30;
bgcolor = Colour (0xffb8bcc0);
}
CpuRam::~CpuRam()
{
}
//==============================================================================
int CpuRam::getNumParameters()
{
return 3;
}
float CpuRam::getParameter (int index)
{
if (index == 0) return interval;
if (index == 1) return minimize;
if (index == 2) return showGraph ? 1.f : 0.f;
else return 0.0f;
}
void CpuRam::setParameter (int index, float newValue)
{
if (index == 0)
{
if (interval != newValue)
{
interval = newValue;
//sendChangeMessage (this);
}
}
else if (index == 1)
{
if (minimize != newValue)
{
minimize = newValue;
if (minimize>=0.5f) lastUIHeight=0;
else lastUIHeight=30;
sendChangeMessage ();
}
}
else if (index == 2)
{
if (showGraph != (newValue>=0.5f))
{
showGraph = newValue>=0.5f;
if (showGraph) lastUIHeight=30;
else lastUIHeight=15;
sendChangeMessage ();
}
}
}
const String CpuRam::getParameterName (int index)
{
if (index == 0) return "interval";
if (index == 1) return "minimize";
if (index == 2) return "show graph";
else return String::empty;
}
const String CpuRam::getParameterText (int index)
{
if (index == 0) {
return String((int)(interval*1700.0)+300)+String(" ms");
}
if (index == 1) {
if (minimize>=0.5f) return String("yes");
else return String("no");
}
if (index == 2) {
return showGraph ? String("yes") : String("no");
}
else return String::empty;
}
const String CpuRam::getInputChannelName (const int channelIndex) const
{
return String (channelIndex + 1);
}
const String CpuRam::getOutputChannelName (const int channelIndex) const
{
return String (channelIndex + 1);
}
bool CpuRam::isInputChannelStereoPair (int index) const
{
return true;
}
bool CpuRam::isOutputChannelStereoPair (int index) const
{
return true;
}
//==============================================================================
void CpuRam::prepareToPlay (double sampleRate, int samplesPerBlock)
{
// do your pre-playback setup stuff here..
}
void CpuRam::releaseResources()
{
// when playback stops, you can use this as an opportunity to free up any
// spare memory, etc.
}
void CpuRam::processBlock (AudioSampleBuffer& buffer,
MidiBuffer& midiMessages)
{
for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
{
buffer.clear (i, 0, buffer.getNumSamples());
}
midiMessages.clear();
}
//==============================================================================
AudioProcessorEditor* CpuRam::createEditor()
{
return new CpuRamEditor (this);
}
//==============================================================================
void CpuRam::getStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
{
// you can store your parameters as binary data if you want to or if you've got
// a load of binary to put in there, but if you're not doing anything too heavy,
// XML is a much cleaner way of doing it - here's an example of how to store your
// params as XML..
// create an outer XML element..
XmlElement xmlState ("MYPLUGINSETTINGS");
// add some attributes to it..
xmlState.setAttribute ("pluginVersion", 1);
xmlState.setAttribute ("intervalLevel", interval);
xmlState.setAttribute ("showGraph", showGraph);
xmlState.setAttribute ("uiWidth", lastUIWidth);
xmlState.setAttribute ("uiHeight", lastUIHeight);
xmlState.setAttribute ("bgcolor", (int)(bgcolor.getARGB()));
// you could also add as many child elements as you need to here..
// then use this helper function to stuff it into the binary blob and return it..
copyXmlToBinary (xmlState, destData);
}
void CpuRam::setStateInformation (const void* data, int sizeInBytes)
{
// use this helper function to get the XML from this binary blob..
XmlElement* const xmlState = getXmlFromBinary (data, sizeInBytes);
if (xmlState != 0)
{
// check that it's the right type of xml..
if (xmlState->hasTagName ("MYPLUGINSETTINGS"))
{
// ok, now pull out our parameters..
interval = (float) xmlState->getDoubleAttribute ("intervalLevel", interval);
showGraph = xmlState->getBoolAttribute ("showGraph", showGraph);
lastUIWidth = xmlState->getIntAttribute ("uiWidth", lastUIWidth);
lastUIHeight = xmlState->getIntAttribute ("uiHeight", lastUIHeight);
bgcolor = Colour(xmlState->getIntAttribute ("bgcolor", bgcolor.getARGB()));
sendChangeMessage ();
}
delete xmlState;
}
}
| 28.049751 | 89 | 0.555161 | [
"object"
] |
824a75c71c2955e08f2b878c1c77728a950c813c | 451 | hpp | C++ | Token.hpp | Sygmei/CrimsonLang | 2db500b9abbc44fe882303f33c5026e2f7eae212 | [
"MIT"
] | null | null | null | Token.hpp | Sygmei/CrimsonLang | 2db500b9abbc44fe882303f33c5026e2f7eae212 | [
"MIT"
] | null | null | null | Token.hpp | Sygmei/CrimsonLang | 2db500b9abbc44fe882303f33c5026e2f7eae212 | [
"MIT"
] | null | null | null | #pragma once
#include <string>
#include "TokenValue.hpp"
#include "TokenType.hpp"
class Token
{
private:
std::vector<Token> children;
TokenType type;
TokenValue value;
public:
Token(TokenType type);
TokenValue& getValue();
void setValue(TokenValue& value);
TokenType getType();
Token& addChild(Token& child);
std::vector<Token>& getChildren();
};
| 20.5 | 43 | 0.580931 | [
"vector"
] |
8252ba6ed82ba96735d87227f613d5db91bb5573 | 981 | cpp | C++ | virtual_node_miner/main.cpp | desert0616/GCGT | 1af8721362d9bbb84b9bda6be76bd9e1a041a12d | [
"MIT"
] | 4 | 2020-06-09T03:41:23.000Z | 2021-07-22T07:31:49.000Z | virtual_node_miner/main.cpp | desert0616/GCGT | 1af8721362d9bbb84b9bda6be76bd9e1a041a12d | [
"MIT"
] | null | null | null | virtual_node_miner/main.cpp | desert0616/GCGT | 1af8721362d9bbb84b9bda6be76bd9e1a041a12d | [
"MIT"
] | 1 | 2021-03-17T05:50:52.000Z | 2021-03-17T05:50:52.000Z | #include <iostream>
#include "virtual_node_miner.hpp"
#include <string>
#include <vector>
#include <cstdio>
#include <sys/resource.h>
int main(int argc,char *argv[]) {
if (argc != 3) {
printf("incorrect arguments.\n");
printf("<input_graph> <output_graph>\n");
abort();
}
std::string input_path(argv[1]);
std::string output_path(argv[2]);
const rlim_t kStackSize = 1 * 1024 * 1024 * 1024;
struct rlimit rl;
int result;
result = getrlimit(RLIMIT_STACK, &rl);
if (result == 0)
{
if (rl.rlim_cur < kStackSize)
{
rl.rlim_cur = kStackSize;
result = setrlimit(RLIMIT_STACK, &rl);
if (result != 0)
{
fprintf(stderr, "setrlimit returned result = %d\n", result);
}
}
}
virtual_node_miner vnminer;
vnminer.load_graph(input_path);
vnminer.compress(5);
vnminer.write_graph(output_path);
return 0;
} | 22.813953 | 76 | 0.572885 | [
"vector"
] |
825534d51638dcfd0baa50a634a02579a69870c6 | 4,922 | cpp | C++ | ge0/parser.cpp | kudlav/organicmaps | 390236365749e0525b9229684132c2888d11369d | [
"Apache-2.0"
] | 3,062 | 2021-04-09T16:51:55.000Z | 2022-03-31T21:02:51.000Z | ge0/parser.cpp | kudlav/organicmaps | 390236365749e0525b9229684132c2888d11369d | [
"Apache-2.0"
] | 1,396 | 2021-04-08T07:26:49.000Z | 2022-03-31T20:27:46.000Z | ge0/parser.cpp | kudlav/organicmaps | 390236365749e0525b9229684132c2888d11369d | [
"Apache-2.0"
] | 242 | 2021-04-10T17:10:46.000Z | 2022-03-31T13:41:07.000Z | #include "ge0/parser.hpp"
#include "ge0/url_generator.hpp"
#include "coding/url.hpp"
#include "geometry/mercator.hpp"
#include "base/assert.hpp"
#include "base/math.hpp"
#include "base/string_utils.hpp"
#include <algorithm>
#include <sstream>
using namespace std;
namespace ge0
{
Ge0Parser::Ge0Parser()
{
for (size_t i = 0; i < 256; ++i)
m_base64ReverseCharTable[i] = 255;
for (uint8_t i = 0; i < 64; ++i)
{
char c = Base64Char(i);
m_base64ReverseCharTable[static_cast<uint8_t>(c)] = i;
}
}
bool Ge0Parser::Parse(string const & url, Result & result)
{
// Original URL format:
//
// +------------------ 1 byte: zoom level
// |+-------+--------- 9 bytes: lat,lon
// || | +--+---- Variable number of bytes: point name
// || | | |
// om://ZCoordba64/Name
// Alternative format (differs only in the prefix):
// http://omaps.app/ZCoordba64/Name
for (string const & prefix : {"ge0://", "om://",
"http://omaps.app/", "https://omaps.app/",
"http://ge0.me/", "https://ge0.me/"})
{
if (strings::StartsWith(url, prefix))
return ParseAfterPrefix(url, prefix.size(), result);
}
return false;
}
bool Ge0Parser::ParseAfterPrefix(string const & url, size_t from, Result & result)
{
size_t const kEncodedZoomAndCoordinatesLength = 10;
if (url.size() < from + kEncodedZoomAndCoordinatesLength)
return false;
size_t const kMaxNameLength = 256;
size_t const posZoom = from;
size_t const posLatLon = posZoom + 1;
size_t const posName = from + kEncodedZoomAndCoordinatesLength + 1;
size_t const lengthLatLon = posName - posLatLon - 1;
uint8_t const zoomI = DecodeBase64Char(url[posZoom]);
if (zoomI >= 64)
return false;
result.m_zoomLevel = DecodeZoom(zoomI);
if (!DecodeLatLon(url.substr(posLatLon, lengthLatLon), result.m_lat, result.m_lon))
return false;
ASSERT(mercator::ValidLat(result.m_lat), (result.m_lat));
ASSERT(mercator::ValidLon(result.m_lon), (result.m_lon));
if (url.size() >= posName)
{
CHECK_GREATER(posName, 0, ());
if (url[posName - 1] != '/')
return false;
result.m_name = DecodeName(url.substr(posName, min(url.size() - posName, kMaxNameLength)));
}
return true;
}
uint8_t Ge0Parser::DecodeBase64Char(char const c)
{
return m_base64ReverseCharTable[static_cast<uint8_t>(c)];
}
double Ge0Parser::DecodeZoom(uint8_t const zoomByte)
{
// Coding zoom - int newZoom = ((oldZoom - 4) * 4)
return static_cast<double>(zoomByte) / 4 + 4;
}
bool Ge0Parser::DecodeLatLon(string const & s, double & lat, double & lon)
{
int latInt = 0;
int lonInt = 0;
if (!DecodeLatLonToInt(s, latInt, lonInt))
return false;
lat = DecodeLatFromInt(latInt, (1 << kMaxCoordBits) - 1);
lon = DecodeLonFromInt(lonInt, (1 << kMaxCoordBits) - 1);
return true;
}
bool Ge0Parser::DecodeLatLonToInt(string const & s, int & lat, int & lon)
{
int shift = kMaxCoordBits - 3;
for (size_t i = 0; i < s.size(); ++i, shift -= 3)
{
uint8_t const a = DecodeBase64Char(s[i]);
if (a >= 64)
return false;
int const lat1 = (((a >> 5) & 1) << 2 | ((a >> 3) & 1) << 1 | ((a >> 1) & 1));
int const lon1 = (((a >> 4) & 1) << 2 | ((a >> 2) & 1) << 1 | (a & 1));
lat |= lat1 << shift;
lon |= lon1 << shift;
}
double const middleOfSquare = 1 << (3 * (kMaxPointBytes - s.size()) - 1);
lat += middleOfSquare;
lon += middleOfSquare;
return true;
}
double Ge0Parser::DecodeLatFromInt(int const lat, int const maxValue)
{
return static_cast<double>(lat) / maxValue * 180 - 90;
}
double Ge0Parser::DecodeLonFromInt(int const lon, int const maxValue)
{
return static_cast<double>(lon) / (maxValue + 1.0) * 360.0 - 180;
}
string Ge0Parser::DecodeName(string name)
{
ValidateName(name);
name = url::UrlDecode(name);
SpacesToUnderscore(name);
return name;
}
void Ge0Parser::SpacesToUnderscore(string & name)
{
for (size_t i = 0; i < name.size(); ++i)
{
if (name[i] == ' ')
name[i] = '_';
else if (name[i] == '_')
name[i] = ' ';
}
}
void Ge0Parser::ValidateName(string & name)
{
if (name.empty())
return;
for (size_t i = 0; i + 2 < name.size(); ++i)
{
if (name[i] == '%' && (!IsHexChar(name[i + 1]) || !IsHexChar(name[i + 2])))
{
name.resize(i);
return;
}
}
if (name[name.size() - 1] == '%')
name.resize(name.size() - 1);
else if (name.size() > 1 && name[name.size() - 2] == '%')
name.resize(name.size() - 2);
}
bool Ge0Parser::IsHexChar(char const a)
{
return ((a >= '0' && a <= '9') || (a >= 'A' && a <= 'F') || (a >= 'a' && a <= 'f'));
}
string DebugPrint(Ge0Parser::Result const & r)
{
ostringstream oss;
oss << "ParseResult [";
oss << "zoom=" << r.m_zoomLevel << ", ";
oss << "lat=" << r.m_lat << ", ";
oss << "lon=" << r.m_lon << ", ";
oss << "name=" << r.m_name << "]";
return oss.str();
}
} // namespace ge0
| 25.112245 | 95 | 0.59935 | [
"geometry"
] |
825673108fc99e0c334b116aabb4f517b82616f3 | 11,523 | cpp | C++ | src/ctlinterfaces/LegacyImageListWrapper.cpp | TimoKunze/ShellBrowserControls | e1699dde8821a55f43274364410c3d6a3c867526 | [
"MIT"
] | 3 | 2020-02-03T12:58:10.000Z | 2021-03-30T04:55:04.000Z | src/ctlinterfaces/LegacyImageListWrapper.cpp | TimoKunze/ShellBrowserControls | e1699dde8821a55f43274364410c3d6a3c867526 | [
"MIT"
] | null | null | null | src/ctlinterfaces/LegacyImageListWrapper.cpp | TimoKunze/ShellBrowserControls | e1699dde8821a55f43274364410c3d6a3c867526 | [
"MIT"
] | 1 | 2021-12-09T18:23:05.000Z | 2021-12-09T18:23:05.000Z | // LegacyImageListWrapper.cpp: An implementation of the IImageList interface wrapping an image list for version 5 of comctl32.dll
#include "stdafx.h"
#include "LegacyImageListWrapper.h"
#include "../ClassFactory.h"
//////////////////////////////////////////////////////////////////////
// implementation of IUnknown
ULONG STDMETHODCALLTYPE LegacyImageListWrapper_AddRef(IImageList* pInterface)
{
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
return InterlockedIncrement(&pThis->referenceCount);
}
ULONG STDMETHODCALLTYPE LegacyImageListWrapper_Release(IImageList* pInterface)
{
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
ULONG ret = InterlockedDecrement(&pThis->referenceCount);
if(!ret) {
// the reference counter reached 0, so delete ourselves
ImageList_Destroy(pThis->hImageList);
HeapFree(GetProcessHeap(), 0, pThis);
}
return ret;
}
STDMETHODIMP LegacyImageListWrapper_QueryInterface(IImageList* pInterface, REFIID requiredInterface, LPVOID* ppInterfaceImpl)
{
if(!ppInterfaceImpl) {
return E_POINTER;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
if(requiredInterface == IID_IUnknown) {
*ppInterfaceImpl = reinterpret_cast<LPUNKNOWN>(&pThis->pImageListVtable);
} else if(requiredInterface == IID_IImageList) {
*ppInterfaceImpl = IImageListFromLegacyImageListWrapper(pThis);
} else {
// the requested interface is not supported
*ppInterfaceImpl = NULL;
return E_NOINTERFACE;
}
// we return a new reference to this object, so increment the counter
LegacyImageListWrapper_AddRef(pInterface);
return S_OK;
}
// implementation of IUnknown
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// implementation of IImageList
STDMETHODIMP LegacyImageListWrapper_Add(IImageList* pInterface, HBITMAP hbmImage, HBITMAP hbmMask, int* pi)
{
if(!pi) {
return E_POINTER;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
*pi = ImageList_Add(pThis->hImageList, hbmImage, hbmMask);
return (*pi != -1 ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_ReplaceIcon(IImageList* pInterface, int i, HICON hicon, int* pi)
{
if(!pi) {
return E_POINTER;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
*pi = ImageList_ReplaceIcon(pThis->hImageList, i, hicon);
return (*pi != -1 ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_SetOverlayImage(IImageList* pInterface, int iImage, int iOverlay)
{
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
BOOL b = ImageList_SetOverlayImage(pThis->hImageList, iImage, iOverlay);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_Replace(IImageList* pInterface, int i, HBITMAP hbmImage, HBITMAP hbmMask)
{
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
BOOL b = ImageList_Replace(pThis->hImageList, i, hbmImage, hbmMask);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_AddMasked(IImageList* pInterface, HBITMAP hbmImage, COLORREF crMask, int* pi)
{
if(!pi) {
return E_POINTER;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
*pi = ImageList_AddMasked(pThis->hImageList, hbmImage, crMask);
return (*pi != -1 ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_Draw(IImageList* pInterface, IMAGELISTDRAWPARAMS* pimldp)
{
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
IMAGELISTDRAWPARAMS params = *pimldp;
params.himl = pThis->hImageList;
BOOL b = ImageList_DrawIndirect(¶ms);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_Remove(IImageList* pInterface, int i)
{
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
BOOL b = ImageList_Remove(pThis->hImageList, i);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_GetIcon(IImageList* pInterface, int i, UINT flags, HICON* picon)
{
if(!picon) {
return E_POINTER;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
*picon = ImageList_GetIcon(pThis->hImageList, i, flags);
return (*picon ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_GetImageInfo(IImageList* pInterface, int i, IMAGEINFO* pImageInfo)
{
if(!pImageInfo) {
return E_POINTER;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
BOOL b = ImageList_GetImageInfo(pThis->hImageList, i, pImageInfo);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_Copy(IImageList* pInterface, int iDst, IUnknown* /*punkSrc*/, int iSrc, UINT uFlags)
{
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
BOOL b = ImageList_Copy(pThis->hImageList, iDst, pThis->hImageList, iSrc, uFlags);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_Merge(IImageList* pInterface, int i1, IUnknown* punk2, int i2, int dx, int dy, REFIID riid, void** ppv)
{
if(!ppv) {
return E_POINTER;
}
if(riid != IID_IImageList) {
return E_NOINTERFACE;
}
CComQIPtr<IImageList> pImgLstOfSecondImage = punk2;
if(!pImgLstOfSecondImage) {
return E_INVALIDARG;
}
HIMAGELIST hImgLstOfSecondImage = IImageListToHIMAGELIST(pImgLstOfSecondImage);
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
HIMAGELIST hImgLstResult = ImageList_Merge(pThis->hImageList, i1, hImgLstOfSecondImage, i2, dx, dy);
if(hImgLstResult) {
return LegacyImageListWrapper_CreateInstance(hImgLstResult, reinterpret_cast<IImageList**>(ppv));
}
return E_FAIL;
}
STDMETHODIMP LegacyImageListWrapper_Clone(IImageList* pInterface, REFIID riid, void** ppv)
{
if(!ppv) {
return E_POINTER;
}
if(riid != IID_IImageList) {
return E_NOINTERFACE;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
HIMAGELIST hImgLstClone = ImageList_Duplicate(pThis->hImageList);
if(hImgLstClone) {
return LegacyImageListWrapper_CreateInstance(hImgLstClone, reinterpret_cast<IImageList**>(ppv));
}
return E_FAIL;
}
STDMETHODIMP LegacyImageListWrapper_GetImageRect(IImageList* pInterface, int i, RECT* prc)
{
if(!prc) {
return E_POINTER;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
int iconWidth = 0;
int iconHeight = 0;
if(ImageList_GetIconSize(pThis->hImageList, &iconWidth, &iconHeight)) {
prc->left = i * iconWidth;
prc->top = 0;
prc->right = prc->left + iconWidth;
prc->bottom = prc->top + iconHeight;
return S_OK;
}
return E_FAIL;
}
STDMETHODIMP LegacyImageListWrapper_GetIconSize(IImageList* pInterface, int* cx, int* cy)
{
if(!cx || !cy) {
return E_POINTER;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
BOOL b = ImageList_GetIconSize(pThis->hImageList, cx, cy);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_SetIconSize(IImageList* pInterface, int cx, int cy)
{
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
BOOL b = ImageList_SetIconSize(pThis->hImageList, cx, cy);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_GetImageCount(IImageList* pInterface, int* pi)
{
if(!pi) {
return E_POINTER;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
*pi = ImageList_GetImageCount(pThis->hImageList);
return S_OK;
}
STDMETHODIMP LegacyImageListWrapper_SetImageCount(IImageList* pInterface, UINT uNewCount)
{
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
BOOL b = ImageList_SetImageCount(pThis->hImageList, uNewCount);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_SetBkColor(IImageList* pInterface, COLORREF clrBk, COLORREF* pclr)
{
if(!pclr) {
return E_POINTER;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
*pclr = ImageList_SetBkColor(pThis->hImageList, clrBk);
return (*pclr != CLR_NONE ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_GetBkColor(IImageList* pInterface, COLORREF* pclr)
{
if(!pclr) {
return E_POINTER;
}
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
*pclr = ImageList_GetBkColor(pThis->hImageList);
return S_OK;
}
STDMETHODIMP LegacyImageListWrapper_BeginDrag(IImageList* pInterface, int iTrack, int dxHotspot, int dyHotspot)
{
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
BOOL b = ImageList_BeginDrag(pThis->hImageList, iTrack, dxHotspot, dyHotspot);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_EndDrag(IImageList* /*pInterface*/)
{
ImageList_EndDrag();
return S_OK;
}
STDMETHODIMP LegacyImageListWrapper_DragEnter(IImageList* /*pInterface*/, HWND hwndLock, int x, int y)
{
BOOL b = ImageList_DragEnter(hwndLock, x, y);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_DragLeave(IImageList* /*pInterface*/, HWND hwndLock)
{
BOOL b = ImageList_DragLeave(hwndLock);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_DragMove(IImageList* /*pInterface*/, int x, int y)
{
BOOL b = ImageList_DragMove(x, y);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_SetDragCursorImage(IImageList* pInterface, IUnknown* /*punk*/, int iDrag, int dxHotspot, int dyHotspot)
{
LegacyImageListWrapper* pThis = LegacyImageListWrapperFromIImageList(pInterface);
BOOL b = ImageList_SetDragCursorImage(pThis->hImageList, iDrag, dxHotspot, dyHotspot);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_DragShowNolock(IImageList* /*pInterface*/, BOOL fShow)
{
BOOL b = ImageList_DragShowNolock(fShow);
return (b ? S_OK : E_FAIL);
}
STDMETHODIMP LegacyImageListWrapper_GetDragImage(IImageList* /*pInterface*/, POINT* ppt, POINT* pptHotspot, REFIID riid, void** ppv)
{
if(!ppv) {
return E_POINTER;
}
if(riid != IID_IImageList) {
return E_NOINTERFACE;
}
HIMAGELIST hImgLstResult = ImageList_GetDragImage(ppt, pptHotspot);
if(hImgLstResult) {
return LegacyImageListWrapper_CreateInstance(hImgLstResult, reinterpret_cast<IImageList**>(ppv));
}
return E_FAIL;
}
STDMETHODIMP LegacyImageListWrapper_GetItemFlags(IImageList* /*pInterface*/, int /*i*/, DWORD* /*dwFlags*/)
{
ATLASSERT(FALSE && "LegacyImageListWrapper_GetItemFlags() should never be called!");
return E_NOTIMPL;
}
STDMETHODIMP LegacyImageListWrapper_GetOverlayImage(IImageList* /*pInterface*/, int /*iOverlay*/, int* /*piIndex*/)
{
ATLASSERT(FALSE && "LegacyImageListWrapper_GetOverlayImage() should never be called!");
return E_NOTIMPL;
}
// implementation of IImageList
//////////////////////////////////////////////////////////////////////
STDMETHODIMP LegacyImageListWrapper_CreateInstance(HIMAGELIST hImageListToWrap, IImageList** ppObject)
{
if(!ppObject) {
return E_POINTER;
}
if(!hImageListToWrap) {
return E_INVALIDARG;
}
LegacyImageListWrapper* pInstance = static_cast<LegacyImageListWrapper*>(HeapAlloc(GetProcessHeap(), 0, sizeof(LegacyImageListWrapper)));
if(!pInstance) {
return E_OUTOFMEMORY;
}
ZeroMemory(pInstance, sizeof(*pInstance));
pInstance->magicValue = 0x4C4D4948;
pInstance->pImageListVtable = &IImageListImpl_Vtbl;
pInstance->referenceCount = 1;
pInstance->hImageList = hImageListToWrap;
*ppObject = IImageListFromLegacyImageListWrapper(pInstance);
return S_OK;
} | 32.187151 | 139 | 0.762649 | [
"object"
] |
825b2681fc80e12cebcd6f7ee64cc4696450f0d3 | 35,773 | cpp | C++ | src/campaign/atlas.cpp | ArneDJ/terranova | 533e9e5687d464153418f73a1d811f57e7c572b9 | [
"CC0-1.0"
] | null | null | null | src/campaign/atlas.cpp | ArneDJ/terranova | 533e9e5687d464153418f73a1d811f57e7c572b9 | [
"CC0-1.0"
] | null | null | null | src/campaign/atlas.cpp | ArneDJ/terranova | 533e9e5687d464153418f73a1d811f57e7c572b9 | [
"CC0-1.0"
] | null | null | null | #include <vector>
#include <random>
#include <memory>
#include <queue>
#include <list>
#include <chrono>
#include <unordered_map>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "../extern/fastnoise/FastNoise.h"
#include "../extern/poisson/PoissonGenerator.h"
#include "../geometry/geometry.h"
#include "../geometry/voronoi.h"
#include "../geometry/transform.h"
#include "../util/image.h"
#include "../util/noise.h"
#include "../util/erode.h"
#include "atlas.h"
static RiverBranch *create_branch(const Corner *confluence)
{
RiverBranch *node = new RiverBranch;
node->confluence = confluence;
node->left = nullptr;
node->right = nullptr;
node->streamorder = 1;
return node;
}
static void prune_branches(RiverBranch *root)
{
if (root == nullptr) { return; }
std::queue<RiverBranch*> queue;
queue.push(root);
while (!queue.empty()) {
RiverBranch *front = queue.front();
queue.pop();
if (front->left) { queue.push(front->left); }
if (front->right) { queue.push(front->right); }
delete front;
}
root = nullptr;
}
static void delete_basin(DrainageBasin *tree)
{
if (tree->mouth == nullptr) { return; }
prune_branches(tree->mouth);
tree->mouth = nullptr;
}
// Strahler stream order
// https://en.wikipedia.org/wiki/Strahler_number
static inline int strahler(const RiverBranch *node)
{
// if node has no children it is a leaf with stream order 1
if (node->left == nullptr && node->right == nullptr) {
return 1;
}
int left = (node->left != nullptr) ? node->left->streamorder : 0;
int right = (node->right != nullptr) ? node->right->streamorder : 0;
if (left == right) {
return std::max(left, right) + 1;
} else {
return std::max(left, right);
}
}
// Shreve stream order
// https://en.wikipedia.org/wiki/Stream_order#Shreve_stream_order
static inline int shreve(const RiverBranch *node)
{
// if node has no children it is a leaf with stream order 1
if (node->left == nullptr && node->right == nullptr) {
return 1;
}
int left = (node->left != nullptr) ? node->left->streamorder : 0;
int right = (node->right != nullptr) ? node->right->streamorder : 0;
return left + right;
}
static inline int postorder_level(RiverBranch *node)
{
if (node->left == nullptr && node->right == nullptr) {
return 0;
}
if (node->left != nullptr && node->right != nullptr) {
return std::max(node->left->depth, node->right->depth) + 1;
}
if (node->left) { return node->left->depth + 1; }
if (node->right) { return node->right->depth + 1; }
return 0;
}
// post order tree traversal
static void stream_postorder(DrainageBasin *tree)
{
std::list<RiverBranch*> stack;
RiverBranch *prev = nullptr;
stack.push_back(tree->mouth);
while (!stack.empty()) {
RiverBranch *current = stack.back();
if (prev == nullptr || prev->left == current || prev->right == current) {
if (current->left != nullptr) {
stack.push_back(current->left);
} else if (current->right != nullptr) {
stack.push_back(current->right);
} else {
current->streamorder = strahler(current);
current->depth = postorder_level(current);
stack.pop_back();
}
} else if (current->left == prev) {
if (current->right != nullptr) {
stack.push_back(current->right);
} else {
current->streamorder = strahler(current);
current->depth = postorder_level(current);
stack.pop_back();
}
} else if (current->right == prev) {
current->streamorder = strahler(current);
current->depth = postorder_level(current);
stack.pop_back();
}
prev = current;
}
}
static bool prunable(const RiverBranch *node, uint8_t min_stream)
{
return (node->streamorder < min_stream);
}
Atlas::Atlas()
{
const uint16_t size = 2048;
m_heightmap.resize(size, size, util::COLORSPACE_GRAYSCALE);
m_normalmap.resize(size, size, util::COLORSPACE_RGB);
m_mask.resize(size, size, util::COLORSPACE_GRAYSCALE);
}
Atlas::~Atlas()
{
clear();
}
void Atlas::generate(int seed, const geom::Rectangle &bounds, const AtlasParameters ¶meters)
{
m_bounds = bounds;
// clear all data
clear();
// generate the graph
std::mt19937 gen(seed);
glm::vec2 scale = bounds.max - bounds.min;
std::vector<glm::vec2> points;
PoissonGenerator::DefaultPRNG PRNG(seed);
const auto positions = PoissonGenerator::generatePoissonPoints(8000, PRNG, false);
for (const auto &position : positions) {
glm::vec2 point = { scale.x * position.x, scale.y * position.y };
point += bounds.min;
points.push_back(point);
}
m_graph.generate(points, bounds, 2);
// create tile map
m_tiles.resize(m_graph.cells.size());
for (const auto &cell : m_graph.cells) {
Tile tile;
tile.index = cell.index;
m_tiles[cell.index] = tile;
}
// borders
m_borders.resize(m_graph.edges.size());
for (const auto &edge : m_graph.edges) {
Border border;
border.index = edge.index;
m_borders[edge.index] = border;
}
// corners
m_corners.resize(m_graph.vertices.size());
for (const auto &vertex : m_graph.vertices) {
Corner corner;
corner.index = vertex.index;
m_corners[vertex.index] = corner;
}
// find edge cases
for (auto &border : m_borders) {
const auto &edge = m_graph.edges[border.index];
if (edge.left_cell == edge.right_cell) {
border.flags |= BORDER_FLAG_FRONTIER;
m_tiles[edge.left_cell->index].flags |= TILE_FLAG_FRONTIER;
m_corners[edge.left_vertex->index].flags |= CORNER_FLAG_FRONTIER;
m_corners[edge.right_vertex->index].flags |= CORNER_FLAG_FRONTIER;
}
}
// create height map
FastNoise fastnoise;
fastnoise.SetSeed(seed);
fastnoise.SetNoiseType(FastNoise::SimplexFractal);
fastnoise.SetFractalType(FastNoise::FBM);
fastnoise.SetFrequency(parameters.noise_frequency);
fastnoise.SetFractalOctaves(parameters.noise_octaves);
fastnoise.SetFractalLacunarity(parameters.noise_lacunarity);
fastnoise.SetPerturbFrequency(parameters.perturb_frequency);
fastnoise.SetGradientPerturbAmp(parameters.perturb_amp);
// fill image with noise
const glm::vec2 image_scale = {
scale.x / float(m_heightmap.width()),
scale.y / float(m_heightmap.height())
};
util::noise_image(m_heightmap, &fastnoise, image_scale, util::CHANNEL_RED);
//util::Eroder eroder;
//eroder.erode(m_heightmap);
for (auto &tile : m_tiles) {
glm::vec2 center = m_graph.cells[tile.index].center;
float x = center.x / scale.x;
float y = center.y / scale.y;
tile.height = 255 * m_heightmap.sample_relative(x, y, util::CHANNEL_RED);
if (tile.height > parameters.mountains) {
tile.relief = ReliefType::MOUNTAINS;
} else if (tile.height > parameters.hills) {
tile.relief = ReliefType::HILLS;
} else if (tile.height > parameters.lowland) {
tile.relief = ReliefType::LOWLAND;
} else {
tile.relief = ReliefType::SEABED;
}
}
// relief floodfill
floodfill_relief(64, ReliefType::SEABED, ReliefType::LOWLAND);
floodfill_relief(4, ReliefType::MOUNTAINS, ReliefType::HILLS);
remove_echoriads();
mark_islands(64);
mark_coasts();
mark_walls();
form_rivers();
// relief has been altered by rivers // and apply corrections
floodfill_relief(4, ReliefType::MOUNTAINS, ReliefType::HILLS);
mark_walls();
// alter height map
create_reliefmap(seed);
river_cut_relief();
//m_heightmap.normalize(util::CHANNEL_RED);
}
void Atlas::clear()
{
m_tiles.clear();
m_corners.clear();
m_borders.clear();
delete_basins();
m_graph.clear();
m_heightmap.wipe();
m_mask.wipe();
}
const geom::VoronoiGraph& Atlas::graph() const
{
return m_graph;
}
const std::vector<Tile>& Atlas::tiles() const
{
return m_tiles;
}
const std::vector<Corner>& Atlas::corners() const
{
return m_corners;
}
const std::vector<Border>& Atlas::borders() const
{
return m_borders;
}
const util::Image<float>& Atlas::heightmap() const
{
return m_heightmap;
}
const util::Image<float>& Atlas::normalmap() const
{
return m_normalmap;
}
const Tile* Atlas::tile_at(const glm::vec2 &position) const
{
auto search = m_graph.cell_at(position);
if (search.found) {
return &m_tiles[search.cell->index];
}
return nullptr;
}
glm::vec2 Atlas::tile_center(uint32_t index) const
{
return m_graph.cells[index].center;
}
const geom::Rectangle& Atlas::bounds() const
{
return m_bounds;
}
void Atlas::floodfill_relief(unsigned max_size, ReliefType target, ReliefType replacement)
{
const auto &cells = m_graph.cells;
std::unordered_map<uint32_t, bool> visited;
for (auto &root : m_tiles) {
std::vector<Tile*> marked;
if (visited[root.index] == false && root.relief == target) {
// breadth first search
visited[root.index] = true;
std::queue<uint32_t> queue;
queue.push(root.index);
while (!queue.empty()) {
uint32_t node = queue.front();
queue.pop();
marked.push_back(&m_tiles[node]);
for (const auto &cell : cells[node].neighbors) {
Tile *neighbor = &m_tiles[cell->index];
if (visited[neighbor->index] == false) {
visited[neighbor->index] = true;
if (neighbor->relief == target) {
queue.push(neighbor->index);
}
}
}
}
}
// now that the size is known replace with target
if (marked.size() > 0 && marked.size() < max_size) {
for (Tile *tile : marked) {
tile->relief = replacement;
}
}
}
}
void Atlas::remove_echoriads()
{
const auto &cells = m_graph.cells;
std::unordered_map<uint32_t, bool> visited;
for (auto &root : m_tiles) {
std::vector<Tile*> marked;
if (visited[root.index] == false && walkable_tile(&root) == true) {
bool found_water = false;
visited[root.index] = true;
std::queue<Tile*> queue;
queue.push(&root);
while (!queue.empty()) {
Tile *tile = queue.front();
queue.pop();
marked.push_back(tile);
for (const auto &cell : cells[tile->index].neighbors) {
Tile *neighbor = &m_tiles[cell->index];
if (neighbor->relief == ReliefType::SEABED) {
found_water = true;
break;
}
if (visited[neighbor->index] == false) {
visited[neighbor->index] = true;
if (walkable_tile(neighbor)) {
queue.push(neighbor);
}
}
}
}
if (found_water == false) {
for (Tile *tile : marked) {
tile->relief = ReliefType::MOUNTAINS;
}
}
}
}
}
void Atlas::mark_islands(unsigned max_size)
{
const auto &cells = m_graph.cells;
std::unordered_map<uint32_t, bool> visited;
for (auto &root : m_tiles) {
std::vector<Tile*> marked;
if (visited[root.index] == false && walkable_tile(&root) == true) {
bool found_water = false;
visited[root.index] = true;
std::queue<Tile*> queue;
queue.push(&root);
while (!queue.empty()) {
Tile *tile = queue.front();
queue.pop();
marked.push_back(tile);
for (const auto &cell : cells[tile->index].neighbors) {
Tile *neighbor = &m_tiles[cell->index];
if (neighbor->relief == ReliefType::SEABED) {
found_water = true;
}
if (visited[neighbor->index] == false) {
visited[neighbor->index] = true;
if (walkable_tile(neighbor)) {
queue.push(neighbor);
}
}
}
}
if (found_water == true && marked.size() < max_size) {
for (Tile *tile : marked) {
tile->flags |= TILE_FLAG_ISLAND;
}
}
}
}
}
void Atlas::mark_coasts()
{
for (auto &tile : m_tiles) {
bool local_land = tile.relief != ReliefType::SEABED;
for (const auto &cell : m_graph.cells[tile.index].neighbors) {
Tile *neighbor = &m_tiles[cell->index];
bool neighbor_land = neighbor->relief != ReliefType::SEABED;
if (local_land ^ neighbor_land) {
tile.flags |= TILE_FLAG_COAST;
}
}
}
for (auto &border : m_borders) {
const auto &edge = m_graph.edges[border.index];
bool left_land = m_tiles[edge.left_cell->index].relief != ReliefType::SEABED;
bool right_land = m_tiles[edge.right_cell->index].relief != ReliefType::SEABED;
if (left_land ^ right_land) {
border.flags |= BORDER_FLAG_COAST;
m_corners[edge.left_vertex->index].flags |= CORNER_FLAG_COAST;
m_corners[edge.right_vertex->index].flags |= CORNER_FLAG_COAST;
}
}
}
// a wall is a border between a mountain tile and a non mountain tile
void Atlas::mark_walls()
{
for (auto &corner : m_corners) {
corner.flags &= ~CORNER_FLAG_WALL; // reset
bool walkable = false;
bool near_mountain = false;
const auto &vertex = m_graph.vertices[corner.index];
for (const auto &cell : vertex.cells) {
const auto &tile = m_tiles[cell->index];
if (tile.relief == ReliefType::MOUNTAINS) {
near_mountain = true;
} else if (tile.relief == ReliefType::HILLS || tile.relief == ReliefType::LOWLAND) {
walkable = true;
}
}
bool frontier = corner.flags & CORNER_FLAG_FRONTIER;
if (near_mountain && walkable) {
corner.flags |= CORNER_FLAG_WALL;
}
if (near_mountain && frontier) {
corner.flags |= CORNER_FLAG_WALL;
}
}
for (auto &border : m_borders) {
border.flags &= ~BORDER_FLAG_WALL; // reset
const auto &edge = m_graph.edges[border.index];
auto &left = m_tiles[edge.left_cell->index];
auto &right = m_tiles[edge.right_cell->index];
bool frontier = border.flags & BORDER_FLAG_FRONTIER;
if (frontier && (left.relief == ReliefType::MOUNTAINS || right.relief == ReliefType::MOUNTAINS)) {
border.flags |= BORDER_FLAG_WALL;
} else if ((left.relief == ReliefType::MOUNTAINS) ^ (right.relief == ReliefType::MOUNTAINS)) {
border.flags |= BORDER_FLAG_WALL;
}
}
}
void Atlas::form_rivers()
{
// construct the drainage basin candidate graph
// only land corners not on the edge of the map can be candidates for the graph
std::vector<const Corner*> candidates;
for (auto &corner : m_corners) {
const auto &vertex = m_graph.vertices[corner.index];
bool frontier = corner.flags & CORNER_FLAG_FRONTIER;
if (!frontier) {
// find if corner touches land
for (const auto &cell : vertex.cells) {
const auto &tile = m_tiles[cell->index];
if (tile.relief != ReliefType::SEABED) {
candidates.push_back(&corner);
corner.flags |= CORNER_FLAG_RIVER;
break;
}
}
}
}
form_drainage_basins(candidates);
// first river assign
assign_rivers();
// river basins will erode some mountains
river_erode_mountains(2);
trim_drainage_basins(3);
// second river assign
assign_rivers();
trim_rivers();
prune_stubby_rivers(3, 4);
// last river assign
assign_rivers();
}
void Atlas::form_drainage_basins(const std::vector<const Corner*> &candidates)
{
struct Meta {
bool visited = false;
int elevation = 0;
int score = 0;
};
std::unordered_map<const Corner*, Meta> lookup;
// add starting weight based on elevation
// corners with higher elevation will get a higher weight
for (auto node : candidates) {
int weight = 0;
const auto &vertex = m_graph.vertices[node->index];
for (const auto &cell : vertex.cells) {
const auto &tile = m_tiles[cell->index];
if (tile.relief == ReliefType::HILLS) {
weight += 3;
} else if (tile.relief == ReliefType::MOUNTAINS) {
weight += 4;
}
}
Meta data = { false, weight, 0 };
lookup[node] = data;
}
// breadth first search to start the drainage basin
// assign scores
for (auto root : candidates) {
if (root->flags & CORNER_FLAG_COAST) {
std::queue<const Corner*> frontier;
lookup[root].visited = true;
frontier.push(root);
while (!frontier.empty()) {
const Corner *corner = frontier.front();
frontier.pop();
Meta &data = lookup[corner];
int depth = data.score + data.elevation + 1;
for (const auto &vertex : m_graph.vertices[corner->index].adjacent) {
const Corner *neighbor = &m_corners[vertex->index];
bool river = neighbor->flags & CORNER_FLAG_RIVER;
bool coast = neighbor->flags & CORNER_FLAG_COAST;
if (river && !coast) {
Meta &neighbor_data = lookup[neighbor];
if (!neighbor_data.visited) {
neighbor_data.visited = true;
neighbor_data.score = depth;
frontier.push(neighbor);
} else if (neighbor_data.score > depth && neighbor_data.elevation >= data.elevation) {
neighbor_data.score = depth;
frontier.push(neighbor);
}
}
}
}
}
}
// reset visited
for (auto node : candidates) {
lookup[node].visited = false;
}
// create the drainage basin binary trees
for (auto root : candidates) {
if (root->flags & CORNER_FLAG_COAST) {
lookup[root].visited = true;
// new drainage basin
DrainageBasin basin = {};
basin.mouth = create_branch(root);
std::queue<RiverBranch*> frontier;
frontier.push(basin.mouth);
while (!frontier.empty()) {
RiverBranch *fork = frontier.front(); frontier.pop();
const Corner *corner = fork->confluence;
Meta &corner_data = lookup[corner];
for (const auto &vertex : m_graph.vertices[corner->index].adjacent) {
const Corner *neighbor = &m_corners[vertex->index];
Meta &neighbor_data = lookup[neighbor];
bool coast = neighbor->flags & CORNER_FLAG_COAST;
if (!neighbor_data.visited && !coast) {
if (neighbor_data.score > corner_data.score && neighbor_data.elevation >= corner_data.elevation) {
neighbor_data.visited = true;
// create a new branch
RiverBranch *child = create_branch(neighbor);
frontier.push(child);
if (fork->left == nullptr) {
fork->left = child;
} else if (fork->right == nullptr) {
fork->right = child;
}
}
}
}
}
basins.push_back(basin);
}
}
// assign stream order numbers
for (auto &basin : basins) {
stream_postorder(&basin);
}
}
void Atlas::river_erode_mountains(size_t min)
{
for (auto it = basins.begin(); it != basins.end(); ) {
DrainageBasin &bas = *it;
std::queue<RiverBranch*> queue;
queue.push(bas.mouth);
while (!queue.empty()) {
RiverBranch *cur = queue.front(); queue.pop();
if (cur->streamorder > min) {
const auto &vertex = m_graph.vertices[cur->confluence->index];
for (const auto &cell : vertex.cells) {
auto &tile = m_tiles[cell->index];
if (tile.relief == ReliefType::MOUNTAINS) {
tile.relief = ReliefType::HILLS;
}
}
}
if (cur->right != nullptr) {
queue.push(cur->right);
}
if (cur->left != nullptr) {
queue.push(cur->left);
}
}
++it;
}
}
void Atlas::trim_drainage_basins(size_t min)
{
// prune binary tree branch if the stream order is too low
for (auto it = basins.begin(); it != basins.end(); ) {
DrainageBasin &bas = *it;
std::queue<RiverBranch*> queue;
queue.push(bas.mouth);
while (!queue.empty()) {
RiverBranch *cur = queue.front(); queue.pop();
if (cur->right != nullptr) {
if (prunable(cur->right, min)) {
prune_branches(cur->right);
cur->right = nullptr;
} else {
queue.push(cur->right);
}
}
if (cur->left != nullptr) {
if (prunable(cur->left, min)) {
prune_branches(cur->left);
cur->left = nullptr;
} else {
queue.push(cur->left);
}
}
}
if (bas.mouth->right == nullptr && bas.mouth->left == nullptr) {
delete bas.mouth;
bas.mouth = nullptr;
it = basins.erase(it);
} else {
++it;
}
}
}
void Atlas::trim_rivers()
{
// remove rivers too close to each other
static const float MIN_RIVER_DISTANCE = 4.F;
for (auto &border : m_borders) {
if (!(border.flags & BORDER_FLAG_RIVER)) {
const auto &edge = m_graph.edges[border.index];
// river with the smallest stream order is trimmed
// if they have the same stream order do a coin flip
auto &left = m_corners[edge.left_vertex->index];
auto &right = m_corners[edge.right_vertex->index];
if ((left.flags & CORNER_FLAG_RIVER) && (right.flags & CORNER_FLAG_RIVER)) {
float d = glm::distance(edge.left_vertex->position, edge.right_vertex->position);
if (d < MIN_RIVER_DISTANCE) {
if (left.river_depth > right.river_depth) {
right.flags &= ~CORNER_FLAG_RIVER;
} else {
left.flags &= ~CORNER_FLAG_RIVER;
}
}
}
}
}
// remove rivers too close to map edges or mountains
for (auto &corner : m_corners) {
if (corner.flags & CORNER_FLAG_RIVER) {
const auto &vertex = m_graph.vertices[corner.index];
for (const auto &adjacent : vertex.adjacent) {
const auto &neighbor = m_corners[adjacent->index];
if (neighbor.flags & CORNER_FLAG_WALL) {
corner.flags &= ~CORNER_FLAG_RIVER;
break;
}
}
}
}
// do the actual pruning in the basin
for (auto it = basins.begin(); it != basins.end(); ) {
DrainageBasin &basin = *it;
std::queue<RiverBranch*> queue;
queue.push(basin.mouth);
while (!queue.empty()) {
RiverBranch *cur = queue.front();
queue.pop();
if (cur->right != nullptr) {
if ((cur->right->confluence->flags & CORNER_FLAG_RIVER) == false) {
prune_branches(cur->right);
cur->right = nullptr;
} else {
queue.push(cur->right);
}
}
if (cur->left != nullptr) {
if ((cur->left->confluence->flags & CORNER_FLAG_RIVER) == false) {
prune_branches(cur->left);
cur->left = nullptr;
} else {
queue.push(cur->left);
}
}
}
if (basin.mouth->right == nullptr && basin.mouth->left == nullptr) {
delete basin.mouth;
basin.mouth = nullptr;
it = basins.erase(it);
} else {
++it;
}
}
}
void Atlas::prune_stubby_rivers(uint8_t min_branch, uint8_t min_basin)
{
std::unordered_map<const RiverBranch*, int> depth;
std::unordered_map<const RiverBranch*, bool> removable;
std::unordered_map<RiverBranch*, RiverBranch*> parents;
std::vector<RiverBranch*> endnodes;
// find river end nodes
for (auto it = basins.begin(); it != basins.end(); ) {
DrainageBasin &bas = *it;
std::queue<RiverBranch*> queue;
queue.push(bas.mouth);
parents[bas.mouth] = nullptr;
removable[bas.mouth] = false;
while (!queue.empty()) {
RiverBranch *cur = queue.front();
depth[cur] = -1;
queue.pop();
if (cur->right == nullptr && cur->left == nullptr) {
endnodes.push_back(cur);
depth[cur] = 0;
} else {
if (cur->right != nullptr) {
queue.push(cur->right);
parents[cur->right] = cur;
}
if (cur->left != nullptr) {
queue.push(cur->left);
parents[cur->left] = cur;
}
}
}
++it;
}
// starting from end nodes assign depth to nodes until they reach a branch
for (auto &node : endnodes) {
std::queue<RiverBranch*> queue;
queue.push(node);
while (!queue.empty()) {
RiverBranch *cur = queue.front();
queue.pop();
RiverBranch *parent = parents[cur];
if (parent) {
depth[parent] = depth[cur] + 1;
if (parent->left != nullptr && parent->right != nullptr) {
// reached a branch
if (depth[cur] > -1 && depth[cur] < min_branch) {
prune_branches(cur);
if (cur == parent->left) {
parent->left = nullptr;
} else if (cur == parent->right) {
parent->right = nullptr;
}
}
} else {
queue.push(parent);
}
} else if (depth[cur] < min_basin) {
// reached the river mouth
// river is simply too small so mark it for deletion
removable[cur] = true;
}
}
}
// remove river basins if they are too small
for (auto it = basins.begin(); it != basins.end(); ) {
DrainageBasin &bas = *it;
if (removable[bas.mouth]) {
delete_basin(&bas);
it = basins.erase(it);
} else {
it++;
}
}
}
// assign river data from basins to the graph data
void Atlas::assign_rivers()
{
// reset river flags
for (auto &corner : m_corners) {
corner.flags &= ~CORNER_FLAG_RIVER;
}
for (auto &border : m_borders) {
border.flags &= ~BORDER_FLAG_RIVER;
}
for (auto &tile : m_tiles) {
tile.flags &= ~TILE_FLAG_RIVER;
}
// link the borders with the river corners
std::map<std::pair<uint32_t, uint32_t>, Border*> link;
for (auto &border : m_borders) {
border.flags &= ~BORDER_FLAG_RIVER;
const auto &edge = m_graph.edges[border.index];
link[std::minmax(edge.left_vertex->index, edge.right_vertex->index)] = &border;
}
for (const auto &basin : basins) {
if (basin.mouth) {
std::queue<RiverBranch*> queue;
queue.push(basin.mouth);
while (!queue.empty()) {
RiverBranch *cur = queue.front(); queue.pop();
m_corners[cur->confluence->index].flags |= CORNER_FLAG_RIVER;
m_corners[cur->confluence->index].river_depth = cur->depth;
if (cur->right != nullptr) {
Border *bord = link[std::minmax(cur->confluence->index, cur->right->confluence->index)];
if (bord) {
bord->flags |= BORDER_FLAG_RIVER;
}
queue.push(cur->right);
}
if (cur->left != nullptr) {
Border *bord = link[std::minmax(cur->confluence->index, cur->left->confluence->index)];
if (bord) {
bord->flags |= BORDER_FLAG_RIVER;
}
queue.push(cur->left);
}
}
}
}
for (auto &tile : m_tiles) {
const auto &cell = m_graph.cells[tile.index];
for (auto &edge : cell.edges) {
const auto &border = m_borders[edge->index];
if (border.flags & BORDER_FLAG_RIVER) {
tile.flags |= TILE_FLAG_RIVER;
break;
}
}
}
}
void Atlas::form_mountain_ridges()
{
// create initial candidate network
// only corners next to mountains are part of the network
std::vector<const Corner*> candidates;
std::unordered_map<uint32_t, bool> touches_mountain;
for (const auto &corner : m_corners) {
touches_mountain[corner.index] = false;
const auto &vertex = m_graph.vertices[corner.index];
// find if corner touches mountains
for (const auto &cell : vertex.cells) {
const auto &tile = m_tiles[cell->index];
if (tile.relief == ReliefType::MOUNTAINS) {
candidates.push_back(&corner);
touches_mountain[corner.index] = true;
break;
}
}
}
struct Meta {
bool visited = false;
int score = 0;
};
std::unordered_map<const Corner*, Meta> lookup;
// starting scores
for (auto node : candidates) {
Meta data = { false, 0 };
lookup[node] = data;
}
// do breadth first search for each mountain corner to find the closest "exit" out of the mountains
// this creates something similar to a drainage network
// this drainage network is used to define the mountain ridges
for (auto root : candidates) {
if (root->flags & CORNER_FLAG_WALL) {
std::queue<const Corner*> frontier;
lookup[root].visited = true;
frontier.push(root);
while (!frontier.empty()) {
const Corner *corner = frontier.front();
frontier.pop();
Meta &data = lookup[corner];
int depth = data.score + 1;
for (const auto &vertex : m_graph.vertices[corner->index].adjacent) {
const Corner *neighbor = &m_corners[vertex->index];
bool mountain = touches_mountain[neighbor->index];
bool wall = neighbor->flags & CORNER_FLAG_WALL;
if (mountain && !wall) {
Meta &neighbor_data = lookup[neighbor];
if (!neighbor_data.visited) {
neighbor_data.visited = true;
neighbor_data.score = depth;
frontier.push(neighbor);
} else if (neighbor_data.score > depth) {
neighbor_data.score = depth;
frontier.push(neighbor);
}
}
}
}
}
}
// now that we have the scores create the mountain valley network
// true if a border is a valley
std::unordered_map<uint32_t, bool> valleys;
// link the borders with the river corners
std::map<std::pair<uint32_t, uint32_t>, uint32_t> link;
for (const auto &border : m_borders) {
const auto &edge = m_graph.edges[border.index];
link[std::minmax(edge.left_vertex->index, edge.right_vertex->index)] = border.index;
}
// reset visited
for (auto node : candidates) {
lookup[node].visited = false;
}
// create the drainage basin binary trees
for (auto root : candidates) {
if (root->flags & CORNER_FLAG_WALL) {
std::queue<const Corner*> frontier;
lookup[root].visited = true;
frontier.push(root);
while (!frontier.empty()) {
const Corner *corner = frontier.front();
frontier.pop();
Meta &data = lookup[corner];
for (const auto &vertex : m_graph.vertices[corner->index].adjacent) {
const Corner *neighbor = &m_corners[vertex->index];
Meta &neighbor_data = lookup[neighbor];
bool wall = neighbor->flags & CORNER_FLAG_WALL;
if (!neighbor_data.visited && !wall) {
if (neighbor_data.score > data.score) {
neighbor_data.visited = true;
frontier.push(neighbor);
// mark valley
auto bord = link[std::minmax(corner->index, neighbor->index)];
valleys[bord] = true;
}
}
}
}
}
}
m_mask.wipe();
const uint8_t color = 255;
// based on the valley network we will asign mountain ridges
// this gives a "fractal" appearance to the mountains like in real life
for (const auto &border : m_borders) {
// is not a valley so we will make a mountain ridge by connecting the two tiles
if (!(valleys[border.index])) {
const auto &edge = m_graph.edges[border.index];
auto &left = m_tiles[edge.left_cell->index];
auto &right = m_tiles[edge.right_cell->index];
// only make ridge if both are mountains
if (left.relief == ReliefType::MOUNTAINS && right.relief == ReliefType::MOUNTAINS) {
glm::vec2 a = m_graph.cells[left.index].center / m_bounds.max;
glm::vec2 b = m_graph.cells[right.index].center / m_bounds.max;
m_mask.draw_thick_line_relative(a, b, 3, util::CHANNEL_RED, color);
}
}
}
m_mask.blur(1.f);
// finally apply the mountain ridges to the heightmap
#pragma omp parallel for
for (int x = 0; x < m_heightmap.width(); x++) {
for (int y = 0; y < m_heightmap.height(); y++) {
float height = m_heightmap.sample(x, y, util::CHANNEL_RED);
uint8_t amp = m_mask.sample(x, y, util::CHANNEL_RED);
if (amp) {
height += 0.1f * (amp / 255.f);
m_heightmap.plot(x, y, util::CHANNEL_RED, height);
}
}
}
}
void Atlas::form_base_relief()
{
// the mountain tiles have an amp score
// the closer a mountain tile is to a non mountain tile the lower the score
struct Meta {
bool visited = false;
int score = 0;
};
std::unordered_map<const Tile*, Meta> lookup;
std::vector<const Tile*> roots; // mountain tiles to start breadth first search
for (const auto &tile : m_tiles) {
Meta data = { false, 0 };
if (tile.relief == ReliefType::MOUNTAINS) {
bool mountain_border = false;
for (const auto &cell : m_graph.cells[tile.index].neighbors) {
Tile *neighbor = &m_tiles[cell->index];
if (neighbor->relief != ReliefType::MOUNTAINS) {
mountain_border = true;
break;
}
}
if (mountain_border) {
roots.push_back(&tile);
data.visited = true;
}
}
// starting scores
lookup[&tile] = data;
}
// do breadth first search to calculate score
for (const auto &root : roots) {
std::queue<const Tile*> frontier;
lookup[root].visited = true;
frontier.push(root);
while (!frontier.empty()) {
const Tile *tile = frontier.front();
frontier.pop();
Meta &data = lookup[tile];
int depth = data.score + 1;
for (const auto &cell : m_graph.cells[tile->index].neighbors) {
const Tile *neighbor = &m_tiles[cell->index];
bool mountain = neighbor->relief == ReliefType::MOUNTAINS;
if (mountain) {
Meta &neighbor_data = lookup[neighbor];
if (!neighbor_data.visited) {
neighbor_data.visited = true;
neighbor_data.score = depth;
frontier.push(neighbor);
} else if (neighbor_data.score > depth) {
neighbor_data.score = depth;
frontier.push(neighbor);
}
}
}
}
}
geom::Bounding<int> score_bounds = { 0, 5 };
// base per tile relief heightmap
#pragma omp parallel for
for (const auto &tile : m_tiles) {
float amp = 0.7f;
// translate mountain score to amplitude
if (tile.relief == ReliefType::MOUNTAINS) {
Meta &data = lookup[&tile];
// clamp the score within the bounds
int score = glm::clamp(data.score, score_bounds.min, score_bounds.max);
float mix = score / float(score_bounds.max);
amp = glm::mix(0.8f, 1.f, mix);
} else if (tile.relief == ReliefType::SEABED) {
amp = 0.3f;
}
// draw the triangles
glm::vec2 center = m_graph.cells[tile.index].center / m_bounds.max;
const auto &cell = m_graph.cells[tile.index];
for (auto &edge : cell.edges) {
const auto &left_vertex = edge->left_vertex;
const auto &right_vertex = edge->right_vertex;
glm::vec2 a = left_vertex->position / m_bounds.max;
glm::vec2 b = right_vertex->position / m_bounds.max;
//m_heightmap.draw_triangle_relative(center, a, b, util::CHANNEL_RED, amp * (tile.height / 255.f));
std::vector<glm::ivec2> pixels;
m_heightmap.find_triangle_pixels_relative(center, a, b, pixels);
for (const auto &pixel : pixels) {
float height = m_heightmap.sample(pixel.x, pixel.y, util::CHANNEL_RED);
height = glm::mix(height, amp * (tile.height / 255.f), 0.7f);
//height *= amp;
m_heightmap.plot(pixel.x, pixel.y, util::CHANNEL_RED, height);
}
}
}
}
void Atlas::create_reliefmap(int seed)
{
form_base_relief();
form_mountain_ridges();
m_heightmap.blur(4.f);
m_mask.blur(2.f);
// detail
FastNoise billow;
billow.SetSeed(seed);
billow.SetNoiseType(FastNoise::SimplexFractal);
billow.SetFractalType(FastNoise::Billow);
billow.SetFrequency(0.03f);
billow.SetFractalOctaves(6);
billow.SetFractalLacunarity(2.5f);
billow.SetGradientPerturbAmp(40.f);
// for edgy mountain peaks
FastNoise cellnoise;
cellnoise.SetSeed(seed);
cellnoise.SetNoiseType(FastNoise::Cellular);
cellnoise.SetCellularDistanceFunction(FastNoise::Euclidean);
cellnoise.SetFrequency(0.2f);
cellnoise.SetCellularReturnType(FastNoise::Distance2Add);
#pragma omp parallel for
for (int x = 0; x < m_heightmap.width(); x++) {
for (int y = 0; y < m_heightmap.height(); y++) {
uint8_t amp = m_mask.sample(x, y, util::CHANNEL_RED);
if (amp) {
float height = m_heightmap.sample(x, y, util::CHANNEL_RED);
float noise = 0.5f * (billow.GetNoise(x, y) + 1.f);
float peak = 0.08f * cellnoise.GetNoise(x, y);
height += 0.1f * noise;
height = glm::mix(height, height + peak, amp / 255.f);
m_heightmap.plot(x, y, util::CHANNEL_RED, height);
}
}
}
m_heightmap.blur(1.f);
}
void Atlas::river_cut_relief()
{
// blank canvas
m_mask.wipe();
// add rivers as lines to the mask
#pragma omp parallel for
for (const auto &border : m_borders) {
if (border.flags & BORDER_FLAG_RIVER) {
const auto &edge = m_graph.edges[border.index];
const auto &left_vertex = edge.left_vertex;
const auto &right_vertex = edge.right_vertex;
glm::vec2 a = left_vertex->position / m_bounds.max;
glm::vec2 b = right_vertex->position / m_bounds.max;
m_mask.draw_thick_line_relative(a, b, 1, util::CHANNEL_RED, 255);
}
}
// blur the mask a bit so we have smooth transition
m_mask.blur(1.f);
// now alter the heightmap based on the river mask
#pragma omp parallel for
for (int x = 0; x < m_heightmap.width(); x++) {
for (int y = 0; y < m_heightmap.height(); y++) {
uint8_t masker = m_mask.sample(x, y, util::CHANNEL_RED);
if (masker > 0) {
float height = m_heightmap.sample(x, y, util::CHANNEL_RED);
float erosion = glm::clamp(1.f - (masker / 255.f), 0.8f, 1.f);
m_heightmap.plot(x, y, util::CHANNEL_RED, erosion * height);
}
}
}
}
void Atlas::create_normalmap()
{
float strength = 16.f;
#pragma omp parallel for
for (int x = 0; x < m_heightmap.width(); x++) {
for (int y = 0; y < m_heightmap.height(); y++) {
const glm::vec3 normal = util::filter_normal(x, y, util::CHANNEL_RED, strength, m_heightmap);
m_normalmap.plot(x, y, util::CHANNEL_RED, normal.x);
m_normalmap.plot(x, y, util::CHANNEL_GREEN, normal.y);
m_normalmap.plot(x, y, util::CHANNEL_BLUE, normal.z);
}
}
}
void Atlas::delete_basins()
{
for (auto &basin : basins) {
delete_basin(&basin);
}
basins.clear();
}
bool walkable_tile(const Tile *tile)
{
return (tile->relief == ReliefType::LOWLAND || tile->relief == ReliefType::HILLS);
}
| 26.896992 | 104 | 0.656081 | [
"geometry",
"vector",
"transform"
] |
82677e99b03ca09cc8eb323116eb462cde22e97e | 3,491 | cc | C++ | onnxruntime/test/global_thread_pools/test_main.cc | lchang20/onnxruntime | 97b8f6f394ae02c73ed775f456fd85639c91ced1 | [
"MIT"
] | 669 | 2018-12-03T22:00:31.000Z | 2019-05-06T19:42:49.000Z | onnxruntime/test/global_thread_pools/test_main.cc | lchang20/onnxruntime | 97b8f6f394ae02c73ed775f456fd85639c91ced1 | [
"MIT"
] | 440 | 2018-12-03T21:09:56.000Z | 2019-05-06T20:47:23.000Z | onnxruntime/test/global_thread_pools/test_main.cc | lchang20/onnxruntime | 97b8f6f394ae02c73ed775f456fd85639c91ced1 | [
"MIT"
] | 140 | 2018-12-03T21:15:28.000Z | 2019-05-06T18:02:36.000Z | // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#ifndef USE_ONNXRUNTIME_DLL
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#else
#endif
#include <google/protobuf/message_lite.h>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif
#include "core/session/onnxruntime_cxx_api.h"
#include "gtest/gtest.h"
#include "test/test_environment.h"
#include <thread>
std::unique_ptr<Ort::Env> ort_env;
#define ORT_RETURN_IF_NON_NULL_STATUS(arg) \
if (arg) { \
return -1; \
}
namespace TestGlobalCustomThreadHooks {
std::vector<std::thread> threads;
int32_t custom_thread_creation_options = 5;
int32_t custom_creation_hook_called = 0;
int32_t custom_join_hook_called = 0;
OrtCustomThreadHandle CreateThreadCustomized(void* options, OrtThreadWorkerFn work_loop, void* param) {
if (*((int32_t*)options) == 5) {
custom_creation_hook_called += 1;
}
threads.push_back(std::thread(work_loop, param));
return reinterpret_cast<OrtCustomThreadHandle>(threads.back().native_handle());
}
void JoinThreadCustomized(OrtCustomThreadHandle handle) {
for (auto& t : threads) {
if (reinterpret_cast<OrtCustomThreadHandle>(t.native_handle()) == handle) {
custom_join_hook_called += 1;
t.join();
}
}
}
} // namespace TestGlobalCustomThreadHooks
using namespace TestGlobalCustomThreadHooks;
int main(int argc, char** argv) {
int status = 0;
const int thread_pool_size = std::thread::hardware_concurrency();
ORT_TRY {
::testing::InitGoogleTest(&argc, argv);
const OrtApi* g_ort = OrtGetApiBase()->GetApi(ORT_API_VERSION);
std::unique_ptr<OrtStatus, decltype(OrtApi::ReleaseStatus)> st_ptr(nullptr, g_ort->ReleaseStatus);
OrtThreadingOptions* tp_options;
st_ptr.reset(g_ort->CreateThreadingOptions(&tp_options));
ORT_RETURN_IF_NON_NULL_STATUS(st_ptr);
st_ptr.reset(g_ort->SetGlobalSpinControl(tp_options, 0));
ORT_RETURN_IF_NON_NULL_STATUS(st_ptr);
st_ptr.reset(g_ort->SetGlobalIntraOpNumThreads(tp_options, thread_pool_size));
ORT_RETURN_IF_NON_NULL_STATUS(st_ptr);
st_ptr.reset(g_ort->SetGlobalCustomCreateThreadFn(tp_options, CreateThreadCustomized));
ORT_RETURN_IF_NON_NULL_STATUS(st_ptr);
st_ptr.reset(g_ort->SetGlobalCustomThreadCreationOptions(tp_options, &custom_thread_creation_options));
ORT_RETURN_IF_NON_NULL_STATUS(st_ptr);
st_ptr.reset(g_ort->SetGlobalCustomJoinThreadFn(tp_options, JoinThreadCustomized));
ORT_RETURN_IF_NON_NULL_STATUS(st_ptr);
st_ptr.reset(g_ort->SetGlobalInterOpNumThreads(tp_options, thread_pool_size));
ORT_RETURN_IF_NON_NULL_STATUS(st_ptr);
st_ptr.reset(g_ort->SetGlobalDenormalAsZero(tp_options));
ORT_RETURN_IF_NON_NULL_STATUS(st_ptr);
ort_env.reset(new Ort::Env(tp_options, ORT_LOGGING_LEVEL_VERBOSE, "Default")); // this is the only change from test/providers/test_main.cc
g_ort->ReleaseThreadingOptions(tp_options);
status = RUN_ALL_TESTS();
}
ORT_CATCH(const std::exception& ex) {
ORT_HANDLE_EXCEPTION([&]() {
std::cerr << ex.what();
status = -1;
});
}
//TODO: Fix the C API issue
ort_env.reset(); //If we don't do this, it will crash
#ifndef USE_ONNXRUNTIME_DLL
//make memory leak checker happy
::google::protobuf::ShutdownProtobufLibrary();
#endif
return status;
}
| 31.736364 | 143 | 0.74334 | [
"vector"
] |
826e7da4763788b09ebb7eb7474c00bc2cd427e3 | 36,073 | cpp | C++ | examples/Cxx/ExampleXdmfEdit.cpp | scottwedge/xdmf | f41196c966997a20f60525a3d2083490a63626a3 | [
"BSD-3-Clause"
] | 4 | 2015-12-07T08:11:06.000Z | 2020-06-15T01:39:07.000Z | examples/Cxx/ExampleXdmfEdit.cpp | scottwedge/xdmf | f41196c966997a20f60525a3d2083490a63626a3 | [
"BSD-3-Clause"
] | 1 | 2020-04-26T16:50:37.000Z | 2020-04-26T16:50:37.000Z | examples/Cxx/ExampleXdmfEdit.cpp | scottwedge/xdmf | f41196c966997a20f60525a3d2083490a63626a3 | [
"BSD-3-Clause"
] | 4 | 2016-04-04T20:54:31.000Z | 2020-06-15T01:39:08.000Z | #include "XdmfDomain.hpp"
#include "XdmfSystemUtils.hpp"
#include "XdmfWriter.hpp"
#include "XdmfReader.hpp"
#include "XdmfHDF5Writer.hpp"
#include "XdmfInformation.hpp"
#include "XdmfAttribute.hpp"
#include "XdmfUnstructuredGrid.hpp"
#include "XdmfCurvilinearGrid.hpp"
#include "XdmfRectilinearGrid.hpp"
#include "XdmfRegularGrid.hpp"
#include "XdmfMap.hpp"
#include "XdmfGridCollection.hpp"
#include "XdmfGridCollectionType.hpp"
#include "XdmfAttributeType.hpp"
#include "XdmfAttributeCenter.hpp"
#include "XdmfSet.hpp"
#include "XdmfArray.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfTopology.hpp"
#include "string.h"
#include "XdmfTestDataGenerator.hpp"
int main(int, char **)
{
shared_ptr<XdmfReader> exampleReader = XdmfReader::New();
/*
This is assuming that the read item is an XdmfDomain object
*/
shared_ptr<XdmfDomain> primaryDomain = shared_dynamic_cast<XdmfDomain>(exampleReader->read("testoutput.xmf"));
shared_ptr<XdmfInformation> outputInformation = primaryDomain->getInformation(0);
printf("Key: %s\nValue: %s\n", outputInformation->getKey().c_str(), outputInformation->getValue().c_str());
printf("The Domain's tag is: %s\n", primaryDomain->getItemTag().c_str());
shared_ptr<XdmfGridCollection> gridHolder = primaryDomain->getGridCollection(0);
printf("The Grid Collection's tag is: %s\n", gridHolder->getItemTag().c_str());
printf("The Grid Collection's name is: %s\n", gridHolder->getName().c_str());
outputInformation = gridHolder->getInformation(0);
printf("Key: %s\nValue: %s\n", outputInformation->getKey().c_str(), outputInformation->getValue().c_str());
std::map<std::string, std::string>::iterator outputwalker = gridHolder->getItemProperties().begin();
for (;outputwalker!=gridHolder->getItemProperties().end(); outputwalker++)
{
printf("%s: %s\n", (*outputwalker).first.c_str(), (*outputwalker).second.c_str());
}
if (gridHolder->getType() == XdmfGridCollectionType::Spatial())
{
printf("This is a spatial grid collection\n");
}
else
{
printf("This is not a spatial grid collection\n");
}
//loop controlling integers
int i = 0;
int j = 0;
int k = 0;
int m = 0;
int task;
int node;
int remote;
std::string blankstring = "";
char* outstring = strdup(blankstring.c_str());
shared_ptr<XdmfMap> readMap;
std::map<int, std::map<int, std::set<int> > > taskIDMap;
std::map<int, std::map<int, std::set<int> > >::iterator taskWalker;
std::map<int, std::set<int> > nodeIDMap;
std::map<int, std::set<int> >::iterator nodeWalker;
std::set<int> remoteIDset;
std::set<int>::iterator remoteWalker;
for (i=0; i<gridHolder->getNumberMaps(); i++)
{
readMap = gridHolder->getMap(i);
if (!readMap->isInitialized())
{
readMap->read();
}
printf("Map # %d\n", i);
taskIDMap = readMap->getMap();
for (taskWalker = taskIDMap.begin(); taskWalker!= taskIDMap.end(); taskWalker++)
{
task = (*taskWalker).first;
nodeIDMap = (*taskWalker).second;
for (nodeWalker = nodeIDMap.begin(); nodeWalker != nodeIDMap.end(); nodeWalker++)
{
node = (*nodeWalker).first;
remoteIDset = (*nodeWalker).second;
for (remoteWalker = remoteIDset.begin(); remoteWalker != remoteIDset.end();remoteWalker++)
{
remote = (*remoteWalker);
printf("taskID: %d\tlocalnodeID: %d\tremotenodeID: %d\n", task, node, remote);
}
}
}
}
printf("Unstructured Grid\n");
shared_ptr<XdmfUnstructuredGrid> ungrid = gridHolder->getUnstructuredGrid(0);
printf("The Unstructured Grid's tag is: %s\n", ungrid->getItemTag().c_str());
printf("The Unstructured Grid's name is: %s\n", ungrid->getName().c_str());
outputwalker = ungrid->getItemProperties().begin();
for (;outputwalker!=ungrid->getItemProperties().end(); outputwalker++)
{
printf("%s: %s\n", (*outputwalker).first.c_str(), (*outputwalker).second.c_str());
}
printf("The Unstructured Grid's time is: %f\n", ungrid->getTime()->getValue());
i=0;
for (i=0; i<ungrid->getNumberMaps(); i++)
{
readMap = ungrid->getMap(i);
if (!readMap->isInitialized())
{
readMap->read();
}
printf("Map # %d\n", i);
taskIDMap = readMap->getMap();
for (taskWalker = taskIDMap.begin(); taskWalker!= taskIDMap.end(); taskWalker++)
{
task = (*taskWalker).first;
nodeIDMap = (*taskWalker).second;
for (nodeWalker = nodeIDMap.begin(); nodeWalker != nodeIDMap.end(); nodeWalker++)
{
node = (*nodeWalker).first;
remoteIDset = (*nodeWalker).second;
for (remoteWalker = remoteIDset.begin(); remoteWalker != remoteIDset.end();remoteWalker++)
{
remote = (*remoteWalker);
printf("taskID: %d\tlocalnodeID: %d\tremotenodeID: %d\n", task, node, remote);
}
}
}
}
shared_ptr<XdmfSet> readSet;
shared_ptr<XdmfAttribute> readAttribute;
for (i=0; i < ungrid->getNumberSets(); i++)
{
readSet = ungrid->getSet(i);
if (!readSet->isInitialized())
{
readSet->read();
}
printf("Set # %d\n", i);
printf("%s\n", readSet->getName().c_str());
if (readSet->getType() == XdmfSetType::Node())
{
printf("This set is a node\n");
}
else
{
printf("This set is not a node\n");
}
outputInformation = readSet->getInformation(0);
printf("Key: %s\nValue: %s\n", outputInformation->getKey().c_str(), outputInformation->getValue().c_str());
printf("%s\n", readSet->getValuesString().c_str());
for (j=0; j < readSet->getNumberAttributes(); j++)
{
readAttribute = readSet->getAttribute(j);
if (!readAttribute->isInitialized())
{
readAttribute->read();
}
printf("Set Attribute # %d\n", j);
printf("%s\n", readAttribute->getName().c_str());
if (readAttribute->getType() == XdmfAttributeType::Scalar())
{
printf("This attribute is a scalar\n");
}
else
{
printf("This attribute is not a scalar\n");
}
if (readAttribute->getCenter() == XdmfAttributeCenter::Node())
{
printf("This attribute is a node\n");
}
else
{
printf("This attribute is not a node\n");
}
printf("%s\n", readAttribute->getValuesString().c_str());
}
}
for (i = 0; i < ungrid->getNumberAttributes(); i++)
{
readAttribute = ungrid->getAttribute(i);
if (!readAttribute->isInitialized())
{
readAttribute->read();
}
printf("Attribute # %d\n", i);
printf("%s\n", readAttribute->getName().c_str());
if (readAttribute->getType() == XdmfAttributeType::Scalar())
{
printf("This attribute is a scalar\n");
}
else
{
printf("This attribute is not a scalar\n");
}
if (readAttribute->getCenter() == XdmfAttributeCenter::Node())
{
printf("This attribute is a node\n");
}
else
{
printf("This attribute is not a node\n");
}
printf("%s\n", readAttribute->getValuesString().c_str());
}
printf("Unstructured Topology\n");
shared_ptr<XdmfTopology> untopology = ungrid->getTopology();
if (!untopology->isInitialized())
{
untopology->read();
}
printf("The topology's tag: %s\n", untopology->getItemTag().c_str());
if (untopology->getType() == XdmfTopologyType::Hexahedron())
{
printf("This topology is a hexahedron\n");
}
else
{
printf("This topology is not a hexahedron\n");
}
printf("Contains %d elements\n", untopology->getNumberElements());
printf("Contains the values: %s\n", untopology->getValuesString().c_str());
printf("Unstructured Geometry\n");
shared_ptr<XdmfGeometry> ungeometry = ungrid->getGeometry();
if (!ungeometry->isInitialized())
{
ungeometry->read();
}
printf("The geometry's tag: %s\n", ungeometry->getItemTag().c_str());
if (ungeometry->getType() == XdmfGeometryType::XYZ())
{
printf("This geometry is XYZ\n");
}
else
{
printf("This geometry is not XYZ\n");
}
outputInformation = ungeometry->getInformation(0);
printf("Key: %s\nValue: %s\n", outputInformation->getKey().c_str(), outputInformation->getValue().c_str());
printf("Contains %d points\n", ungeometry->getNumberPoints());
printf("Contains the values: %s\n", ungeometry->getValuesString().c_str());
printf("Curvilinear Grid\n");
shared_ptr<XdmfCurvilinearGrid> curvgrid = gridHolder->getCurvilinearGrid(0);
printf("The Curvilinear Grid's tag is: %s\n", curvgrid->getItemTag().c_str());
printf("The Curvilinear Grid's name is: %s\n", curvgrid->getName().c_str());
outputwalker = curvgrid->getItemProperties().begin();
for (;outputwalker!=curvgrid->getItemProperties().end(); outputwalker++)
{
printf("%s: %s\n", (*outputwalker).first.c_str(), (*outputwalker).second.c_str());
}
outputInformation = curvgrid->getInformation(0);
printf("Key: %s\nValue: %s\n", outputInformation->getKey().c_str(), outputInformation->getValue().c_str());
printf("The Curvilinear Grid's time is: %f\n", curvgrid->getTime()->getValue());
for (i=0; i<curvgrid->getNumberMaps(); i++)
{
readMap = curvgrid->getMap(i);
if (!readMap->isInitialized())
{
readMap->read();
}
printf("Map # %d\n", i);
taskIDMap = readMap->getMap();
for (taskWalker = taskIDMap.begin(); taskWalker!= taskIDMap.end(); taskWalker++)
{
task = (*taskWalker).first;
nodeIDMap = (*taskWalker).second;
for (nodeWalker = nodeIDMap.begin(); nodeWalker != nodeIDMap.end(); nodeWalker++)
{
node = (*nodeWalker).first;
remoteIDset = (*nodeWalker).second;
for (remoteWalker = remoteIDset.begin(); remoteWalker != remoteIDset.end();remoteWalker++)
{
remote = (*remoteWalker);
printf("taskID: %d\tlocalnodeID: %d\tremotenodeID: %d\n", task, node, remote);
}
}
}
}
for (i=0; i < curvgrid->getNumberSets(); i++)
{
readSet = curvgrid->getSet(i);
if (!readSet->isInitialized());
{
readSet->read();
}
printf("Set # %d\n", i);
printf("%s\n", readSet->getName().c_str());
if (readSet->getType() == XdmfSetType::Node())
{
printf("This set is a node\n");
}
else
{
printf("This set is not a node\n");
}
outputInformation = readSet->getInformation(0);
printf("Key: %s\nValue: %s\n", outputInformation->getKey().c_str(), outputInformation->getValue().c_str());
printf("%s\n", readSet->getValuesString().c_str());
for (j=0; j < readSet->getNumberAttributes(); j++)
{
readAttribute = readSet->getAttribute(j);
if (!readAttribute->isInitialized())
{
readAttribute->read();
}
printf("Set Attribute # %d\n", j);
printf("%s\n", readAttribute->getName().c_str());
if (readAttribute->getType() == XdmfAttributeType::Scalar())
{
printf("This attribute is a scalar\n");
}
else
{
printf("This attribute is not a scalar\n");
}
if (readAttribute->getCenter() == XdmfAttributeCenter::Node())
{
printf("This attribute is a node\n");
}
else
{
printf("This attribute is not a node\n");
}
printf("%s\n", readAttribute->getValuesString().c_str());
}
}
for (i = 0; i < curvgrid->getNumberAttributes(); i++)
{
readAttribute = curvgrid->getAttribute(i);
if (!readAttribute->isInitialized())
{
readAttribute->read();
}
printf("Attribute # %d\n", i);
printf("%s\n", readAttribute->getName().c_str());
if (readAttribute->getType() == XdmfAttributeType::Scalar())
{
printf("This attribute is a scalar\n");
}
else
{
printf("This attribute is not a scalar\n");
}
if (readAttribute->getCenter() == XdmfAttributeCenter::Node())
{
printf("This attribute is a node\n");
}
else
{
printf("This attribute is not a node\n");
}
printf("%s\n", readAttribute->getValuesString().c_str());
}
printf("Curvilinear Dimensions\n");
shared_ptr<XdmfArray> curvdimensions = curvgrid->getDimensions();
if (!curvdimensions->isInitialized())
{
curvdimensions->read();
}
printf("The dimensions' tag: %s\n", curvdimensions->getItemTag().c_str());
printf("Contains the values: %s\n", curvdimensions->getValuesString().c_str());
printf("Curvilinear Geometry\n");
shared_ptr<XdmfGeometry> curvgeometry = curvgrid->getGeometry();
if (!curvgeometry->isInitialized())
{
curvgeometry->read();
}
printf("The geometry's tag: %s\n", curvgeometry->getItemTag().c_str());
if (curvgeometry->getType() == XdmfGeometryType::XYZ())
{
printf("This geometry is XYZ\n");
}
else
{
printf("This geometry is not XYZ\n");
}
outputInformation = curvgeometry->getInformation(0);
printf("Key: %s\nValue: %s\n", outputInformation->getKey().c_str(), outputInformation->getValue().c_str());
printf("Contains %d points\n", curvgeometry->getNumberPoints());
printf("Contains the values: %s\n", curvgeometry->getValuesString().c_str());
printf("Rectilinear Grid\n");
shared_ptr<XdmfRectilinearGrid> rectgrid = gridHolder->getRectilinearGrid(0);
printf("The Rectilinear Grid's tag is: %s\n", rectgrid->getItemTag().c_str());
printf("The Rectilinear Grid's name is: %s\n", rectgrid->getName().c_str());
printf("The Rectilinear Grid's time is: %f\n", rectgrid->getTime()->getValue());
outputwalker = rectgrid->getItemProperties().begin();
for (; outputwalker!=rectgrid->getItemProperties().end(); outputwalker++)
{
printf("%s: %s\n", (*outputwalker).first.c_str(), (*outputwalker).second.c_str());
}
for (i=0; i<rectgrid->getNumberMaps(); i++)
{
readMap = rectgrid->getMap(i);
if (!readMap->isInitialized())
{
readMap->read();
}
printf("Map # %d\n", i);
taskIDMap = readMap->getMap();
for (taskWalker = taskIDMap.begin(); taskWalker!= taskIDMap.end(); taskWalker++)
{
task = (*taskWalker).first;
nodeIDMap = (*taskWalker).second;
for (nodeWalker = nodeIDMap.begin(); nodeWalker != nodeIDMap.end(); nodeWalker++)
{
node = (*nodeWalker).first;
remoteIDset = (*nodeWalker).second;
for (remoteWalker = remoteIDset.begin(); remoteWalker != remoteIDset.end();remoteWalker++)
{
remote = (*remoteWalker);
printf("taskID: %d\tlocalnodeID: %d\tremotenodeID: %d\n", task, node, remote);
}
}
}
}
for (i=0; i < rectgrid->getNumberSets(); i++)
{
readSet = rectgrid->getSet(i);
if (!readSet->isInitialized())
{
readSet->read();
}
printf("Set # %d\n", i);
printf("%s\n", readSet->getName().c_str());
if (readSet->getType() == XdmfSetType::Node())
{
printf("This set is a node\n");
}
else
{
printf("This set is not a node\n");
}
outputInformation = readSet->getInformation(0);
printf("Key: %s\nValue: %s\n", outputInformation->getKey().c_str(), outputInformation->getValue().c_str());
printf("%s\n", readSet->getValuesString().c_str());
for (j=0; j < readSet->getNumberAttributes(); j++)
{
readAttribute = readSet->getAttribute(j);
if (!readAttribute->isInitialized())
{
readAttribute->read();
}
printf("Set Attribute # %d\n", j);
printf("%s\n", readAttribute->getName().c_str());
if (readAttribute->getType() == XdmfAttributeType::Scalar())
{
printf("This attribute is a scalar\n");
}
else
{
printf("This attribute is not a scalar\n");
}
if (readAttribute->getCenter() == XdmfAttributeCenter::Node())
{
printf("This attribute is a node\n");
}
else
{
printf("This attribute is not a node\n");
}
printf("%s\n", readAttribute->getValuesString().c_str());
}
}
for (i = 0; i < rectgrid->getNumberAttributes(); i++)
{
readAttribute = rectgrid->getAttribute(i);
if (!readAttribute->isInitialized())
{
readAttribute->read();
}
printf("Attribute # %d\n", i);
printf("%s\n", readAttribute->getName().c_str());
if (readAttribute->getType() == XdmfAttributeType::Scalar())
{
printf("This attribute is a scalar\n");
}
else
{
printf("This attribute is not a scalar\n");
}
if (readAttribute->getCenter() == XdmfAttributeCenter::Node())
{
printf("This attribute is a node\n");
}
else
{
printf("This attribute is not a node\n");
}
printf("%s\n", readAttribute->getValuesString().c_str());
}
printf("Rectilinear Dimensions\n");
shared_ptr<XdmfArray> rectdimensions = rectgrid->getDimensions();
if (!rectdimensions->isInitialized())
{
rectdimensions->read();
}
printf("The dimensions' tag: %s\n", rectdimensions->getItemTag().c_str());
printf("Contains the values: %s\n", rectdimensions->getValuesString().c_str());
printf("Rectilinear Coordinates\n");
std::vector<shared_ptr<XdmfArray> > rectcoordinates = rectgrid->getCoordinates();
printf("Contains the values: \n");
for (i=0;i<rectcoordinates.size();i++)
{
if (!rectcoordinates[i]->isInitialized())
{
rectcoordinates[i]->read();
}
printf("%s\n", rectcoordinates[i]->getValuesString().c_str());
}
printf("Regular Grid\n");
shared_ptr<XdmfRegularGrid> reggrid = gridHolder->getRegularGrid(0);
printf("The Regular Grid's tag is: %s\n", reggrid->getItemTag().c_str());
printf("The Regular Grid's name is: %s\n", reggrid->getName().c_str());
outputwalker = reggrid->getItemProperties().begin();
for (;outputwalker!=reggrid->getItemProperties().end(); outputwalker++)
{
printf("%s: %s\n", (*outputwalker).first.c_str(), (*outputwalker).second.c_str());
}
printf("The Regular Grid's time is: %f\n", reggrid->getTime()->getValue());
for (i=0; i<reggrid->getNumberMaps(); i++)
{
readMap = reggrid->getMap(i);
if (!readMap->isInitialized())
{
readMap->read();
}
printf("Map # %d\n", i);
taskIDMap = readMap->getMap();
for (taskWalker = taskIDMap.begin(); taskWalker!= taskIDMap.end(); taskWalker++)
{
task = (*taskWalker).first;
nodeIDMap = (*taskWalker).second;
for (nodeWalker = nodeIDMap.begin(); nodeWalker != nodeIDMap.end(); nodeWalker++)
{
node = (*nodeWalker).first;
remoteIDset = (*nodeWalker).second;
for (remoteWalker = remoteIDset.begin(); remoteWalker != remoteIDset.end();remoteWalker++)
{
remote = (*remoteWalker);
printf("taskID: %d\tlocalnodeID: %d\tremotenodeID: %d\n", task, node, remote);
}
}
}
}
for (i=0; i < reggrid->getNumberSets(); i++)
{
readSet = reggrid->getSet(i);
if (!readSet->isInitialized())
{
readSet->read();
}
printf("Set # %d\n", i);
printf("%s\n", readSet->getName().c_str());
if (readSet->getType() == XdmfSetType::Node())
{
printf("This set is a node");
}
else
{
printf("This set is not a node");
}
outputInformation = readSet->getInformation(0);
printf("Key: %s\nValue: %s\n", outputInformation->getKey().c_str(), outputInformation->getValue().c_str());
printf("%s\n", readSet->getValuesString().c_str());
for (j=0; j < readSet->getNumberAttributes(); j++)
{
readAttribute = readSet->getAttribute(j);
if (!readAttribute->isInitialized())
{
readAttribute->read();
}
printf("Set Attribute # %d\n", j);
printf("%s\n", readAttribute->getName().c_str());
if (readAttribute->getType() == XdmfAttributeType::Scalar())
{
printf("This attribute is a scalar");
}
else
{
printf("This attribute is not a scalar");
}
if (readAttribute->getCenter() == XdmfAttributeCenter::Node())
{
printf("This attribute is a node");
}
else
{
printf("This attribute is not a node");
}
printf("%s\n", readAttribute->getValuesString().c_str());
}
}
for (i = 0; i < reggrid->getNumberAttributes(); i++)
{
readAttribute = reggrid->getAttribute(i);
if (!readAttribute->isInitialized())
{
readAttribute->read();
}
printf("Attribute # %d\n", i);
printf("%s\n", readAttribute->getName().c_str());
if (readAttribute->getType() == XdmfAttributeType::Scalar())
{
printf("This attribute is a scalar\n");
}
else
{
printf("This attribute is not a scalar\n");
}
if (readAttribute->getCenter() == XdmfAttributeCenter::Node())
{
printf("This attribute is a node\n");
}
else
{
printf("This attribute is not a node\n");
}
printf("%s\n", readAttribute->getValuesString().c_str());
}
printf("Regular Brick Size\n");
shared_ptr<XdmfArray> regbricksize = reggrid->getBrickSize();
if (!regbricksize->isInitialized())
{
regbricksize->read();
}
printf("The brick's tag: %s\n", regbricksize->getItemTag().c_str());
printf("Contains the values: %s\n", regbricksize->getValuesString().c_str());
printf("Regular Number of Points\n");
shared_ptr<XdmfArray> regnumpoints = reggrid->getDimensions();
if (!regnumpoints->isInitialized())
{
regnumpoints->read();
}
printf("The dimensions' tag: %s\n", regnumpoints->getItemTag().c_str());
printf("Contains the values: %s\n", regnumpoints->getValuesString().c_str());
printf("Regular Origin\n");
shared_ptr<XdmfArray> regorigin = reggrid->getOrigin();
if (!regorigin->isInitialized())
{
regorigin->read();
}
printf("The origin's tag: %s\n", regorigin->getItemTag().c_str());
printf("Contains the values: %s\n", regorigin->getValuesString().c_str());
primaryDomain->getInformation(0)->setKey("Edited");
primaryDomain->getInformation(0)->setValue("This file is the edited version");
printf("edited domain information\n");
shared_ptr<XdmfAttribute> unglobalIDs = ungrid->getAttribute(0);
int newIDs1 [] = {5,2,8,7,9,1};
unglobalIDs->insert(0, newIDs1, 6, 1, 1);
printf("edited unstructured attribute: %s\n", unglobalIDs->getValuesString());
shared_ptr<XdmfSet> unset = ungrid->getSet(0);
double newunsetdata [] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 0.23};
unset->insert(0, newunsetdata, 10, 1, 1);
printf("edited unstructured set: %s\n", unset->getValuesString());
untopology = ungrid->getTopology();
int untoposize = untopology->getSize();
int untopologydata [untoposize];
untopology->getValues(0, untopologydata, untopology->getSize(), 1, 1);
for (i=0; i < untopology->getSize(); i++)
{
untopologydata[i] = untopologydata[i] + 1;
}
untopology->insert(0, untopologydata, untopology->getSize(), 1, 1);
printf("edited unstructured topology: %s\n", untopology->getValuesString());
ungeometry = ungrid->getGeometry();
int ungeosize = ungeometry->getSize();
double ungeometrydata [ungeosize];
ungeometry->getValues(0, ungeometrydata, ungeometry->getSize(), 1, 1);
for (i=0; i<ungeometry->getSize();i++)
{
ungeometrydata[i] = ungeometrydata[i] + 1;
}
ungeometry->insert(0, ungeometrydata, ungeometry->getSize(), 1, 1);
shared_ptr<XdmfAttribute> curvglobalIDs = curvgrid->getAttribute(0);
int newIDs2 [] = {3, 6, 2, 8, 1, 7, 5};
curvglobalIDs->insert(0, newIDs2, 7, 1, 1);
curvgeometry = curvgrid->getGeometry();
int curvgeosize = curvgeometry->getSize();
double curvgeometrydata [curvgeosize];
curvgeometry->getValues(0, curvgeometrydata, curvgeometry->getSize(), 1, 1);
for (i = 0; i<curvgeometry->getSize(); i++)
{
curvgeometrydata[i] = curvgeometrydata[i] + 1;
}
curvgeometry->insert(0, curvgeometrydata, curvgeometry->getSize(), 1, 1);
for (i = 0; i < 3; i++)
{
curvgeometry->pushBack(curvgeometry->getSize());
}
curvdimensions = curvgrid->getDimensions();
int curvdimensionsize = curvdimensions->getSize();
int curvdimensiondata [curvdimensionsize];
curvdimensions->getValues(0, curvdimensiondata, curvdimensions->getSize(), 1, 1);
for (i = 0; i< curvdimensions->getSize(); i++)
{
curvdimensiondata[i] = curvdimensiondata[i] + 1;
}
curvdimensions->insert(0, curvdimensiondata, curvdimensions->getSize(), 1, 1);
shared_ptr<XdmfAttribute> rectglobalIDs = rectgrid->getAttribute(0);
int newIDs3 [] = {6, 4, 3, 7, 9, 8};
rectglobalIDs->insert(0, newIDs3, 6, 1, 1);
rectdimensions = rectgrid->getDimensions();
int rectdimensionsize = rectdimensions->getSize();
int rectdimensiondata [rectdimensionsize];
rectdimensions->getValues(0, rectdimensiondata, rectdimensions->getSize(), 1, 1);
for (i = 0; i < rectdimensions->getSize(); i++)
{
rectdimensiondata[i] = rectdimensiondata[i] + 1;
}
rectdimensions->insert(0, rectdimensiondata, rectdimensions->getSize(), 1, 1);
std::vector<shared_ptr<XdmfArray> > rectcoordinatevector = rectgrid->getCoordinates();
shared_ptr<XdmfArray> coordinateaxis;
for (i=0;i<rectcoordinatevector.size(); i++)
{
coordinateaxis = rectcoordinatevector[i];
int coordinatesize = coordinateaxis->getSize();
int coordinatedata [coordinatesize];
coordinateaxis->getValues(0, coordinatedata, coordinateaxis->getSize(), 1, 1);
for (j = 0; j < coordinateaxis->getSize(); j++)
{
coordinatedata[i] = coordinatedata[i] + 1;
}
coordinateaxis->insert(0, coordinatedata, coordinateaxis->getSize(), 1, 1);
coordinateaxis->pushBack(coordinateaxis->getSize());
rectcoordinatevector[i] = coordinateaxis;
}
rectgrid->setCoordinates(rectcoordinatevector);
shared_ptr<XdmfAttribute> regglobalIDs = reggrid->getAttribute(0);
int newIDs4 [] = {3, 5, 1, 2, 4, 8, 0};
regglobalIDs->insert(0, newIDs4, 7, 1, 1);
regbricksize = reggrid->getBrickSize();
int regbrickdatasize = regbricksize->getSize();
double brickdata [regbrickdatasize];
regbricksize->getValues(0, brickdata, regbricksize->getSize(), 1, 1);
for (i = 0; i < regbricksize->getSize(); i++)
{
brickdata[i] = brickdata[i] + 1;
}
regbricksize->insert(0, brickdata, regbricksize->getSize(), 1, 1);
reggrid->setBrickSize(regbricksize);
shared_ptr<XdmfArray> regdimensions = reggrid->getDimensions();
int regdimensionssize = regdimensions->getSize();
int regdimensiondata [regdimensionssize];
regdimensions->getValues(0, regdimensiondata, regdimensions->getSize(), 1, 1);
for (i = 0; i < regdimensions->getSize(); i++)
{
regdimensiondata[i] = regdimensiondata[i] + 1;
}
regdimensions->insert(0, regdimensiondata, regdimensions->getSize(), 1, 1);
reggrid->setDimensions(regdimensions);
regorigin = reggrid->getOrigin();
int regoriginsize = regorigin->getSize();
double regorigindata [regoriginsize];
regorigin->getValues(0, regorigindata, regorigin->getSize(), 1, 1);
for (i = 0; i < regorigin->getSize(); i++)
{
regorigindata[i] = regorigindata[i] + 1;
}
regorigin->insert(0, regorigindata, regorigin->getSize(), 1, 1);
reggrid->setOrigin(regorigin);
shared_ptr<XdmfHDF5Writer> exampleHeavyWriter = XdmfHDF5Writer::New("editedtestoutput.h5");
shared_ptr<XdmfWriter> exampleWriter = XdmfWriter::New("editedtestoutput.xmf", exampleHeavyWriter);
//exampleHeavyWriter->setFileSizeLimit(1);
primaryDomain->accept(exampleHeavyWriter);
exampleHeavyWriter->setMode(XdmfHeavyDataWriter::Overwrite);
primaryDomain->accept(exampleWriter);
return 0;
}
| 43.619105 | 123 | 0.483076 | [
"geometry",
"object",
"vector"
] |
826e8d575b731a2794bd71af897b90497468f11b | 4,617 | hxx | C++ | Modules/ThirdParty/VNL/src/vxl/core/vnl/io/vnl_io_sparse_matrix.hxx | floryst/ITK | 321e673bcbac15aae2fcad863fd0977b7fbdb3e9 | [
"Apache-2.0"
] | 945 | 2015-01-09T00:43:52.000Z | 2022-03-30T08:23:02.000Z | Modules/ThirdParty/VNL/src/vxl/core/vnl/io/vnl_io_sparse_matrix.hxx | floryst/ITK | 321e673bcbac15aae2fcad863fd0977b7fbdb3e9 | [
"Apache-2.0"
] | 2,354 | 2015-02-04T21:54:21.000Z | 2022-03-31T20:58:21.000Z | Modules/ThirdParty/VNL/src/vxl/core/vnl/io/vnl_io_sparse_matrix.hxx | floryst/ITK | 321e673bcbac15aae2fcad863fd0977b7fbdb3e9 | [
"Apache-2.0"
] | 566 | 2015-01-04T14:26:57.000Z | 2022-03-18T20:33:18.000Z | // This is core/vnl/io/vnl_io_sparse_matrix.hxx
#ifndef vnl_io_sparse_matrix_hxx_
#define vnl_io_sparse_matrix_hxx_
//:
// \file
#include <iostream>
#include "vnl_io_sparse_matrix.h"
#include <vnl/vnl_sparse_matrix.h>
#include <vsl/vsl_binary_io.h>
#include <cassert>
#ifdef _MSC_VER
# include <vcl_msvc_warnings.h>
#endif
// I/O for vnl_sparse_matrix_pair
//==================================================================================
// IO Helper functions
//==================================================================================
//=================================================================================
//: Binary save self to stream.
template<class T>
void vsl_b_write(vsl_b_ostream &os, const vnl_sparse_matrix_pair<T> & p)
{
constexpr short io_version_no = 1;
vsl_b_write(os, io_version_no);
vsl_b_write(os, p.first);
vsl_b_write(os, p.second);
}
//=================================================================================
//: Binary load self from stream.
template<class T>
void vsl_b_read(vsl_b_istream &is, vnl_sparse_matrix_pair<T> & p)
{
if (!is) return;
short ver;
vsl_b_read(is, ver);
switch (ver)
{
case 1:
vsl_b_read(is, p.first);
vsl_b_read(is, p.second);
break;
default:
std::cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vnl_sparse_matrix_pair<T>&)\n"
<< " Unknown version number "<< ver << '\n';
is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
return;
}
}
//================================================================================
//: Output a human readable summary to the stream
template<class T>
void vsl_print_summary(std::ostream& os,const vnl_sparse_matrix_pair<T>& p)
{
os<< "Sparse matrix pair ( " << p.first << ',' << p.second << " )\n";
}
// I/O for vnl_sparse_matrix
//=================================================================================
//: Binary save self to stream.
template<class T>
void vsl_b_write(vsl_b_ostream & os, const vnl_sparse_matrix<T> & p)
{
typedef vnl_sparse_matrix_pair<T> pair_t;
typedef std::vector < pair_t > row;
row rw;
vnl_sparse_matrix<T> v=p;
constexpr short io_version_no = 1;
vsl_b_write(os, io_version_no);
vsl_b_write(os, v.rows());
vsl_b_write(os, v.columns());
for (unsigned int i=0;i<v.rows();i++)
{
rw=v.get_row(i);
vsl_b_write(os, rw.size());
for (unsigned int j=0;j<rw.size();j++)
{
vsl_b_write(os, rw[j]);
}
}
}
//=================================================================================
//: Binary load self from stream.
template<class T>
void vsl_b_read(vsl_b_istream &is, vnl_sparse_matrix<T> & p)
{
if (!is) return;
typedef vnl_sparse_matrix_pair<T> pair_t;
short ver;
unsigned n_rows;
unsigned n_cols;
unsigned row_size=0;
vsl_b_read(is, ver);
std::vector<int> indexes(row_size);
std::vector<T> values(row_size);
switch (ver)
{
case 1:
vsl_b_read(is, n_rows);
vsl_b_read(is, n_cols);
// As we cannot resize the matrix, check that it is the correct size.
assert (n_rows==p.rows());
assert (n_cols==p.columns());
for (unsigned i=0;i<n_rows;++i)
{
vsl_b_read(is,row_size);
indexes.resize(row_size);
values.resize(row_size);
for (unsigned j=0;j<row_size;j++)
{
pair_t q;
vsl_b_read(is, q);
indexes[j] = q.first;
values[j] = q.second;
}
p.set_row(i, indexes, values);
}
break;
default:
std::cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&, vnl_sparse_matrix<T>&)\n"
<< " Unknown version number "<< ver << '\n';
is.is().clear(std::ios::badbit); // Set an unrecoverable IO error on stream
return;
}
}
//====================================================================================
//: Output a human readable summary to the stream
template<class T>
void vsl_print_summary(std::ostream & os,const vnl_sparse_matrix<T> & p)
{
os<<"Rows x Columns: "<<p.rows()<<" x "<<p.columns()<<std::endl;
vnl_sparse_matrix<T> v=p;
v.reset();
v.next();
for (int i=0;i<5;i++)
{
os<<" ("<< v.getrow() <<','<< v.getcolumn() <<") value "<< v.value()<<'\n';
if (!v.next()) break;
}
}
#define VNL_IO_SPARSE_MATRIX_INSTANTIATE(T) \
template VNL_EXPORT void vsl_print_summary(std::ostream &, const vnl_sparse_matrix<T > &); \
template VNL_EXPORT void vsl_b_read(vsl_b_istream &, vnl_sparse_matrix<T > &); \
template VNL_EXPORT void vsl_b_write(vsl_b_ostream &, const vnl_sparse_matrix<T > &)
#endif // vnl_io_sparse_matrix_hxx_
| 27.981818 | 94 | 0.556422 | [
"vector"
] |
82704dce78ea26779ebb5f036f59a4f66a67f978 | 190,440 | cc | C++ | protobuf/src/google/protobuf/util/json_format.pb.cc | wissunpower/WeizenbierGame | 34f027c43055dfa6b05e62ca0b6c31271af013f3 | [
"Unlicense"
] | null | null | null | protobuf/src/google/protobuf/util/json_format.pb.cc | wissunpower/WeizenbierGame | 34f027c43055dfa6b05e62ca0b6c31271af013f3 | [
"Unlicense"
] | null | null | null | protobuf/src/google/protobuf/util/json_format.pb.cc | wissunpower/WeizenbierGame | 34f027c43055dfa6b05e62ca0b6c31271af013f3 | [
"Unlicense"
] | null | null | null | // Generated by the protocol buffer compiler. DO NOT EDIT!
// source: google/protobuf/util/json_format.proto
#include "google/protobuf/util/json_format.pb.h"
#include <algorithm>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
// @@protoc_insertion_point(includes)
#include <google/protobuf/port_def.inc>
PROTOBUF_PRAGMA_INIT_SEG
namespace protobuf_unittest {
constexpr TestFlagsAndStrings_RepeatedGroup::TestFlagsAndStrings_RepeatedGroup(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: f_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string){}
struct TestFlagsAndStrings_RepeatedGroupDefaultTypeInternal {
constexpr TestFlagsAndStrings_RepeatedGroupDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestFlagsAndStrings_RepeatedGroupDefaultTypeInternal() {}
union {
TestFlagsAndStrings_RepeatedGroup _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestFlagsAndStrings_RepeatedGroupDefaultTypeInternal _TestFlagsAndStrings_RepeatedGroup_default_instance_;
constexpr TestFlagsAndStrings::TestFlagsAndStrings(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: repeatedgroup_()
, a_(0){}
struct TestFlagsAndStringsDefaultTypeInternal {
constexpr TestFlagsAndStringsDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestFlagsAndStringsDefaultTypeInternal() {}
union {
TestFlagsAndStrings _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestFlagsAndStringsDefaultTypeInternal _TestFlagsAndStrings_default_instance_;
constexpr TestBase64ByteArrays::TestBase64ByteArrays(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: a_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string){}
struct TestBase64ByteArraysDefaultTypeInternal {
constexpr TestBase64ByteArraysDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestBase64ByteArraysDefaultTypeInternal() {}
union {
TestBase64ByteArrays _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestBase64ByteArraysDefaultTypeInternal _TestBase64ByteArrays_default_instance_;
constexpr TestJavaScriptJSON::TestJavaScriptJSON(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: in_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string)
, var_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string)
, a_(0)
, final_(0){}
struct TestJavaScriptJSONDefaultTypeInternal {
constexpr TestJavaScriptJSONDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestJavaScriptJSONDefaultTypeInternal() {}
union {
TestJavaScriptJSON _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestJavaScriptJSONDefaultTypeInternal _TestJavaScriptJSON_default_instance_;
constexpr TestJavaScriptOrderJSON1::TestJavaScriptOrderJSON1(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: d_(0)
, c_(0)
, x_(false)
, b_(0)
, a_(0){}
struct TestJavaScriptOrderJSON1DefaultTypeInternal {
constexpr TestJavaScriptOrderJSON1DefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestJavaScriptOrderJSON1DefaultTypeInternal() {}
union {
TestJavaScriptOrderJSON1 _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestJavaScriptOrderJSON1DefaultTypeInternal _TestJavaScriptOrderJSON1_default_instance_;
constexpr TestJavaScriptOrderJSON2::TestJavaScriptOrderJSON2(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: z_()
, d_(0)
, c_(0)
, x_(false)
, b_(0)
, a_(0){}
struct TestJavaScriptOrderJSON2DefaultTypeInternal {
constexpr TestJavaScriptOrderJSON2DefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestJavaScriptOrderJSON2DefaultTypeInternal() {}
union {
TestJavaScriptOrderJSON2 _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestJavaScriptOrderJSON2DefaultTypeInternal _TestJavaScriptOrderJSON2_default_instance_;
constexpr TestLargeInt::TestLargeInt(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: a_(int64_t{0})
, b_(uint64_t{0u}){}
struct TestLargeIntDefaultTypeInternal {
constexpr TestLargeIntDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestLargeIntDefaultTypeInternal() {}
union {
TestLargeInt _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestLargeIntDefaultTypeInternal _TestLargeInt_default_instance_;
constexpr TestNumbers::TestNumbers(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: a_(0)
, b_(0)
, c_(0)
, d_(false)
, e_(0)
, f_(0u){}
struct TestNumbersDefaultTypeInternal {
constexpr TestNumbersDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestNumbersDefaultTypeInternal() {}
union {
TestNumbers _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestNumbersDefaultTypeInternal _TestNumbers_default_instance_;
constexpr TestCamelCase::TestCamelCase(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: normal_field_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string)
, capital_field_(0)
, camelcasefield_(0){}
struct TestCamelCaseDefaultTypeInternal {
constexpr TestCamelCaseDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestCamelCaseDefaultTypeInternal() {}
union {
TestCamelCase _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestCamelCaseDefaultTypeInternal _TestCamelCase_default_instance_;
constexpr TestBoolMap_BoolMapEntry_DoNotUse::TestBoolMap_BoolMapEntry_DoNotUse(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized){}
struct TestBoolMap_BoolMapEntry_DoNotUseDefaultTypeInternal {
constexpr TestBoolMap_BoolMapEntry_DoNotUseDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestBoolMap_BoolMapEntry_DoNotUseDefaultTypeInternal() {}
union {
TestBoolMap_BoolMapEntry_DoNotUse _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestBoolMap_BoolMapEntry_DoNotUseDefaultTypeInternal _TestBoolMap_BoolMapEntry_DoNotUse_default_instance_;
constexpr TestBoolMap::TestBoolMap(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: bool_map_(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}){}
struct TestBoolMapDefaultTypeInternal {
constexpr TestBoolMapDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestBoolMapDefaultTypeInternal() {}
union {
TestBoolMap _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestBoolMapDefaultTypeInternal _TestBoolMap_default_instance_;
constexpr TestRecursion::TestRecursion(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: child_(nullptr)
, value_(0){}
struct TestRecursionDefaultTypeInternal {
constexpr TestRecursionDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestRecursionDefaultTypeInternal() {}
union {
TestRecursion _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestRecursionDefaultTypeInternal _TestRecursion_default_instance_;
constexpr TestStringMap_StringMapEntry_DoNotUse::TestStringMap_StringMapEntry_DoNotUse(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized){}
struct TestStringMap_StringMapEntry_DoNotUseDefaultTypeInternal {
constexpr TestStringMap_StringMapEntry_DoNotUseDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestStringMap_StringMapEntry_DoNotUseDefaultTypeInternal() {}
union {
TestStringMap_StringMapEntry_DoNotUse _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestStringMap_StringMapEntry_DoNotUseDefaultTypeInternal _TestStringMap_StringMapEntry_DoNotUse_default_instance_;
constexpr TestStringMap::TestStringMap(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: string_map_(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}){}
struct TestStringMapDefaultTypeInternal {
constexpr TestStringMapDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestStringMapDefaultTypeInternal() {}
union {
TestStringMap _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestStringMapDefaultTypeInternal _TestStringMap_default_instance_;
constexpr TestStringSerializer_StringMapEntry_DoNotUse::TestStringSerializer_StringMapEntry_DoNotUse(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized){}
struct TestStringSerializer_StringMapEntry_DoNotUseDefaultTypeInternal {
constexpr TestStringSerializer_StringMapEntry_DoNotUseDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestStringSerializer_StringMapEntry_DoNotUseDefaultTypeInternal() {}
union {
TestStringSerializer_StringMapEntry_DoNotUse _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestStringSerializer_StringMapEntry_DoNotUseDefaultTypeInternal _TestStringSerializer_StringMapEntry_DoNotUse_default_instance_;
constexpr TestStringSerializer::TestStringSerializer(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: repeated_string_()
, string_map_(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{})
, scalar_string_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string){}
struct TestStringSerializerDefaultTypeInternal {
constexpr TestStringSerializerDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestStringSerializerDefaultTypeInternal() {}
union {
TestStringSerializer _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestStringSerializerDefaultTypeInternal _TestStringSerializer_default_instance_;
constexpr TestMessageWithExtension::TestMessageWithExtension(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized){}
struct TestMessageWithExtensionDefaultTypeInternal {
constexpr TestMessageWithExtensionDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestMessageWithExtensionDefaultTypeInternal() {}
union {
TestMessageWithExtension _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestMessageWithExtensionDefaultTypeInternal _TestMessageWithExtension_default_instance_;
constexpr TestExtension::TestExtension(
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
: value_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string){}
struct TestExtensionDefaultTypeInternal {
constexpr TestExtensionDefaultTypeInternal()
: _instance(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized{}) {}
~TestExtensionDefaultTypeInternal() {}
union {
TestExtension _instance;
};
};
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT TestExtensionDefaultTypeInternal _TestExtension_default_instance_;
} // namespace protobuf_unittest
static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[18];
static const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[1];
static constexpr ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2futil_2fjson_5fformat_2eproto = nullptr;
const ::PROTOBUF_NAMESPACE_ID::uint32 TableStruct_google_2fprotobuf_2futil_2fjson_5fformat_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestFlagsAndStrings_RepeatedGroup, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestFlagsAndStrings_RepeatedGroup, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestFlagsAndStrings_RepeatedGroup, f_),
0,
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestFlagsAndStrings, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestFlagsAndStrings, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestFlagsAndStrings, a_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestFlagsAndStrings, repeatedgroup_),
0,
~0u,
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestBase64ByteArrays, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestBase64ByteArrays, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestBase64ByteArrays, a_),
0,
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptJSON, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptJSON, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptJSON, a_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptJSON, final_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptJSON, in_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptJSON, var_),
2,
3,
0,
1,
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON1, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON1, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON1, d_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON1, c_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON1, x_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON1, b_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON1, a_),
0,
1,
2,
3,
4,
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON2, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON2, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON2, d_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON2, c_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON2, x_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON2, b_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON2, a_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestJavaScriptOrderJSON2, z_),
0,
1,
2,
3,
4,
~0u,
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestLargeInt, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestLargeInt, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestLargeInt, a_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestLargeInt, b_),
0,
1,
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestNumbers, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestNumbers, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestNumbers, a_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestNumbers, b_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestNumbers, c_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestNumbers, d_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestNumbers, e_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestNumbers, f_),
0,
1,
2,
3,
4,
5,
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestCamelCase, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestCamelCase, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestCamelCase, normal_field_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestCamelCase, capital_field_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestCamelCase, camelcasefield_),
0,
1,
2,
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestBoolMap_BoolMapEntry_DoNotUse, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestBoolMap_BoolMapEntry_DoNotUse, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestBoolMap_BoolMapEntry_DoNotUse, key_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestBoolMap_BoolMapEntry_DoNotUse, value_),
0,
1,
~0u, // no _has_bits_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestBoolMap, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestBoolMap, bool_map_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestRecursion, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestRecursion, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestRecursion, value_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestRecursion, child_),
1,
0,
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringMap_StringMapEntry_DoNotUse, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringMap_StringMapEntry_DoNotUse, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringMap_StringMapEntry_DoNotUse, key_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringMap_StringMapEntry_DoNotUse, value_),
0,
1,
~0u, // no _has_bits_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringMap, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringMap, string_map_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringSerializer_StringMapEntry_DoNotUse, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringSerializer_StringMapEntry_DoNotUse, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringSerializer_StringMapEntry_DoNotUse, key_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringSerializer_StringMapEntry_DoNotUse, value_),
0,
1,
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringSerializer, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringSerializer, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringSerializer, scalar_string_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringSerializer, repeated_string_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestStringSerializer, string_map_),
0,
~0u,
~0u,
~0u, // no _has_bits_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestMessageWithExtension, _internal_metadata_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestMessageWithExtension, _extensions_),
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestExtension, _has_bits_),
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestExtension, _internal_metadata_),
~0u, // no _extensions_
~0u, // no _oneof_case_
~0u, // no _weak_field_map_
PROTOBUF_FIELD_OFFSET(::protobuf_unittest::TestExtension, value_),
0,
};
static const ::PROTOBUF_NAMESPACE_ID::internal::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
{ 0, 6, sizeof(::protobuf_unittest::TestFlagsAndStrings_RepeatedGroup)},
{ 7, 14, sizeof(::protobuf_unittest::TestFlagsAndStrings)},
{ 16, 22, sizeof(::protobuf_unittest::TestBase64ByteArrays)},
{ 23, 32, sizeof(::protobuf_unittest::TestJavaScriptJSON)},
{ 36, 46, sizeof(::protobuf_unittest::TestJavaScriptOrderJSON1)},
{ 51, 62, sizeof(::protobuf_unittest::TestJavaScriptOrderJSON2)},
{ 68, 75, sizeof(::protobuf_unittest::TestLargeInt)},
{ 77, 88, sizeof(::protobuf_unittest::TestNumbers)},
{ 94, 102, sizeof(::protobuf_unittest::TestCamelCase)},
{ 105, 112, sizeof(::protobuf_unittest::TestBoolMap_BoolMapEntry_DoNotUse)},
{ 114, -1, sizeof(::protobuf_unittest::TestBoolMap)},
{ 120, 127, sizeof(::protobuf_unittest::TestRecursion)},
{ 129, 136, sizeof(::protobuf_unittest::TestStringMap_StringMapEntry_DoNotUse)},
{ 138, -1, sizeof(::protobuf_unittest::TestStringMap)},
{ 144, 151, sizeof(::protobuf_unittest::TestStringSerializer_StringMapEntry_DoNotUse)},
{ 153, 161, sizeof(::protobuf_unittest::TestStringSerializer)},
{ 164, -1, sizeof(::protobuf_unittest::TestMessageWithExtension)},
{ 169, 175, sizeof(::protobuf_unittest::TestExtension)},
};
static ::PROTOBUF_NAMESPACE_ID::Message const * const file_default_instances[] = {
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestFlagsAndStrings_RepeatedGroup_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestFlagsAndStrings_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestBase64ByteArrays_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestJavaScriptJSON_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestJavaScriptOrderJSON1_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestJavaScriptOrderJSON2_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestLargeInt_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestNumbers_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestCamelCase_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestBoolMap_BoolMapEntry_DoNotUse_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestBoolMap_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestRecursion_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestStringMap_StringMapEntry_DoNotUse_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestStringMap_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestStringSerializer_StringMapEntry_DoNotUse_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestStringSerializer_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestMessageWithExtension_default_instance_),
reinterpret_cast<const ::PROTOBUF_NAMESPACE_ID::Message*>(&::protobuf_unittest::_TestExtension_default_instance_),
};
const char descriptor_table_protodef_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) =
"\n&google/protobuf/util/json_format.proto"
"\022\021protobuf_unittest\"\211\001\n\023TestFlagsAndStri"
"ngs\022\t\n\001A\030\001 \002(\005\022K\n\rrepeatedgroup\030\002 \003(\n24."
"protobuf_unittest.TestFlagsAndStrings.Re"
"peatedGroup\032\032\n\rRepeatedGroup\022\t\n\001f\030\003 \002(\t\""
"!\n\024TestBase64ByteArrays\022\t\n\001a\030\001 \002(\014\"G\n\022Te"
"stJavaScriptJSON\022\t\n\001a\030\001 \001(\005\022\r\n\005final\030\002 \001"
"(\002\022\n\n\002in\030\003 \001(\t\022\013\n\003Var\030\004 \001(\t\"Q\n\030TestJavaS"
"criptOrderJSON1\022\t\n\001d\030\001 \001(\005\022\t\n\001c\030\002 \001(\005\022\t\n"
"\001x\030\003 \001(\010\022\t\n\001b\030\004 \001(\005\022\t\n\001a\030\005 \001(\005\"\211\001\n\030TestJ"
"avaScriptOrderJSON2\022\t\n\001d\030\001 \001(\005\022\t\n\001c\030\002 \001("
"\005\022\t\n\001x\030\003 \001(\010\022\t\n\001b\030\004 \001(\005\022\t\n\001a\030\005 \001(\005\0226\n\001z\030"
"\006 \003(\0132+.protobuf_unittest.TestJavaScript"
"OrderJSON1\"$\n\014TestLargeInt\022\t\n\001a\030\001 \002(\003\022\t\n"
"\001b\030\002 \002(\004\"\240\001\n\013TestNumbers\0220\n\001a\030\001 \001(\0162%.pr"
"otobuf_unittest.TestNumbers.MyType\022\t\n\001b\030"
"\002 \001(\005\022\t\n\001c\030\003 \001(\002\022\t\n\001d\030\004 \001(\010\022\t\n\001e\030\005 \001(\001\022\t"
"\n\001f\030\006 \001(\r\"(\n\006MyType\022\006\n\002OK\020\000\022\013\n\007WARNING\020\001"
"\022\t\n\005ERROR\020\002\"T\n\rTestCamelCase\022\024\n\014normal_f"
"ield\030\001 \001(\t\022\025\n\rCAPITAL_FIELD\030\002 \001(\005\022\026\n\016Cam"
"elCaseField\030\003 \001(\005\"|\n\013TestBoolMap\022=\n\010bool"
"_map\030\001 \003(\0132+.protobuf_unittest.TestBoolM"
"ap.BoolMapEntry\032.\n\014BoolMapEntry\022\013\n\003key\030\001"
" \001(\010\022\r\n\005value\030\002 \001(\005:\0028\001\"O\n\rTestRecursion"
"\022\r\n\005value\030\001 \001(\005\022/\n\005child\030\002 \001(\0132 .protobu"
"f_unittest.TestRecursion\"\206\001\n\rTestStringM"
"ap\022C\n\nstring_map\030\001 \003(\0132/.protobuf_unitte"
"st.TestStringMap.StringMapEntry\0320\n\016Strin"
"gMapEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:\0028"
"\001\"\304\001\n\024TestStringSerializer\022\025\n\rscalar_str"
"ing\030\001 \001(\t\022\027\n\017repeated_string\030\002 \003(\t\022J\n\nst"
"ring_map\030\003 \003(\01326.protobuf_unittest.TestS"
"tringSerializer.StringMapEntry\0320\n\016String"
"MapEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:\0028\001"
"\"$\n\030TestMessageWithExtension*\010\010d\020\200\200\200\200\002\"z"
"\n\rTestExtension\022\r\n\005value\030\001 \001(\t2Z\n\003ext\022+."
"protobuf_unittest.TestMessageWithExtensi"
"on\030d \001(\0132 .protobuf_unittest.TestExtensi"
"on"
;
static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once;
const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto = {
false, false, 1522, descriptor_table_protodef_google_2fprotobuf_2futil_2fjson_5fformat_2eproto, "google/protobuf/util/json_format.proto",
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once, nullptr, 0, 18,
schemas, file_default_instances, TableStruct_google_2fprotobuf_2futil_2fjson_5fformat_2eproto::offsets,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto, file_level_enum_descriptors_google_2fprotobuf_2futil_2fjson_5fformat_2eproto, file_level_service_descriptors_google_2fprotobuf_2futil_2fjson_5fformat_2eproto,
};
PROTOBUF_ATTRIBUTE_WEAK const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable* descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter() {
return &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto;
}
// Force running AddDescriptors() at dynamic initialization time.
PROTOBUF_ATTRIBUTE_INIT_PRIORITY static ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2futil_2fjson_5fformat_2eproto(&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto);
namespace protobuf_unittest {
const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* TestNumbers_MyType_descriptor() {
::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto);
return file_level_enum_descriptors_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[0];
}
bool TestNumbers_MyType_IsValid(int value) {
switch (value) {
case 0:
case 1:
case 2:
return true;
default:
return false;
}
}
#if (__cplusplus < 201703) && (!defined(_MSC_VER) || _MSC_VER >= 1900)
constexpr TestNumbers_MyType TestNumbers::OK;
constexpr TestNumbers_MyType TestNumbers::WARNING;
constexpr TestNumbers_MyType TestNumbers::ERROR;
constexpr TestNumbers_MyType TestNumbers::MyType_MIN;
constexpr TestNumbers_MyType TestNumbers::MyType_MAX;
constexpr int TestNumbers::MyType_ARRAYSIZE;
#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || _MSC_VER >= 1900)
// ===================================================================
class TestFlagsAndStrings_RepeatedGroup::_Internal {
public:
using HasBits = decltype(std::declval<TestFlagsAndStrings_RepeatedGroup>()._has_bits_);
static void set_has_f(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
static bool MissingRequiredFields(const HasBits& has_bits) {
return ((has_bits[0] & 0x00000001) ^ 0x00000001) != 0;
}
};
TestFlagsAndStrings_RepeatedGroup::TestFlagsAndStrings_RepeatedGroup(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestFlagsAndStrings.RepeatedGroup)
}
TestFlagsAndStrings_RepeatedGroup::TestFlagsAndStrings_RepeatedGroup(const TestFlagsAndStrings_RepeatedGroup& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
f_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_f()) {
f_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_f(),
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestFlagsAndStrings.RepeatedGroup)
}
inline void TestFlagsAndStrings_RepeatedGroup::SharedCtor() {
f_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
TestFlagsAndStrings_RepeatedGroup::~TestFlagsAndStrings_RepeatedGroup() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestFlagsAndStrings.RepeatedGroup)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestFlagsAndStrings_RepeatedGroup::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
f_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
void TestFlagsAndStrings_RepeatedGroup::ArenaDtor(void* object) {
TestFlagsAndStrings_RepeatedGroup* _this = reinterpret_cast< TestFlagsAndStrings_RepeatedGroup* >(object);
(void)_this;
}
void TestFlagsAndStrings_RepeatedGroup::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestFlagsAndStrings_RepeatedGroup::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestFlagsAndStrings_RepeatedGroup::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestFlagsAndStrings.RepeatedGroup)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000001u) {
f_.ClearNonDefaultToEmpty();
}
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestFlagsAndStrings_RepeatedGroup::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// required string f = 3;
case 3:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) {
auto str = _internal_mutable_f();
ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx);
#ifndef NDEBUG
::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "protobuf_unittest.TestFlagsAndStrings.RepeatedGroup.f");
#endif // !NDEBUG
CHK_(ptr);
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestFlagsAndStrings_RepeatedGroup::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestFlagsAndStrings.RepeatedGroup)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// required string f = 3;
if (cached_has_bits & 0x00000001u) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField(
this->_internal_f().data(), static_cast<int>(this->_internal_f().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE,
"protobuf_unittest.TestFlagsAndStrings.RepeatedGroup.f");
target = stream->WriteStringMaybeAliased(
3, this->_internal_f(), target);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestFlagsAndStrings.RepeatedGroup)
return target;
}
size_t TestFlagsAndStrings_RepeatedGroup::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestFlagsAndStrings.RepeatedGroup)
size_t total_size = 0;
// required string f = 3;
if (_internal_has_f()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_f());
}
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestFlagsAndStrings_RepeatedGroup::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestFlagsAndStrings_RepeatedGroup::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestFlagsAndStrings_RepeatedGroup::GetClassData() const { return &_class_data_; }
void TestFlagsAndStrings_RepeatedGroup::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestFlagsAndStrings_RepeatedGroup *>(to)->MergeFrom(
static_cast<const TestFlagsAndStrings_RepeatedGroup &>(from));
}
void TestFlagsAndStrings_RepeatedGroup::MergeFrom(const TestFlagsAndStrings_RepeatedGroup& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestFlagsAndStrings.RepeatedGroup)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
if (from._internal_has_f()) {
_internal_set_f(from._internal_f());
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestFlagsAndStrings_RepeatedGroup::CopyFrom(const TestFlagsAndStrings_RepeatedGroup& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestFlagsAndStrings.RepeatedGroup)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestFlagsAndStrings_RepeatedGroup::IsInitialized() const {
if (_Internal::MissingRequiredFields(_has_bits_)) return false;
return true;
}
void TestFlagsAndStrings_RepeatedGroup::InternalSwap(TestFlagsAndStrings_RepeatedGroup* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&f_, GetArenaForAllocation(),
&other->f_, other->GetArenaForAllocation()
);
}
::PROTOBUF_NAMESPACE_ID::Metadata TestFlagsAndStrings_RepeatedGroup::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[0]);
}
// ===================================================================
class TestFlagsAndStrings::_Internal {
public:
using HasBits = decltype(std::declval<TestFlagsAndStrings>()._has_bits_);
static void set_has_a(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
static bool MissingRequiredFields(const HasBits& has_bits) {
return ((has_bits[0] & 0x00000001) ^ 0x00000001) != 0;
}
};
TestFlagsAndStrings::TestFlagsAndStrings(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
repeatedgroup_(arena) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestFlagsAndStrings)
}
TestFlagsAndStrings::TestFlagsAndStrings(const TestFlagsAndStrings& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_),
repeatedgroup_(from.repeatedgroup_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
a_ = from.a_;
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestFlagsAndStrings)
}
inline void TestFlagsAndStrings::SharedCtor() {
a_ = 0;
}
TestFlagsAndStrings::~TestFlagsAndStrings() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestFlagsAndStrings)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestFlagsAndStrings::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
}
void TestFlagsAndStrings::ArenaDtor(void* object) {
TestFlagsAndStrings* _this = reinterpret_cast< TestFlagsAndStrings* >(object);
(void)_this;
}
void TestFlagsAndStrings::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestFlagsAndStrings::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestFlagsAndStrings::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestFlagsAndStrings)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
repeatedgroup_.Clear();
a_ = 0;
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestFlagsAndStrings::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// required int32 A = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) {
_Internal::set_has_a(&has_bits);
a_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// repeated group RepeatedGroup = 2 { ... };
case 2:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 19)) {
ptr -= 1;
do {
ptr += 1;
ptr = ctx->ParseGroup(_internal_add_repeatedgroup(), ptr, 19);
CHK_(ptr);
if (!ctx->DataAvailable(ptr)) break;
} while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<19>(ptr));
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestFlagsAndStrings::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestFlagsAndStrings)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// required int32 A = 1;
if (cached_has_bits & 0x00000001u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(1, this->_internal_a(), target);
}
// repeated group RepeatedGroup = 2 { ... };
for (unsigned int i = 0,
n = static_cast<unsigned int>(this->_internal_repeatedgroup_size()); i < n; i++) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::
InternalWriteGroup(2, this->_internal_repeatedgroup(i), target, stream);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestFlagsAndStrings)
return target;
}
size_t TestFlagsAndStrings::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestFlagsAndStrings)
size_t total_size = 0;
// required int32 A = 1;
if (_internal_has_a()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_a());
}
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
// repeated group RepeatedGroup = 2 { ... };
total_size += 2UL * this->_internal_repeatedgroup_size();
for (const auto& msg : this->repeatedgroup_) {
total_size +=
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::GroupSize(msg);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestFlagsAndStrings::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestFlagsAndStrings::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestFlagsAndStrings::GetClassData() const { return &_class_data_; }
void TestFlagsAndStrings::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestFlagsAndStrings *>(to)->MergeFrom(
static_cast<const TestFlagsAndStrings &>(from));
}
void TestFlagsAndStrings::MergeFrom(const TestFlagsAndStrings& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestFlagsAndStrings)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
repeatedgroup_.MergeFrom(from.repeatedgroup_);
if (from._internal_has_a()) {
_internal_set_a(from._internal_a());
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestFlagsAndStrings::CopyFrom(const TestFlagsAndStrings& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestFlagsAndStrings)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestFlagsAndStrings::IsInitialized() const {
if (_Internal::MissingRequiredFields(_has_bits_)) return false;
if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(repeatedgroup_)) return false;
return true;
}
void TestFlagsAndStrings::InternalSwap(TestFlagsAndStrings* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
repeatedgroup_.InternalSwap(&other->repeatedgroup_);
swap(a_, other->a_);
}
::PROTOBUF_NAMESPACE_ID::Metadata TestFlagsAndStrings::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[1]);
}
// ===================================================================
class TestBase64ByteArrays::_Internal {
public:
using HasBits = decltype(std::declval<TestBase64ByteArrays>()._has_bits_);
static void set_has_a(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
static bool MissingRequiredFields(const HasBits& has_bits) {
return ((has_bits[0] & 0x00000001) ^ 0x00000001) != 0;
}
};
TestBase64ByteArrays::TestBase64ByteArrays(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestBase64ByteArrays)
}
TestBase64ByteArrays::TestBase64ByteArrays(const TestBase64ByteArrays& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
a_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_a()) {
a_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_a(),
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestBase64ByteArrays)
}
inline void TestBase64ByteArrays::SharedCtor() {
a_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
TestBase64ByteArrays::~TestBase64ByteArrays() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestBase64ByteArrays)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestBase64ByteArrays::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
a_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
void TestBase64ByteArrays::ArenaDtor(void* object) {
TestBase64ByteArrays* _this = reinterpret_cast< TestBase64ByteArrays* >(object);
(void)_this;
}
void TestBase64ByteArrays::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestBase64ByteArrays::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestBase64ByteArrays::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestBase64ByteArrays)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000001u) {
a_.ClearNonDefaultToEmpty();
}
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestBase64ByteArrays::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// required bytes a = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) {
auto str = _internal_mutable_a();
ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx);
CHK_(ptr);
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestBase64ByteArrays::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestBase64ByteArrays)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// required bytes a = 1;
if (cached_has_bits & 0x00000001u) {
target = stream->WriteBytesMaybeAliased(
1, this->_internal_a(), target);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestBase64ByteArrays)
return target;
}
size_t TestBase64ByteArrays::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestBase64ByteArrays)
size_t total_size = 0;
// required bytes a = 1;
if (_internal_has_a()) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize(
this->_internal_a());
}
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestBase64ByteArrays::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestBase64ByteArrays::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestBase64ByteArrays::GetClassData() const { return &_class_data_; }
void TestBase64ByteArrays::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestBase64ByteArrays *>(to)->MergeFrom(
static_cast<const TestBase64ByteArrays &>(from));
}
void TestBase64ByteArrays::MergeFrom(const TestBase64ByteArrays& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestBase64ByteArrays)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
if (from._internal_has_a()) {
_internal_set_a(from._internal_a());
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestBase64ByteArrays::CopyFrom(const TestBase64ByteArrays& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestBase64ByteArrays)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestBase64ByteArrays::IsInitialized() const {
if (_Internal::MissingRequiredFields(_has_bits_)) return false;
return true;
}
void TestBase64ByteArrays::InternalSwap(TestBase64ByteArrays* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&a_, GetArenaForAllocation(),
&other->a_, other->GetArenaForAllocation()
);
}
::PROTOBUF_NAMESPACE_ID::Metadata TestBase64ByteArrays::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[2]);
}
// ===================================================================
class TestJavaScriptJSON::_Internal {
public:
using HasBits = decltype(std::declval<TestJavaScriptJSON>()._has_bits_);
static void set_has_a(HasBits* has_bits) {
(*has_bits)[0] |= 4u;
}
static void set_has_final(HasBits* has_bits) {
(*has_bits)[0] |= 8u;
}
static void set_has_in(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
static void set_has_var(HasBits* has_bits) {
(*has_bits)[0] |= 2u;
}
};
TestJavaScriptJSON::TestJavaScriptJSON(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestJavaScriptJSON)
}
TestJavaScriptJSON::TestJavaScriptJSON(const TestJavaScriptJSON& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
in_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_in()) {
in_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_in(),
GetArenaForAllocation());
}
var_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_var()) {
var_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_var(),
GetArenaForAllocation());
}
::memcpy(&a_, &from.a_,
static_cast<size_t>(reinterpret_cast<char*>(&final_) -
reinterpret_cast<char*>(&a_)) + sizeof(final_));
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestJavaScriptJSON)
}
inline void TestJavaScriptJSON::SharedCtor() {
in_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
var_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&a_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&final_) -
reinterpret_cast<char*>(&a_)) + sizeof(final_));
}
TestJavaScriptJSON::~TestJavaScriptJSON() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestJavaScriptJSON)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestJavaScriptJSON::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
in_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
var_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
void TestJavaScriptJSON::ArenaDtor(void* object) {
TestJavaScriptJSON* _this = reinterpret_cast< TestJavaScriptJSON* >(object);
(void)_this;
}
void TestJavaScriptJSON::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestJavaScriptJSON::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestJavaScriptJSON::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestJavaScriptJSON)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000003u) {
if (cached_has_bits & 0x00000001u) {
in_.ClearNonDefaultToEmpty();
}
if (cached_has_bits & 0x00000002u) {
var_.ClearNonDefaultToEmpty();
}
}
if (cached_has_bits & 0x0000000cu) {
::memset(&a_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&final_) -
reinterpret_cast<char*>(&a_)) + sizeof(final_));
}
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestJavaScriptJSON::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// optional int32 a = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) {
_Internal::set_has_a(&has_bits);
a_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional float final = 2;
case 2:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 21)) {
_Internal::set_has_final(&has_bits);
final_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<float>(ptr);
ptr += sizeof(float);
} else goto handle_unusual;
continue;
// optional string in = 3;
case 3:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) {
auto str = _internal_mutable_in();
ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx);
#ifndef NDEBUG
::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "protobuf_unittest.TestJavaScriptJSON.in");
#endif // !NDEBUG
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional string Var = 4;
case 4:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 34)) {
auto str = _internal_mutable_var();
ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx);
#ifndef NDEBUG
::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "protobuf_unittest.TestJavaScriptJSON.Var");
#endif // !NDEBUG
CHK_(ptr);
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestJavaScriptJSON::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestJavaScriptJSON)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// optional int32 a = 1;
if (cached_has_bits & 0x00000004u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(1, this->_internal_a(), target);
}
// optional float final = 2;
if (cached_has_bits & 0x00000008u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteFloatToArray(2, this->_internal_final(), target);
}
// optional string in = 3;
if (cached_has_bits & 0x00000001u) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField(
this->_internal_in().data(), static_cast<int>(this->_internal_in().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE,
"protobuf_unittest.TestJavaScriptJSON.in");
target = stream->WriteStringMaybeAliased(
3, this->_internal_in(), target);
}
// optional string Var = 4;
if (cached_has_bits & 0x00000002u) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField(
this->_internal_var().data(), static_cast<int>(this->_internal_var().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE,
"protobuf_unittest.TestJavaScriptJSON.Var");
target = stream->WriteStringMaybeAliased(
4, this->_internal_var(), target);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestJavaScriptJSON)
return target;
}
size_t TestJavaScriptJSON::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestJavaScriptJSON)
size_t total_size = 0;
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x0000000fu) {
// optional string in = 3;
if (cached_has_bits & 0x00000001u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_in());
}
// optional string Var = 4;
if (cached_has_bits & 0x00000002u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_var());
}
// optional int32 a = 1;
if (cached_has_bits & 0x00000004u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_a());
}
// optional float final = 2;
if (cached_has_bits & 0x00000008u) {
total_size += 1 + 4;
}
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestJavaScriptJSON::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestJavaScriptJSON::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestJavaScriptJSON::GetClassData() const { return &_class_data_; }
void TestJavaScriptJSON::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestJavaScriptJSON *>(to)->MergeFrom(
static_cast<const TestJavaScriptJSON &>(from));
}
void TestJavaScriptJSON::MergeFrom(const TestJavaScriptJSON& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestJavaScriptJSON)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = from._has_bits_[0];
if (cached_has_bits & 0x0000000fu) {
if (cached_has_bits & 0x00000001u) {
_internal_set_in(from._internal_in());
}
if (cached_has_bits & 0x00000002u) {
_internal_set_var(from._internal_var());
}
if (cached_has_bits & 0x00000004u) {
a_ = from.a_;
}
if (cached_has_bits & 0x00000008u) {
final_ = from.final_;
}
_has_bits_[0] |= cached_has_bits;
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestJavaScriptJSON::CopyFrom(const TestJavaScriptJSON& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestJavaScriptJSON)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestJavaScriptJSON::IsInitialized() const {
return true;
}
void TestJavaScriptJSON::InternalSwap(TestJavaScriptJSON* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&in_, GetArenaForAllocation(),
&other->in_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&var_, GetArenaForAllocation(),
&other->var_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(TestJavaScriptJSON, final_)
+ sizeof(TestJavaScriptJSON::final_)
- PROTOBUF_FIELD_OFFSET(TestJavaScriptJSON, a_)>(
reinterpret_cast<char*>(&a_),
reinterpret_cast<char*>(&other->a_));
}
::PROTOBUF_NAMESPACE_ID::Metadata TestJavaScriptJSON::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[3]);
}
// ===================================================================
class TestJavaScriptOrderJSON1::_Internal {
public:
using HasBits = decltype(std::declval<TestJavaScriptOrderJSON1>()._has_bits_);
static void set_has_d(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
static void set_has_c(HasBits* has_bits) {
(*has_bits)[0] |= 2u;
}
static void set_has_x(HasBits* has_bits) {
(*has_bits)[0] |= 4u;
}
static void set_has_b(HasBits* has_bits) {
(*has_bits)[0] |= 8u;
}
static void set_has_a(HasBits* has_bits) {
(*has_bits)[0] |= 16u;
}
};
TestJavaScriptOrderJSON1::TestJavaScriptOrderJSON1(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestJavaScriptOrderJSON1)
}
TestJavaScriptOrderJSON1::TestJavaScriptOrderJSON1(const TestJavaScriptOrderJSON1& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::memcpy(&d_, &from.d_,
static_cast<size_t>(reinterpret_cast<char*>(&a_) -
reinterpret_cast<char*>(&d_)) + sizeof(a_));
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestJavaScriptOrderJSON1)
}
inline void TestJavaScriptOrderJSON1::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&d_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&a_) -
reinterpret_cast<char*>(&d_)) + sizeof(a_));
}
TestJavaScriptOrderJSON1::~TestJavaScriptOrderJSON1() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestJavaScriptOrderJSON1)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestJavaScriptOrderJSON1::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
}
void TestJavaScriptOrderJSON1::ArenaDtor(void* object) {
TestJavaScriptOrderJSON1* _this = reinterpret_cast< TestJavaScriptOrderJSON1* >(object);
(void)_this;
}
void TestJavaScriptOrderJSON1::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestJavaScriptOrderJSON1::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestJavaScriptOrderJSON1::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestJavaScriptOrderJSON1)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x0000001fu) {
::memset(&d_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&a_) -
reinterpret_cast<char*>(&d_)) + sizeof(a_));
}
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestJavaScriptOrderJSON1::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// optional int32 d = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) {
_Internal::set_has_d(&has_bits);
d_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional int32 c = 2;
case 2:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 16)) {
_Internal::set_has_c(&has_bits);
c_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional bool x = 3;
case 3:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 24)) {
_Internal::set_has_x(&has_bits);
x_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional int32 b = 4;
case 4:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 32)) {
_Internal::set_has_b(&has_bits);
b_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional int32 a = 5;
case 5:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 40)) {
_Internal::set_has_a(&has_bits);
a_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestJavaScriptOrderJSON1::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestJavaScriptOrderJSON1)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// optional int32 d = 1;
if (cached_has_bits & 0x00000001u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(1, this->_internal_d(), target);
}
// optional int32 c = 2;
if (cached_has_bits & 0x00000002u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(2, this->_internal_c(), target);
}
// optional bool x = 3;
if (cached_has_bits & 0x00000004u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBoolToArray(3, this->_internal_x(), target);
}
// optional int32 b = 4;
if (cached_has_bits & 0x00000008u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(4, this->_internal_b(), target);
}
// optional int32 a = 5;
if (cached_has_bits & 0x00000010u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(5, this->_internal_a(), target);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestJavaScriptOrderJSON1)
return target;
}
size_t TestJavaScriptOrderJSON1::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestJavaScriptOrderJSON1)
size_t total_size = 0;
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x0000001fu) {
// optional int32 d = 1;
if (cached_has_bits & 0x00000001u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_d());
}
// optional int32 c = 2;
if (cached_has_bits & 0x00000002u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_c());
}
// optional bool x = 3;
if (cached_has_bits & 0x00000004u) {
total_size += 1 + 1;
}
// optional int32 b = 4;
if (cached_has_bits & 0x00000008u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_b());
}
// optional int32 a = 5;
if (cached_has_bits & 0x00000010u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_a());
}
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestJavaScriptOrderJSON1::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestJavaScriptOrderJSON1::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestJavaScriptOrderJSON1::GetClassData() const { return &_class_data_; }
void TestJavaScriptOrderJSON1::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestJavaScriptOrderJSON1 *>(to)->MergeFrom(
static_cast<const TestJavaScriptOrderJSON1 &>(from));
}
void TestJavaScriptOrderJSON1::MergeFrom(const TestJavaScriptOrderJSON1& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestJavaScriptOrderJSON1)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = from._has_bits_[0];
if (cached_has_bits & 0x0000001fu) {
if (cached_has_bits & 0x00000001u) {
d_ = from.d_;
}
if (cached_has_bits & 0x00000002u) {
c_ = from.c_;
}
if (cached_has_bits & 0x00000004u) {
x_ = from.x_;
}
if (cached_has_bits & 0x00000008u) {
b_ = from.b_;
}
if (cached_has_bits & 0x00000010u) {
a_ = from.a_;
}
_has_bits_[0] |= cached_has_bits;
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestJavaScriptOrderJSON1::CopyFrom(const TestJavaScriptOrderJSON1& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestJavaScriptOrderJSON1)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestJavaScriptOrderJSON1::IsInitialized() const {
return true;
}
void TestJavaScriptOrderJSON1::InternalSwap(TestJavaScriptOrderJSON1* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(TestJavaScriptOrderJSON1, a_)
+ sizeof(TestJavaScriptOrderJSON1::a_)
- PROTOBUF_FIELD_OFFSET(TestJavaScriptOrderJSON1, d_)>(
reinterpret_cast<char*>(&d_),
reinterpret_cast<char*>(&other->d_));
}
::PROTOBUF_NAMESPACE_ID::Metadata TestJavaScriptOrderJSON1::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[4]);
}
// ===================================================================
class TestJavaScriptOrderJSON2::_Internal {
public:
using HasBits = decltype(std::declval<TestJavaScriptOrderJSON2>()._has_bits_);
static void set_has_d(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
static void set_has_c(HasBits* has_bits) {
(*has_bits)[0] |= 2u;
}
static void set_has_x(HasBits* has_bits) {
(*has_bits)[0] |= 4u;
}
static void set_has_b(HasBits* has_bits) {
(*has_bits)[0] |= 8u;
}
static void set_has_a(HasBits* has_bits) {
(*has_bits)[0] |= 16u;
}
};
TestJavaScriptOrderJSON2::TestJavaScriptOrderJSON2(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
z_(arena) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestJavaScriptOrderJSON2)
}
TestJavaScriptOrderJSON2::TestJavaScriptOrderJSON2(const TestJavaScriptOrderJSON2& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_),
z_(from.z_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::memcpy(&d_, &from.d_,
static_cast<size_t>(reinterpret_cast<char*>(&a_) -
reinterpret_cast<char*>(&d_)) + sizeof(a_));
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestJavaScriptOrderJSON2)
}
inline void TestJavaScriptOrderJSON2::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&d_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&a_) -
reinterpret_cast<char*>(&d_)) + sizeof(a_));
}
TestJavaScriptOrderJSON2::~TestJavaScriptOrderJSON2() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestJavaScriptOrderJSON2)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestJavaScriptOrderJSON2::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
}
void TestJavaScriptOrderJSON2::ArenaDtor(void* object) {
TestJavaScriptOrderJSON2* _this = reinterpret_cast< TestJavaScriptOrderJSON2* >(object);
(void)_this;
}
void TestJavaScriptOrderJSON2::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestJavaScriptOrderJSON2::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestJavaScriptOrderJSON2::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestJavaScriptOrderJSON2)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
z_.Clear();
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x0000001fu) {
::memset(&d_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&a_) -
reinterpret_cast<char*>(&d_)) + sizeof(a_));
}
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestJavaScriptOrderJSON2::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// optional int32 d = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) {
_Internal::set_has_d(&has_bits);
d_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional int32 c = 2;
case 2:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 16)) {
_Internal::set_has_c(&has_bits);
c_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional bool x = 3;
case 3:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 24)) {
_Internal::set_has_x(&has_bits);
x_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional int32 b = 4;
case 4:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 32)) {
_Internal::set_has_b(&has_bits);
b_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional int32 a = 5;
case 5:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 40)) {
_Internal::set_has_a(&has_bits);
a_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// repeated .protobuf_unittest.TestJavaScriptOrderJSON1 z = 6;
case 6:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 50)) {
ptr -= 1;
do {
ptr += 1;
ptr = ctx->ParseMessage(_internal_add_z(), ptr);
CHK_(ptr);
if (!ctx->DataAvailable(ptr)) break;
} while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<50>(ptr));
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestJavaScriptOrderJSON2::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestJavaScriptOrderJSON2)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// optional int32 d = 1;
if (cached_has_bits & 0x00000001u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(1, this->_internal_d(), target);
}
// optional int32 c = 2;
if (cached_has_bits & 0x00000002u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(2, this->_internal_c(), target);
}
// optional bool x = 3;
if (cached_has_bits & 0x00000004u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBoolToArray(3, this->_internal_x(), target);
}
// optional int32 b = 4;
if (cached_has_bits & 0x00000008u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(4, this->_internal_b(), target);
}
// optional int32 a = 5;
if (cached_has_bits & 0x00000010u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(5, this->_internal_a(), target);
}
// repeated .protobuf_unittest.TestJavaScriptOrderJSON1 z = 6;
for (unsigned int i = 0,
n = static_cast<unsigned int>(this->_internal_z_size()); i < n; i++) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::
InternalWriteMessage(6, this->_internal_z(i), target, stream);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestJavaScriptOrderJSON2)
return target;
}
size_t TestJavaScriptOrderJSON2::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestJavaScriptOrderJSON2)
size_t total_size = 0;
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
// repeated .protobuf_unittest.TestJavaScriptOrderJSON1 z = 6;
total_size += 1UL * this->_internal_z_size();
for (const auto& msg : this->z_) {
total_size +=
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(msg);
}
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x0000001fu) {
// optional int32 d = 1;
if (cached_has_bits & 0x00000001u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_d());
}
// optional int32 c = 2;
if (cached_has_bits & 0x00000002u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_c());
}
// optional bool x = 3;
if (cached_has_bits & 0x00000004u) {
total_size += 1 + 1;
}
// optional int32 b = 4;
if (cached_has_bits & 0x00000008u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_b());
}
// optional int32 a = 5;
if (cached_has_bits & 0x00000010u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_a());
}
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestJavaScriptOrderJSON2::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestJavaScriptOrderJSON2::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestJavaScriptOrderJSON2::GetClassData() const { return &_class_data_; }
void TestJavaScriptOrderJSON2::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestJavaScriptOrderJSON2 *>(to)->MergeFrom(
static_cast<const TestJavaScriptOrderJSON2 &>(from));
}
void TestJavaScriptOrderJSON2::MergeFrom(const TestJavaScriptOrderJSON2& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestJavaScriptOrderJSON2)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
z_.MergeFrom(from.z_);
cached_has_bits = from._has_bits_[0];
if (cached_has_bits & 0x0000001fu) {
if (cached_has_bits & 0x00000001u) {
d_ = from.d_;
}
if (cached_has_bits & 0x00000002u) {
c_ = from.c_;
}
if (cached_has_bits & 0x00000004u) {
x_ = from.x_;
}
if (cached_has_bits & 0x00000008u) {
b_ = from.b_;
}
if (cached_has_bits & 0x00000010u) {
a_ = from.a_;
}
_has_bits_[0] |= cached_has_bits;
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestJavaScriptOrderJSON2::CopyFrom(const TestJavaScriptOrderJSON2& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestJavaScriptOrderJSON2)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestJavaScriptOrderJSON2::IsInitialized() const {
return true;
}
void TestJavaScriptOrderJSON2::InternalSwap(TestJavaScriptOrderJSON2* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
z_.InternalSwap(&other->z_);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(TestJavaScriptOrderJSON2, a_)
+ sizeof(TestJavaScriptOrderJSON2::a_)
- PROTOBUF_FIELD_OFFSET(TestJavaScriptOrderJSON2, d_)>(
reinterpret_cast<char*>(&d_),
reinterpret_cast<char*>(&other->d_));
}
::PROTOBUF_NAMESPACE_ID::Metadata TestJavaScriptOrderJSON2::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[5]);
}
// ===================================================================
class TestLargeInt::_Internal {
public:
using HasBits = decltype(std::declval<TestLargeInt>()._has_bits_);
static void set_has_a(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
static void set_has_b(HasBits* has_bits) {
(*has_bits)[0] |= 2u;
}
static bool MissingRequiredFields(const HasBits& has_bits) {
return ((has_bits[0] & 0x00000003) ^ 0x00000003) != 0;
}
};
TestLargeInt::TestLargeInt(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestLargeInt)
}
TestLargeInt::TestLargeInt(const TestLargeInt& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::memcpy(&a_, &from.a_,
static_cast<size_t>(reinterpret_cast<char*>(&b_) -
reinterpret_cast<char*>(&a_)) + sizeof(b_));
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestLargeInt)
}
inline void TestLargeInt::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&a_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&b_) -
reinterpret_cast<char*>(&a_)) + sizeof(b_));
}
TestLargeInt::~TestLargeInt() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestLargeInt)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestLargeInt::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
}
void TestLargeInt::ArenaDtor(void* object) {
TestLargeInt* _this = reinterpret_cast< TestLargeInt* >(object);
(void)_this;
}
void TestLargeInt::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestLargeInt::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestLargeInt::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestLargeInt)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000003u) {
::memset(&a_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&b_) -
reinterpret_cast<char*>(&a_)) + sizeof(b_));
}
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestLargeInt::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// required int64 a = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) {
_Internal::set_has_a(&has_bits);
a_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// required uint64 b = 2;
case 2:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 16)) {
_Internal::set_has_b(&has_bits);
b_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestLargeInt::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestLargeInt)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// required int64 a = 1;
if (cached_has_bits & 0x00000001u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt64ToArray(1, this->_internal_a(), target);
}
// required uint64 b = 2;
if (cached_has_bits & 0x00000002u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt64ToArray(2, this->_internal_b(), target);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestLargeInt)
return target;
}
size_t TestLargeInt::RequiredFieldsByteSizeFallback() const {
// @@protoc_insertion_point(required_fields_byte_size_fallback_start:protobuf_unittest.TestLargeInt)
size_t total_size = 0;
if (_internal_has_a()) {
// required int64 a = 1;
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int64Size(
this->_internal_a());
}
if (_internal_has_b()) {
// required uint64 b = 2;
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt64Size(
this->_internal_b());
}
return total_size;
}
size_t TestLargeInt::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestLargeInt)
size_t total_size = 0;
if (((_has_bits_[0] & 0x00000003) ^ 0x00000003) == 0) { // All required fields are present.
// required int64 a = 1;
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int64Size(
this->_internal_a());
// required uint64 b = 2;
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt64Size(
this->_internal_b());
} else {
total_size += RequiredFieldsByteSizeFallback();
}
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestLargeInt::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestLargeInt::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestLargeInt::GetClassData() const { return &_class_data_; }
void TestLargeInt::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestLargeInt *>(to)->MergeFrom(
static_cast<const TestLargeInt &>(from));
}
void TestLargeInt::MergeFrom(const TestLargeInt& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestLargeInt)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = from._has_bits_[0];
if (cached_has_bits & 0x00000003u) {
if (cached_has_bits & 0x00000001u) {
a_ = from.a_;
}
if (cached_has_bits & 0x00000002u) {
b_ = from.b_;
}
_has_bits_[0] |= cached_has_bits;
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestLargeInt::CopyFrom(const TestLargeInt& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestLargeInt)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestLargeInt::IsInitialized() const {
if (_Internal::MissingRequiredFields(_has_bits_)) return false;
return true;
}
void TestLargeInt::InternalSwap(TestLargeInt* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(TestLargeInt, b_)
+ sizeof(TestLargeInt::b_)
- PROTOBUF_FIELD_OFFSET(TestLargeInt, a_)>(
reinterpret_cast<char*>(&a_),
reinterpret_cast<char*>(&other->a_));
}
::PROTOBUF_NAMESPACE_ID::Metadata TestLargeInt::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[6]);
}
// ===================================================================
class TestNumbers::_Internal {
public:
using HasBits = decltype(std::declval<TestNumbers>()._has_bits_);
static void set_has_a(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
static void set_has_b(HasBits* has_bits) {
(*has_bits)[0] |= 2u;
}
static void set_has_c(HasBits* has_bits) {
(*has_bits)[0] |= 4u;
}
static void set_has_d(HasBits* has_bits) {
(*has_bits)[0] |= 8u;
}
static void set_has_e(HasBits* has_bits) {
(*has_bits)[0] |= 16u;
}
static void set_has_f(HasBits* has_bits) {
(*has_bits)[0] |= 32u;
}
};
TestNumbers::TestNumbers(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestNumbers)
}
TestNumbers::TestNumbers(const TestNumbers& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
::memcpy(&a_, &from.a_,
static_cast<size_t>(reinterpret_cast<char*>(&f_) -
reinterpret_cast<char*>(&a_)) + sizeof(f_));
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestNumbers)
}
inline void TestNumbers::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&a_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&f_) -
reinterpret_cast<char*>(&a_)) + sizeof(f_));
}
TestNumbers::~TestNumbers() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestNumbers)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestNumbers::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
}
void TestNumbers::ArenaDtor(void* object) {
TestNumbers* _this = reinterpret_cast< TestNumbers* >(object);
(void)_this;
}
void TestNumbers::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestNumbers::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestNumbers::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestNumbers)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x0000003fu) {
::memset(&a_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&f_) -
reinterpret_cast<char*>(&a_)) + sizeof(f_));
}
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestNumbers::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// optional .protobuf_unittest.TestNumbers.MyType a = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) {
::PROTOBUF_NAMESPACE_ID::uint64 val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
if (PROTOBUF_PREDICT_TRUE(::protobuf_unittest::TestNumbers_MyType_IsValid(val))) {
_internal_set_a(static_cast<::protobuf_unittest::TestNumbers_MyType>(val));
} else {
::PROTOBUF_NAMESPACE_ID::internal::WriteVarint(1, val, mutable_unknown_fields());
}
} else goto handle_unusual;
continue;
// optional int32 b = 2;
case 2:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 16)) {
_Internal::set_has_b(&has_bits);
b_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional float c = 3;
case 3:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 29)) {
_Internal::set_has_c(&has_bits);
c_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<float>(ptr);
ptr += sizeof(float);
} else goto handle_unusual;
continue;
// optional bool d = 4;
case 4:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 32)) {
_Internal::set_has_d(&has_bits);
d_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional double e = 5;
case 5:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 41)) {
_Internal::set_has_e(&has_bits);
e_ = ::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<double>(ptr);
ptr += sizeof(double);
} else goto handle_unusual;
continue;
// optional uint32 f = 6;
case 6:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 48)) {
_Internal::set_has_f(&has_bits);
f_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestNumbers::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestNumbers)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// optional .protobuf_unittest.TestNumbers.MyType a = 1;
if (cached_has_bits & 0x00000001u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteEnumToArray(
1, this->_internal_a(), target);
}
// optional int32 b = 2;
if (cached_has_bits & 0x00000002u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(2, this->_internal_b(), target);
}
// optional float c = 3;
if (cached_has_bits & 0x00000004u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteFloatToArray(3, this->_internal_c(), target);
}
// optional bool d = 4;
if (cached_has_bits & 0x00000008u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBoolToArray(4, this->_internal_d(), target);
}
// optional double e = 5;
if (cached_has_bits & 0x00000010u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteDoubleToArray(5, this->_internal_e(), target);
}
// optional uint32 f = 6;
if (cached_has_bits & 0x00000020u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(6, this->_internal_f(), target);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestNumbers)
return target;
}
size_t TestNumbers::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestNumbers)
size_t total_size = 0;
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x0000003fu) {
// optional .protobuf_unittest.TestNumbers.MyType a = 1;
if (cached_has_bits & 0x00000001u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::EnumSize(this->_internal_a());
}
// optional int32 b = 2;
if (cached_has_bits & 0x00000002u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_b());
}
// optional float c = 3;
if (cached_has_bits & 0x00000004u) {
total_size += 1 + 4;
}
// optional bool d = 4;
if (cached_has_bits & 0x00000008u) {
total_size += 1 + 1;
}
// optional double e = 5;
if (cached_has_bits & 0x00000010u) {
total_size += 1 + 8;
}
// optional uint32 f = 6;
if (cached_has_bits & 0x00000020u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size(
this->_internal_f());
}
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestNumbers::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestNumbers::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestNumbers::GetClassData() const { return &_class_data_; }
void TestNumbers::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestNumbers *>(to)->MergeFrom(
static_cast<const TestNumbers &>(from));
}
void TestNumbers::MergeFrom(const TestNumbers& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestNumbers)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = from._has_bits_[0];
if (cached_has_bits & 0x0000003fu) {
if (cached_has_bits & 0x00000001u) {
a_ = from.a_;
}
if (cached_has_bits & 0x00000002u) {
b_ = from.b_;
}
if (cached_has_bits & 0x00000004u) {
c_ = from.c_;
}
if (cached_has_bits & 0x00000008u) {
d_ = from.d_;
}
if (cached_has_bits & 0x00000010u) {
e_ = from.e_;
}
if (cached_has_bits & 0x00000020u) {
f_ = from.f_;
}
_has_bits_[0] |= cached_has_bits;
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestNumbers::CopyFrom(const TestNumbers& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestNumbers)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestNumbers::IsInitialized() const {
return true;
}
void TestNumbers::InternalSwap(TestNumbers* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(TestNumbers, f_)
+ sizeof(TestNumbers::f_)
- PROTOBUF_FIELD_OFFSET(TestNumbers, a_)>(
reinterpret_cast<char*>(&a_),
reinterpret_cast<char*>(&other->a_));
}
::PROTOBUF_NAMESPACE_ID::Metadata TestNumbers::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[7]);
}
// ===================================================================
class TestCamelCase::_Internal {
public:
using HasBits = decltype(std::declval<TestCamelCase>()._has_bits_);
static void set_has_normal_field(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
static void set_has_capital_field(HasBits* has_bits) {
(*has_bits)[0] |= 2u;
}
static void set_has_camelcasefield(HasBits* has_bits) {
(*has_bits)[0] |= 4u;
}
};
TestCamelCase::TestCamelCase(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestCamelCase)
}
TestCamelCase::TestCamelCase(const TestCamelCase& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
normal_field_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_normal_field()) {
normal_field_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_normal_field(),
GetArenaForAllocation());
}
::memcpy(&capital_field_, &from.capital_field_,
static_cast<size_t>(reinterpret_cast<char*>(&camelcasefield_) -
reinterpret_cast<char*>(&capital_field_)) + sizeof(camelcasefield_));
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestCamelCase)
}
inline void TestCamelCase::SharedCtor() {
normal_field_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&capital_field_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&camelcasefield_) -
reinterpret_cast<char*>(&capital_field_)) + sizeof(camelcasefield_));
}
TestCamelCase::~TestCamelCase() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestCamelCase)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestCamelCase::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
normal_field_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
void TestCamelCase::ArenaDtor(void* object) {
TestCamelCase* _this = reinterpret_cast< TestCamelCase* >(object);
(void)_this;
}
void TestCamelCase::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestCamelCase::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestCamelCase::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestCamelCase)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000001u) {
normal_field_.ClearNonDefaultToEmpty();
}
if (cached_has_bits & 0x00000006u) {
::memset(&capital_field_, 0, static_cast<size_t>(
reinterpret_cast<char*>(&camelcasefield_) -
reinterpret_cast<char*>(&capital_field_)) + sizeof(camelcasefield_));
}
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestCamelCase::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// optional string normal_field = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) {
auto str = _internal_mutable_normal_field();
ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx);
#ifndef NDEBUG
::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "protobuf_unittest.TestCamelCase.normal_field");
#endif // !NDEBUG
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional int32 CAPITAL_FIELD = 2;
case 2:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 16)) {
_Internal::set_has_capital_field(&has_bits);
capital_field_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional int32 CamelCaseField = 3;
case 3:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 24)) {
_Internal::set_has_camelcasefield(&has_bits);
camelcasefield_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestCamelCase::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestCamelCase)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// optional string normal_field = 1;
if (cached_has_bits & 0x00000001u) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField(
this->_internal_normal_field().data(), static_cast<int>(this->_internal_normal_field().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE,
"protobuf_unittest.TestCamelCase.normal_field");
target = stream->WriteStringMaybeAliased(
1, this->_internal_normal_field(), target);
}
// optional int32 CAPITAL_FIELD = 2;
if (cached_has_bits & 0x00000002u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(2, this->_internal_capital_field(), target);
}
// optional int32 CamelCaseField = 3;
if (cached_has_bits & 0x00000004u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(3, this->_internal_camelcasefield(), target);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestCamelCase)
return target;
}
size_t TestCamelCase::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestCamelCase)
size_t total_size = 0;
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000007u) {
// optional string normal_field = 1;
if (cached_has_bits & 0x00000001u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_normal_field());
}
// optional int32 CAPITAL_FIELD = 2;
if (cached_has_bits & 0x00000002u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_capital_field());
}
// optional int32 CamelCaseField = 3;
if (cached_has_bits & 0x00000004u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_camelcasefield());
}
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestCamelCase::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestCamelCase::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestCamelCase::GetClassData() const { return &_class_data_; }
void TestCamelCase::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestCamelCase *>(to)->MergeFrom(
static_cast<const TestCamelCase &>(from));
}
void TestCamelCase::MergeFrom(const TestCamelCase& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestCamelCase)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = from._has_bits_[0];
if (cached_has_bits & 0x00000007u) {
if (cached_has_bits & 0x00000001u) {
_internal_set_normal_field(from._internal_normal_field());
}
if (cached_has_bits & 0x00000002u) {
capital_field_ = from.capital_field_;
}
if (cached_has_bits & 0x00000004u) {
camelcasefield_ = from.camelcasefield_;
}
_has_bits_[0] |= cached_has_bits;
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestCamelCase::CopyFrom(const TestCamelCase& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestCamelCase)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestCamelCase::IsInitialized() const {
return true;
}
void TestCamelCase::InternalSwap(TestCamelCase* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&normal_field_, GetArenaForAllocation(),
&other->normal_field_, other->GetArenaForAllocation()
);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(TestCamelCase, camelcasefield_)
+ sizeof(TestCamelCase::camelcasefield_)
- PROTOBUF_FIELD_OFFSET(TestCamelCase, capital_field_)>(
reinterpret_cast<char*>(&capital_field_),
reinterpret_cast<char*>(&other->capital_field_));
}
::PROTOBUF_NAMESPACE_ID::Metadata TestCamelCase::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[8]);
}
// ===================================================================
TestBoolMap_BoolMapEntry_DoNotUse::TestBoolMap_BoolMapEntry_DoNotUse() {}
TestBoolMap_BoolMapEntry_DoNotUse::TestBoolMap_BoolMapEntry_DoNotUse(::PROTOBUF_NAMESPACE_ID::Arena* arena)
: SuperType(arena) {}
void TestBoolMap_BoolMapEntry_DoNotUse::MergeFrom(const TestBoolMap_BoolMapEntry_DoNotUse& other) {
MergeFromInternal(other);
}
::PROTOBUF_NAMESPACE_ID::Metadata TestBoolMap_BoolMapEntry_DoNotUse::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[9]);
}
// ===================================================================
class TestBoolMap::_Internal {
public:
};
TestBoolMap::TestBoolMap(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
bool_map_(arena) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestBoolMap)
}
TestBoolMap::TestBoolMap(const TestBoolMap& from)
: ::PROTOBUF_NAMESPACE_ID::Message() {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
bool_map_.MergeFrom(from.bool_map_);
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestBoolMap)
}
inline void TestBoolMap::SharedCtor() {
}
TestBoolMap::~TestBoolMap() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestBoolMap)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestBoolMap::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
}
void TestBoolMap::ArenaDtor(void* object) {
TestBoolMap* _this = reinterpret_cast< TestBoolMap* >(object);
(void)_this;
_this->bool_map_. ~MapField();
}
inline void TestBoolMap::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena) {
if (arena != nullptr) {
arena->OwnCustomDestructor(this, &TestBoolMap::ArenaDtor);
}
}
void TestBoolMap::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestBoolMap::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestBoolMap)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
bool_map_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestBoolMap::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// map<bool, int32> bool_map = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) {
ptr -= 1;
do {
ptr += 1;
ptr = ctx->ParseMessage(&bool_map_, ptr);
CHK_(ptr);
if (!ctx->DataAvailable(ptr)) break;
} while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr));
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestBoolMap::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestBoolMap)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
// map<bool, int32> bool_map = 1;
if (!this->_internal_bool_map().empty()) {
typedef ::PROTOBUF_NAMESPACE_ID::Map< bool, ::PROTOBUF_NAMESPACE_ID::int32 >::const_pointer
ConstPtr;
typedef ::PROTOBUF_NAMESPACE_ID::internal::SortItem< bool, ConstPtr > SortItem;
typedef ::PROTOBUF_NAMESPACE_ID::internal::CompareByFirstField<SortItem> Less;
if (stream->IsSerializationDeterministic() &&
this->_internal_bool_map().size() > 1) {
::std::unique_ptr<SortItem[]> items(
new SortItem[this->_internal_bool_map().size()]);
typedef ::PROTOBUF_NAMESPACE_ID::Map< bool, ::PROTOBUF_NAMESPACE_ID::int32 >::size_type size_type;
size_type n = 0;
for (::PROTOBUF_NAMESPACE_ID::Map< bool, ::PROTOBUF_NAMESPACE_ID::int32 >::const_iterator
it = this->_internal_bool_map().begin();
it != this->_internal_bool_map().end(); ++it, ++n) {
items[static_cast<ptrdiff_t>(n)] = SortItem(&*it);
}
::std::sort(&items[0], &items[static_cast<ptrdiff_t>(n)], Less());
for (size_type i = 0; i < n; i++) {
target = TestBoolMap_BoolMapEntry_DoNotUse::Funcs::InternalSerialize(1, items[static_cast<ptrdiff_t>(i)].second->first, items[static_cast<ptrdiff_t>(i)].second->second, target, stream);
}
} else {
for (::PROTOBUF_NAMESPACE_ID::Map< bool, ::PROTOBUF_NAMESPACE_ID::int32 >::const_iterator
it = this->_internal_bool_map().begin();
it != this->_internal_bool_map().end(); ++it) {
target = TestBoolMap_BoolMapEntry_DoNotUse::Funcs::InternalSerialize(1, it->first, it->second, target, stream);
}
}
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestBoolMap)
return target;
}
size_t TestBoolMap::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestBoolMap)
size_t total_size = 0;
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
// map<bool, int32> bool_map = 1;
total_size += 1 *
::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->_internal_bool_map_size());
for (::PROTOBUF_NAMESPACE_ID::Map< bool, ::PROTOBUF_NAMESPACE_ID::int32 >::const_iterator
it = this->_internal_bool_map().begin();
it != this->_internal_bool_map().end(); ++it) {
total_size += TestBoolMap_BoolMapEntry_DoNotUse::Funcs::ByteSizeLong(it->first, it->second);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestBoolMap::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestBoolMap::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestBoolMap::GetClassData() const { return &_class_data_; }
void TestBoolMap::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestBoolMap *>(to)->MergeFrom(
static_cast<const TestBoolMap &>(from));
}
void TestBoolMap::MergeFrom(const TestBoolMap& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestBoolMap)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
bool_map_.MergeFrom(from.bool_map_);
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestBoolMap::CopyFrom(const TestBoolMap& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestBoolMap)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestBoolMap::IsInitialized() const {
return true;
}
void TestBoolMap::InternalSwap(TestBoolMap* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
bool_map_.InternalSwap(&other->bool_map_);
}
::PROTOBUF_NAMESPACE_ID::Metadata TestBoolMap::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[10]);
}
// ===================================================================
class TestRecursion::_Internal {
public:
using HasBits = decltype(std::declval<TestRecursion>()._has_bits_);
static void set_has_value(HasBits* has_bits) {
(*has_bits)[0] |= 2u;
}
static const ::protobuf_unittest::TestRecursion& child(const TestRecursion* msg);
static void set_has_child(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
};
const ::protobuf_unittest::TestRecursion&
TestRecursion::_Internal::child(const TestRecursion* msg) {
return *msg->child_;
}
TestRecursion::TestRecursion(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestRecursion)
}
TestRecursion::TestRecursion(const TestRecursion& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
if (from._internal_has_child()) {
child_ = new ::protobuf_unittest::TestRecursion(*from.child_);
} else {
child_ = nullptr;
}
value_ = from.value_;
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestRecursion)
}
inline void TestRecursion::SharedCtor() {
::memset(reinterpret_cast<char*>(this) + static_cast<size_t>(
reinterpret_cast<char*>(&child_) - reinterpret_cast<char*>(this)),
0, static_cast<size_t>(reinterpret_cast<char*>(&value_) -
reinterpret_cast<char*>(&child_)) + sizeof(value_));
}
TestRecursion::~TestRecursion() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestRecursion)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestRecursion::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
if (this != internal_default_instance()) delete child_;
}
void TestRecursion::ArenaDtor(void* object) {
TestRecursion* _this = reinterpret_cast< TestRecursion* >(object);
(void)_this;
}
void TestRecursion::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestRecursion::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestRecursion::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestRecursion)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000001u) {
GOOGLE_DCHECK(child_ != nullptr);
child_->Clear();
}
value_ = 0;
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestRecursion::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// optional int32 value = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) {
_Internal::set_has_value(&has_bits);
value_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
// optional .protobuf_unittest.TestRecursion child = 2;
case 2:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) {
ptr = ctx->ParseMessage(_internal_mutable_child(), ptr);
CHK_(ptr);
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestRecursion::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestRecursion)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// optional int32 value = 1;
if (cached_has_bits & 0x00000002u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(1, this->_internal_value(), target);
}
// optional .protobuf_unittest.TestRecursion child = 2;
if (cached_has_bits & 0x00000001u) {
target = stream->EnsureSpace(target);
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::
InternalWriteMessage(
2, _Internal::child(this), target, stream);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestRecursion)
return target;
}
size_t TestRecursion::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestRecursion)
size_t total_size = 0;
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000003u) {
// optional .protobuf_unittest.TestRecursion child = 2;
if (cached_has_bits & 0x00000001u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(
*child_);
}
// optional int32 value = 1;
if (cached_has_bits & 0x00000002u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size(
this->_internal_value());
}
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestRecursion::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestRecursion::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestRecursion::GetClassData() const { return &_class_data_; }
void TestRecursion::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestRecursion *>(to)->MergeFrom(
static_cast<const TestRecursion &>(from));
}
void TestRecursion::MergeFrom(const TestRecursion& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestRecursion)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = from._has_bits_[0];
if (cached_has_bits & 0x00000003u) {
if (cached_has_bits & 0x00000001u) {
_internal_mutable_child()->::protobuf_unittest::TestRecursion::MergeFrom(from._internal_child());
}
if (cached_has_bits & 0x00000002u) {
value_ = from.value_;
}
_has_bits_[0] |= cached_has_bits;
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestRecursion::CopyFrom(const TestRecursion& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestRecursion)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestRecursion::IsInitialized() const {
return true;
}
void TestRecursion::InternalSwap(TestRecursion* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::memswap<
PROTOBUF_FIELD_OFFSET(TestRecursion, value_)
+ sizeof(TestRecursion::value_)
- PROTOBUF_FIELD_OFFSET(TestRecursion, child_)>(
reinterpret_cast<char*>(&child_),
reinterpret_cast<char*>(&other->child_));
}
::PROTOBUF_NAMESPACE_ID::Metadata TestRecursion::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[11]);
}
// ===================================================================
TestStringMap_StringMapEntry_DoNotUse::TestStringMap_StringMapEntry_DoNotUse() {}
TestStringMap_StringMapEntry_DoNotUse::TestStringMap_StringMapEntry_DoNotUse(::PROTOBUF_NAMESPACE_ID::Arena* arena)
: SuperType(arena) {}
void TestStringMap_StringMapEntry_DoNotUse::MergeFrom(const TestStringMap_StringMapEntry_DoNotUse& other) {
MergeFromInternal(other);
}
::PROTOBUF_NAMESPACE_ID::Metadata TestStringMap_StringMapEntry_DoNotUse::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[12]);
}
// ===================================================================
class TestStringMap::_Internal {
public:
};
TestStringMap::TestStringMap(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
string_map_(arena) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestStringMap)
}
TestStringMap::TestStringMap(const TestStringMap& from)
: ::PROTOBUF_NAMESPACE_ID::Message() {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
string_map_.MergeFrom(from.string_map_);
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestStringMap)
}
inline void TestStringMap::SharedCtor() {
}
TestStringMap::~TestStringMap() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestStringMap)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestStringMap::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
}
void TestStringMap::ArenaDtor(void* object) {
TestStringMap* _this = reinterpret_cast< TestStringMap* >(object);
(void)_this;
_this->string_map_. ~MapField();
}
inline void TestStringMap::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena) {
if (arena != nullptr) {
arena->OwnCustomDestructor(this, &TestStringMap::ArenaDtor);
}
}
void TestStringMap::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestStringMap::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestStringMap)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
string_map_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestStringMap::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// map<string, string> string_map = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) {
ptr -= 1;
do {
ptr += 1;
ptr = ctx->ParseMessage(&string_map_, ptr);
CHK_(ptr);
if (!ctx->DataAvailable(ptr)) break;
} while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr));
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestStringMap::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestStringMap)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
// map<string, string> string_map = 1;
if (!this->_internal_string_map().empty()) {
typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_pointer
ConstPtr;
typedef ConstPtr SortItem;
typedef ::PROTOBUF_NAMESPACE_ID::internal::CompareByDerefFirst<SortItem> Less;
struct Utf8Check {
static void Check(ConstPtr p) {
(void)p;
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField(
p->first.data(), static_cast<int>(p->first.length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE,
"protobuf_unittest.TestStringMap.StringMapEntry.key");
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField(
p->second.data(), static_cast<int>(p->second.length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE,
"protobuf_unittest.TestStringMap.StringMapEntry.value");
}
};
if (stream->IsSerializationDeterministic() &&
this->_internal_string_map().size() > 1) {
::std::unique_ptr<SortItem[]> items(
new SortItem[this->_internal_string_map().size()]);
typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::size_type size_type;
size_type n = 0;
for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator
it = this->_internal_string_map().begin();
it != this->_internal_string_map().end(); ++it, ++n) {
items[static_cast<ptrdiff_t>(n)] = SortItem(&*it);
}
::std::sort(&items[0], &items[static_cast<ptrdiff_t>(n)], Less());
for (size_type i = 0; i < n; i++) {
target = TestStringMap_StringMapEntry_DoNotUse::Funcs::InternalSerialize(1, items[static_cast<ptrdiff_t>(i)]->first, items[static_cast<ptrdiff_t>(i)]->second, target, stream);
Utf8Check::Check(&(*items[static_cast<ptrdiff_t>(i)]));
}
} else {
for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator
it = this->_internal_string_map().begin();
it != this->_internal_string_map().end(); ++it) {
target = TestStringMap_StringMapEntry_DoNotUse::Funcs::InternalSerialize(1, it->first, it->second, target, stream);
Utf8Check::Check(&(*it));
}
}
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestStringMap)
return target;
}
size_t TestStringMap::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestStringMap)
size_t total_size = 0;
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
// map<string, string> string_map = 1;
total_size += 1 *
::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->_internal_string_map_size());
for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator
it = this->_internal_string_map().begin();
it != this->_internal_string_map().end(); ++it) {
total_size += TestStringMap_StringMapEntry_DoNotUse::Funcs::ByteSizeLong(it->first, it->second);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestStringMap::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestStringMap::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestStringMap::GetClassData() const { return &_class_data_; }
void TestStringMap::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestStringMap *>(to)->MergeFrom(
static_cast<const TestStringMap &>(from));
}
void TestStringMap::MergeFrom(const TestStringMap& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestStringMap)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
string_map_.MergeFrom(from.string_map_);
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestStringMap::CopyFrom(const TestStringMap& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestStringMap)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestStringMap::IsInitialized() const {
return true;
}
void TestStringMap::InternalSwap(TestStringMap* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
string_map_.InternalSwap(&other->string_map_);
}
::PROTOBUF_NAMESPACE_ID::Metadata TestStringMap::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[13]);
}
// ===================================================================
TestStringSerializer_StringMapEntry_DoNotUse::TestStringSerializer_StringMapEntry_DoNotUse() {}
TestStringSerializer_StringMapEntry_DoNotUse::TestStringSerializer_StringMapEntry_DoNotUse(::PROTOBUF_NAMESPACE_ID::Arena* arena)
: SuperType(arena) {}
void TestStringSerializer_StringMapEntry_DoNotUse::MergeFrom(const TestStringSerializer_StringMapEntry_DoNotUse& other) {
MergeFromInternal(other);
}
::PROTOBUF_NAMESPACE_ID::Metadata TestStringSerializer_StringMapEntry_DoNotUse::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[14]);
}
// ===================================================================
class TestStringSerializer::_Internal {
public:
using HasBits = decltype(std::declval<TestStringSerializer>()._has_bits_);
static void set_has_scalar_string(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
};
TestStringSerializer::TestStringSerializer(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
repeated_string_(arena),
string_map_(arena) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestStringSerializer)
}
TestStringSerializer::TestStringSerializer(const TestStringSerializer& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_),
repeated_string_(from.repeated_string_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
string_map_.MergeFrom(from.string_map_);
scalar_string_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_scalar_string()) {
scalar_string_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_scalar_string(),
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestStringSerializer)
}
inline void TestStringSerializer::SharedCtor() {
scalar_string_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
TestStringSerializer::~TestStringSerializer() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestStringSerializer)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestStringSerializer::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
scalar_string_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
void TestStringSerializer::ArenaDtor(void* object) {
TestStringSerializer* _this = reinterpret_cast< TestStringSerializer* >(object);
(void)_this;
_this->string_map_. ~MapField();
}
inline void TestStringSerializer::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena) {
if (arena != nullptr) {
arena->OwnCustomDestructor(this, &TestStringSerializer::ArenaDtor);
}
}
void TestStringSerializer::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestStringSerializer::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestStringSerializer)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
repeated_string_.Clear();
string_map_.Clear();
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000001u) {
scalar_string_.ClearNonDefaultToEmpty();
}
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestStringSerializer::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// optional string scalar_string = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) {
auto str = _internal_mutable_scalar_string();
ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx);
#ifndef NDEBUG
::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "protobuf_unittest.TestStringSerializer.scalar_string");
#endif // !NDEBUG
CHK_(ptr);
} else goto handle_unusual;
continue;
// repeated string repeated_string = 2;
case 2:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) {
ptr -= 1;
do {
ptr += 1;
auto str = _internal_add_repeated_string();
ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx);
#ifndef NDEBUG
::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "protobuf_unittest.TestStringSerializer.repeated_string");
#endif // !NDEBUG
CHK_(ptr);
if (!ctx->DataAvailable(ptr)) break;
} while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr));
} else goto handle_unusual;
continue;
// map<string, string> string_map = 3;
case 3:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) {
ptr -= 1;
do {
ptr += 1;
ptr = ctx->ParseMessage(&string_map_, ptr);
CHK_(ptr);
if (!ctx->DataAvailable(ptr)) break;
} while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr));
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestStringSerializer::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestStringSerializer)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// optional string scalar_string = 1;
if (cached_has_bits & 0x00000001u) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField(
this->_internal_scalar_string().data(), static_cast<int>(this->_internal_scalar_string().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE,
"protobuf_unittest.TestStringSerializer.scalar_string");
target = stream->WriteStringMaybeAliased(
1, this->_internal_scalar_string(), target);
}
// repeated string repeated_string = 2;
for (int i = 0, n = this->_internal_repeated_string_size(); i < n; i++) {
const auto& s = this->_internal_repeated_string(i);
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField(
s.data(), static_cast<int>(s.length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE,
"protobuf_unittest.TestStringSerializer.repeated_string");
target = stream->WriteString(2, s, target);
}
// map<string, string> string_map = 3;
if (!this->_internal_string_map().empty()) {
typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_pointer
ConstPtr;
typedef ConstPtr SortItem;
typedef ::PROTOBUF_NAMESPACE_ID::internal::CompareByDerefFirst<SortItem> Less;
struct Utf8Check {
static void Check(ConstPtr p) {
(void)p;
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField(
p->first.data(), static_cast<int>(p->first.length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE,
"protobuf_unittest.TestStringSerializer.StringMapEntry.key");
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField(
p->second.data(), static_cast<int>(p->second.length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE,
"protobuf_unittest.TestStringSerializer.StringMapEntry.value");
}
};
if (stream->IsSerializationDeterministic() &&
this->_internal_string_map().size() > 1) {
::std::unique_ptr<SortItem[]> items(
new SortItem[this->_internal_string_map().size()]);
typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::size_type size_type;
size_type n = 0;
for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator
it = this->_internal_string_map().begin();
it != this->_internal_string_map().end(); ++it, ++n) {
items[static_cast<ptrdiff_t>(n)] = SortItem(&*it);
}
::std::sort(&items[0], &items[static_cast<ptrdiff_t>(n)], Less());
for (size_type i = 0; i < n; i++) {
target = TestStringSerializer_StringMapEntry_DoNotUse::Funcs::InternalSerialize(3, items[static_cast<ptrdiff_t>(i)]->first, items[static_cast<ptrdiff_t>(i)]->second, target, stream);
Utf8Check::Check(&(*items[static_cast<ptrdiff_t>(i)]));
}
} else {
for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator
it = this->_internal_string_map().begin();
it != this->_internal_string_map().end(); ++it) {
target = TestStringSerializer_StringMapEntry_DoNotUse::Funcs::InternalSerialize(3, it->first, it->second, target, stream);
Utf8Check::Check(&(*it));
}
}
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestStringSerializer)
return target;
}
size_t TestStringSerializer::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestStringSerializer)
size_t total_size = 0;
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
// repeated string repeated_string = 2;
total_size += 1 *
::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(repeated_string_.size());
for (int i = 0, n = repeated_string_.size(); i < n; i++) {
total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
repeated_string_.Get(i));
}
// map<string, string> string_map = 3;
total_size += 1 *
::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->_internal_string_map_size());
for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator
it = this->_internal_string_map().begin();
it != this->_internal_string_map().end(); ++it) {
total_size += TestStringSerializer_StringMapEntry_DoNotUse::Funcs::ByteSizeLong(it->first, it->second);
}
// optional string scalar_string = 1;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000001u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_scalar_string());
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestStringSerializer::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestStringSerializer::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestStringSerializer::GetClassData() const { return &_class_data_; }
void TestStringSerializer::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestStringSerializer *>(to)->MergeFrom(
static_cast<const TestStringSerializer &>(from));
}
void TestStringSerializer::MergeFrom(const TestStringSerializer& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestStringSerializer)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
repeated_string_.MergeFrom(from.repeated_string_);
string_map_.MergeFrom(from.string_map_);
if (from._internal_has_scalar_string()) {
_internal_set_scalar_string(from._internal_scalar_string());
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestStringSerializer::CopyFrom(const TestStringSerializer& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestStringSerializer)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestStringSerializer::IsInitialized() const {
return true;
}
void TestStringSerializer::InternalSwap(TestStringSerializer* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
repeated_string_.InternalSwap(&other->repeated_string_);
string_map_.InternalSwap(&other->string_map_);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&scalar_string_, GetArenaForAllocation(),
&other->scalar_string_, other->GetArenaForAllocation()
);
}
::PROTOBUF_NAMESPACE_ID::Metadata TestStringSerializer::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[15]);
}
// ===================================================================
class TestMessageWithExtension::_Internal {
public:
};
TestMessageWithExtension::TestMessageWithExtension(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned),
_extensions_(arena) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestMessageWithExtension)
}
TestMessageWithExtension::TestMessageWithExtension(const TestMessageWithExtension& from)
: ::PROTOBUF_NAMESPACE_ID::Message() {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
_extensions_.MergeFrom(from._extensions_);
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestMessageWithExtension)
}
inline void TestMessageWithExtension::SharedCtor() {
}
TestMessageWithExtension::~TestMessageWithExtension() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestMessageWithExtension)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestMessageWithExtension::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
}
void TestMessageWithExtension::ArenaDtor(void* object) {
TestMessageWithExtension* _this = reinterpret_cast< TestMessageWithExtension* >(object);
(void)_this;
}
void TestMessageWithExtension::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestMessageWithExtension::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestMessageWithExtension::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestMessageWithExtension)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
_extensions_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestMessageWithExtension::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
if ((800u <= tag)) {
ptr = _extensions_.ParseField(tag, ptr,
internal_default_instance(), &_internal_metadata_, ctx);
CHK_(ptr != nullptr);
continue;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
} // while
success:
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestMessageWithExtension::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestMessageWithExtension)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
// Extension range [100, 536870912)
target = _extensions_._InternalSerialize(
100, 536870912, target, stream);
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestMessageWithExtension)
return target;
}
size_t TestMessageWithExtension::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestMessageWithExtension)
size_t total_size = 0;
total_size += _extensions_.ByteSize();
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestMessageWithExtension::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestMessageWithExtension::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestMessageWithExtension::GetClassData() const { return &_class_data_; }
void TestMessageWithExtension::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestMessageWithExtension *>(to)->MergeFrom(
static_cast<const TestMessageWithExtension &>(from));
}
void TestMessageWithExtension::MergeFrom(const TestMessageWithExtension& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestMessageWithExtension)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
_extensions_.MergeFrom(from._extensions_);
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestMessageWithExtension::CopyFrom(const TestMessageWithExtension& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestMessageWithExtension)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestMessageWithExtension::IsInitialized() const {
if (!_extensions_.IsInitialized()) {
return false;
}
return true;
}
void TestMessageWithExtension::InternalSwap(TestMessageWithExtension* other) {
using std::swap;
_extensions_.InternalSwap(&other->_extensions_);
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
}
::PROTOBUF_NAMESPACE_ID::Metadata TestMessageWithExtension::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[16]);
}
// ===================================================================
class TestExtension::_Internal {
public:
using HasBits = decltype(std::declval<TestExtension>()._has_bits_);
static void set_has_value(HasBits* has_bits) {
(*has_bits)[0] |= 1u;
}
};
TestExtension::TestExtension(::PROTOBUF_NAMESPACE_ID::Arena* arena,
bool is_message_owned)
: ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) {
SharedCtor();
if (!is_message_owned) {
RegisterArenaDtor(arena);
}
// @@protoc_insertion_point(arena_constructor:protobuf_unittest.TestExtension)
}
TestExtension::TestExtension(const TestExtension& from)
: ::PROTOBUF_NAMESPACE_ID::Message(),
_has_bits_(from._has_bits_) {
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
if (from._internal_has_value()) {
value_.Set(::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::EmptyDefault{}, from._internal_value(),
GetArenaForAllocation());
}
// @@protoc_insertion_point(copy_constructor:protobuf_unittest.TestExtension)
}
inline void TestExtension::SharedCtor() {
value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
TestExtension::~TestExtension() {
// @@protoc_insertion_point(destructor:protobuf_unittest.TestExtension)
if (GetArenaForAllocation() != nullptr) return;
SharedDtor();
_internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
inline void TestExtension::SharedDtor() {
GOOGLE_DCHECK(GetArenaForAllocation() == nullptr);
value_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
void TestExtension::ArenaDtor(void* object) {
TestExtension* _this = reinterpret_cast< TestExtension* >(object);
(void)_this;
}
void TestExtension::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) {
}
void TestExtension::SetCachedSize(int size) const {
_cached_size_.Set(size);
}
void TestExtension::Clear() {
// @@protoc_insertion_point(message_clear_start:protobuf_unittest.TestExtension)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000001u) {
value_.ClearNonDefaultToEmpty();
}
_has_bits_.Clear();
_internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>();
}
const char* TestExtension::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) {
#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure
_Internal::HasBits has_bits{};
while (!ctx->Done(&ptr)) {
::PROTOBUF_NAMESPACE_ID::uint32 tag;
ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag);
switch (tag >> 3) {
// optional string value = 1;
case 1:
if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) {
auto str = _internal_mutable_value();
ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx);
#ifndef NDEBUG
::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "protobuf_unittest.TestExtension.value");
#endif // !NDEBUG
CHK_(ptr);
} else goto handle_unusual;
continue;
default: {
handle_unusual:
if ((tag == 0) || ((tag & 7) == 4)) {
CHK_(ptr);
ctx->SetLastTag(tag);
goto success;
}
ptr = UnknownFieldParse(tag,
_internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(),
ptr, ctx);
CHK_(ptr != nullptr);
continue;
}
} // switch
} // while
success:
_has_bits_.Or(has_bits);
return ptr;
failure:
ptr = nullptr;
goto success;
#undef CHK_
}
::PROTOBUF_NAMESPACE_ID::uint8* TestExtension::_InternalSerialize(
::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const {
// @@protoc_insertion_point(serialize_to_array_start:protobuf_unittest.TestExtension)
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
cached_has_bits = _has_bits_[0];
// optional string value = 1;
if (cached_has_bits & 0x00000001u) {
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField(
this->_internal_value().data(), static_cast<int>(this->_internal_value().length()),
::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE,
"protobuf_unittest.TestExtension.value");
target = stream->WriteStringMaybeAliased(
1, this->_internal_value(), target);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
}
// @@protoc_insertion_point(serialize_to_array_end:protobuf_unittest.TestExtension)
return target;
}
size_t TestExtension::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:protobuf_unittest.TestExtension)
size_t total_size = 0;
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
// Prevent compiler warnings about cached_has_bits being unused
(void) cached_has_bits;
// optional string value = 1;
cached_has_bits = _has_bits_[0];
if (cached_has_bits & 0x00000001u) {
total_size += 1 +
::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(
this->_internal_value());
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize(
_internal_metadata_, total_size, &_cached_size_);
}
int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size);
SetCachedSize(cached_size);
return total_size;
}
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TestExtension::_class_data_ = {
::PROTOBUF_NAMESPACE_ID::Message::CopyWithSizeCheck,
TestExtension::MergeImpl
};
const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TestExtension::GetClassData() const { return &_class_data_; }
void TestExtension::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message*to,
const ::PROTOBUF_NAMESPACE_ID::Message&from) {
static_cast<TestExtension *>(to)->MergeFrom(
static_cast<const TestExtension &>(from));
}
void TestExtension::MergeFrom(const TestExtension& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:protobuf_unittest.TestExtension)
GOOGLE_DCHECK_NE(&from, this);
::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
(void) cached_has_bits;
if (from._internal_has_value()) {
_internal_set_value(from._internal_value());
}
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
}
void TestExtension::CopyFrom(const TestExtension& from) {
// @@protoc_insertion_point(class_specific_copy_from_start:protobuf_unittest.TestExtension)
if (&from == this) return;
Clear();
MergeFrom(from);
}
bool TestExtension::IsInitialized() const {
return true;
}
void TestExtension::InternalSwap(TestExtension* other) {
using std::swap;
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
swap(_has_bits_[0], other->_has_bits_[0]);
::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
&value_, GetArenaForAllocation(),
&other->value_, other->GetArenaForAllocation()
);
}
::PROTOBUF_NAMESPACE_ID::Metadata TestExtension::GetMetadata() const {
return ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(
&descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_getter, &descriptor_table_google_2fprotobuf_2futil_2fjson_5fformat_2eproto_once,
file_level_metadata_google_2fprotobuf_2futil_2fjson_5fformat_2eproto[17]);
}
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int TestExtension::kExtFieldNumber;
#endif
PROTOBUF_ATTRIBUTE_INIT_PRIORITY ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::protobuf_unittest::TestMessageWithExtension,
::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::protobuf_unittest::TestExtension >, 11, false >
TestExtension::ext(kExtFieldNumber, ::protobuf_unittest::TestExtension::default_instance());
// @@protoc_insertion_point(namespace_scope)
} // namespace protobuf_unittest
PROTOBUF_NAMESPACE_OPEN
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestFlagsAndStrings_RepeatedGroup* Arena::CreateMaybeMessage< ::protobuf_unittest::TestFlagsAndStrings_RepeatedGroup >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestFlagsAndStrings_RepeatedGroup >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestFlagsAndStrings* Arena::CreateMaybeMessage< ::protobuf_unittest::TestFlagsAndStrings >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestFlagsAndStrings >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestBase64ByteArrays* Arena::CreateMaybeMessage< ::protobuf_unittest::TestBase64ByteArrays >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestBase64ByteArrays >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestJavaScriptJSON* Arena::CreateMaybeMessage< ::protobuf_unittest::TestJavaScriptJSON >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestJavaScriptJSON >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestJavaScriptOrderJSON1* Arena::CreateMaybeMessage< ::protobuf_unittest::TestJavaScriptOrderJSON1 >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestJavaScriptOrderJSON1 >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestJavaScriptOrderJSON2* Arena::CreateMaybeMessage< ::protobuf_unittest::TestJavaScriptOrderJSON2 >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestJavaScriptOrderJSON2 >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestLargeInt* Arena::CreateMaybeMessage< ::protobuf_unittest::TestLargeInt >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestLargeInt >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestNumbers* Arena::CreateMaybeMessage< ::protobuf_unittest::TestNumbers >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestNumbers >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestCamelCase* Arena::CreateMaybeMessage< ::protobuf_unittest::TestCamelCase >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestCamelCase >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestBoolMap_BoolMapEntry_DoNotUse* Arena::CreateMaybeMessage< ::protobuf_unittest::TestBoolMap_BoolMapEntry_DoNotUse >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestBoolMap_BoolMapEntry_DoNotUse >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestBoolMap* Arena::CreateMaybeMessage< ::protobuf_unittest::TestBoolMap >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestBoolMap >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestRecursion* Arena::CreateMaybeMessage< ::protobuf_unittest::TestRecursion >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestRecursion >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestStringMap_StringMapEntry_DoNotUse* Arena::CreateMaybeMessage< ::protobuf_unittest::TestStringMap_StringMapEntry_DoNotUse >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestStringMap_StringMapEntry_DoNotUse >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestStringMap* Arena::CreateMaybeMessage< ::protobuf_unittest::TestStringMap >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestStringMap >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestStringSerializer_StringMapEntry_DoNotUse* Arena::CreateMaybeMessage< ::protobuf_unittest::TestStringSerializer_StringMapEntry_DoNotUse >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestStringSerializer_StringMapEntry_DoNotUse >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestStringSerializer* Arena::CreateMaybeMessage< ::protobuf_unittest::TestStringSerializer >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestStringSerializer >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestMessageWithExtension* Arena::CreateMaybeMessage< ::protobuf_unittest::TestMessageWithExtension >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestMessageWithExtension >(arena);
}
template<> PROTOBUF_NOINLINE ::protobuf_unittest::TestExtension* Arena::CreateMaybeMessage< ::protobuf_unittest::TestExtension >(Arena* arena) {
return Arena::CreateMessageInternal< ::protobuf_unittest::TestExtension >(arena);
}
PROTOBUF_NAMESPACE_CLOSE
// @@protoc_insertion_point(global_scope)
#include <google/protobuf/port_undef.inc>
| 40.570942 | 232 | 0.735738 | [
"object"
] |
8278265d90d01b0eeaf81401091e56bc444e2487 | 2,604 | cpp | C++ | assignments/a1-hello/unique.cpp | msunde137/animation-toolkit | d2455d8d41108b645cb4be26060ba6d5c6c955b3 | [
"MIT"
] | 3 | 2021-12-24T04:12:53.000Z | 2021-12-24T04:14:28.000Z | assignments/a1-hello/unique.cpp | msunde137/animation-toolkit | d2455d8d41108b645cb4be26060ba6d5c6c955b3 | [
"MIT"
] | null | null | null | assignments/a1-hello/unique.cpp | msunde137/animation-toolkit | d2455d8d41108b645cb4be26060ba6d5c6c955b3 | [
"MIT"
] | null | null | null | #include "atkui/framework.h"
using namespace glm;
struct particle
{
vec3 position;
vec3 velocity;
vec3 color;
};
class Unique : public atkui::Framework {
public:
Unique() : atkui::Framework(atkui::Orthographic) {
}
virtual void setup() {
//winx = 0;
//winy = 0;
//glfwGetWindowPos(atkui::Framework::getWindow(), &winx, &winy);
gravity = -300;
drag = .05;
bounce = .7;
numParticles = 150;
for (int i = 0; i < numParticles; i++)
{
particle p;
p.position = (agl::randomUnitSquare() + vec3(0.5, 0.5, 0)) * vec3(width() - 22, height() - 22, 0) + vec3(11, 11, 0);
p.velocity = agl::randomUnitDisk() * 20.0f;
p.color = agl::randomUnitCube() + vec3(0.5, 0.5, 0.5);
particles.push_back(p);
}
}
virtual void scene() {
float dt = atkui::Framework::dt();
// tried implementing window movement
//int wincx = 0;
//int wincy = 0;
//glfwGetWindowPos(atkui::Framework::getWindow(), &wincx, &wincy);
//vec3 dwin = vec3(0, -winy, 0) - vec3(0, -wincy, 0);
//winx = wincx;
//winy = wincy;
for (int i = 0; i < particles.size(); i++)
{
particles[i].position += particles[i].velocity * dt;
particles[i].velocity += vec3(0, gravity, 0) * dt;
particles[i].velocity -= particles[i].velocity * drag * dt;
setColor(particles[i].color);
drawSphere(particles[i].position, 10);
// bounding box
if (particles[i].position.x + 10 > width())
{
particles[i].velocity = glm::reflect(particles[i].velocity, vec3(-1, 0, 0));
particles[i].velocity *= bounce;
particles[i].position.x = width() - 11;
}
else if (particles[i].position.x - 10 < 0)
{
particles[i].velocity = glm::reflect(particles[i].velocity, vec3(1, 0, 0));
particles[i].velocity *= bounce;
particles[i].position.x = 11;
}
if (particles[i].position.y + 10 > height())
{
particles[i].velocity = glm::reflect(particles[i].velocity, vec3(0, 1, 0));
particles[i].velocity *= bounce;
particles[i].position.y = height() - 11;
}
else if (particles[i].position.y - 10 < 0)
{
particles[i].velocity = glm::reflect(particles[i].velocity, vec3(0, -1, 0));
particles[i].velocity *= bounce;
particles[i].position.y = 11;
}
if (atkui::Framework::keyIsDown(GLFW_KEY_R))
{
particles.clear();
setup();
}
}
}
int winx, winy;
vec3 dwin;
std::vector<particle> particles;
int numParticles;
float drag;
float bounce;
float gravity;
};
int main(int argc, char** argv) {
Unique viewer;
viewer.run();
return 0;
}
| 23.889908 | 120 | 0.593702 | [
"vector"
] |
82788fafd9290679bbfb424a4e2db1bf3a8b7cd2 | 16,643 | cpp | C++ | flashlight/fl/experimental/memory/allocator/freelist/FreeList.cpp | codekansas/flashlight | 6b9e1f5d00269bda8ca6f453ab7f15bd2b8627f9 | [
"BSD-3-Clause"
] | 1 | 2021-05-26T11:56:41.000Z | 2021-05-26T11:56:41.000Z | flashlight/fl/experimental/memory/allocator/freelist/FreeList.cpp | codekansas/flashlight | 6b9e1f5d00269bda8ca6f453ab7f15bd2b8627f9 | [
"BSD-3-Clause"
] | null | null | null | flashlight/fl/experimental/memory/allocator/freelist/FreeList.cpp | codekansas/flashlight | 6b9e1f5d00269bda8ca6f453ab7f15bd2b8627f9 | [
"BSD-3-Clause"
] | null | null | null | /*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "flashlight/fl/experimental/memory/allocator/freelist/FreeList.h"
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <sstream>
#include <stdexcept>
#include <unordered_map>
#include <utility>
#include "flashlight/fl/common/Histogram.h"
#include "flashlight/fl/common/Logging.h"
#include "flashlight/fl/common/Utils.h"
namespace fl {
// prettyString() will show up to the first kPrettyStringMaxChunks chunks.
constexpr size_t kPrettyStringMaxChunks = 3;
FreeList::Chunk::Chunk(size_t blockStartIndex, size_t sizeInBlocks)
: blockStartIndex_(blockStartIndex),
sizeInBlocks_(sizeInBlocks),
next_(nullptr),
prev_(nullptr) {}
std::string FreeList::Chunk::prettyString() const {
std::stringstream ss;
ss << "Chunk{blockStartIndex_=" << blockStartIndex_
<< " sizeInBlocks_=" << sizeInBlocks_ << " next_=" << next_
<< " prev_=" << prev_ << "}";
return ss.str();
}
FreeList::FreeList(
std::string name,
void* arena,
size_t arenaSizeInBytes,
size_t blockSize,
double allocatedRatioJitThreshold,
int logLevel)
: MemoryAllocator(std::move(name), logLevel),
stats_(arena, arenaSizeInBytes, blockSize),
largestChunkInBlocks_(stats_.statsInBlocks.arenaSize),
totalNumberOfChunks_(1),
freeListSize_(1),
maxFreeListSize_(1),
freeList_(new Chunk(0, stats_.statsInBlocks.arenaSize)),
allocatedRatioJitThreshold_(allocatedRatioJitThreshold),
isNullAllocator_(arenaSizeInBytes < blockSize) {
if (getLogLevel() > 1) {
std::stringstream ss;
ss << "FreeList::FreeList(name_=" << name_ << " arena=" << arena
<< " arenaSizeInBytes=" << arenaSizeInBytes << " blockSize=" << blockSize
<< ')';
if (arenaSizeInBytes < blockSize) {
ss << " arenaSizeInBytes < blockSize --> isNullAllocator_=true";
isNullAllocator_ = true;
}
ss << ' ' << prettyString();
FL_LOG(fl::INFO) << ss.str();
}
}
FreeList::~FreeList() {
if (pointerToAllocatedChunkMap_.size() && getLogLevel() > 0) {
FL_LOG(fl::WARNING) << "~FreeList() there are still "
<< stats_.statsInBlocks.arenaSize << " blocks in "
<< pointerToAllocatedChunkMap_.size()
<< " chunks held by the user";
// Free chunks held by the user.
for (auto& ptrAndChunk : pointerToAllocatedChunkMap_) {
delete ptrAndChunk.second;
}
}
// Free chunks in the free list.
for (Chunk* chunk = freeList_; chunk;) {
Chunk* toDelete = chunk;
chunk = chunk->next_;
delete toDelete;
}
}
bool FreeList::jitTreeExceedsMemoryPressure(size_t bytes) {
if (bytes == 0 || isNullAllocator_) {
return false;
}
const size_t nBlocksNeed = divRoundUp(bytes, stats_.blockSize);
if (nBlocksNeed > largestChunkInBlocks_) {
FL_LOG(fl::INFO) << "FreeList::jitTreeExceedsMemoryPressure(bytes=" << bytes
<< ") true nBlocksNeed=" << nBlocksNeed
<< " largestChunkInBlocks_=" << largestChunkInBlocks_;
return true;
}
const double allocatedRatio =
static_cast<double>(stats_.statsInBlocks.allocatedCount + nBlocksNeed) /
static_cast<double>(stats_.statsInBlocks.arenaSize);
if (allocatedRatio > allocatedRatioJitThreshold_) {
FL_LOG(fl::INFO) << "FreeList::jitTreeExceedsMemoryPressure(bytes=" << bytes
<< ") true allocatedRatio=" << allocatedRatio
<< " allocatedRatioJitThreshold_="
<< allocatedRatioJitThreshold_;
}
return allocatedRatio > allocatedRatioJitThreshold_;
}
void* FreeList::allocate(size_t size) {
if (!size && isNullAllocator_) {
return nullptr;
}
const size_t nBlocksNeed = divRoundUp(size, stats_.blockSize);
Chunk* chunk = findBestFit(nBlocksNeed);
if (!chunk || freeListSize_ == 0) {
if (getLogLevel() > 1) {
stats_.incrementOomEventCount();
std::stringstream ss;
ss << "OOM error at FreeList::allocate(size="
<< prettyStringMemorySize(size) << ") name=" << getName()
<< " freeListSize_=" << freeListSize_
<< " failed to allocate since largestChunkInBlocks_="
<< largestChunkInBlocks_ << " but nBlocksNeed=" << nBlocksNeed;
FL_LOG(fl::ERROR) << ss.str();
throw std::invalid_argument(ss.str());
}
return nullptr;
}
chopChunkIfNeeded(chunk, nBlocksNeed);
removeFromFreeList(chunk);
void* ptr = memoryAddress(stats_.arena, chunk->blockStartIndex_);
pointerToAllocatedChunkMap_[ptr] = chunk;
chunk->sizeInBytes_ = size;
stats_.allocate(chunk->sizeInBytes_, chunk->sizeInBlocks_);
stats_.addPerformanceCost(freeListSize_);
--freeListSize_;
// historyOfAllocationRequestInBlocks_.push_back(nBlocksNeed);
return ptr;
}
namespace {
void throwGetChunkError(
void* ptr,
const std::string& callerNameForErrorMessage,
const std::string& name) {
std::stringstream ss;
ss << callerNameForErrorMessage << "(ptr=" << ptr
<< ") pointer is not managed by FreeList name=" << name;
throw std::invalid_argument(ss.str());
}
} // namespace
FreeList::Chunk* FreeList::getChunkAndRemoveFromMap(
void* ptr,
const std::string& callerNameForErrorMessage) {
Chunk* chunk = nullptr;
auto chunkItr = pointerToAllocatedChunkMap_.find(ptr);
if (chunkItr != pointerToAllocatedChunkMap_.end()) {
chunk = chunkItr->second;
pointerToAllocatedChunkMap_.erase(chunkItr);
} else {
throwGetChunkError(ptr, callerNameForErrorMessage, getName());
}
return chunk;
}
const FreeList::Chunk* FreeList::getChunk(
void* ptr,
const std::string& callerNameForErrorMessage) const {
const auto chunkItr = pointerToAllocatedChunkMap_.find(ptr);
if (chunkItr == pointerToAllocatedChunkMap_.end()) {
throwGetChunkError(ptr, callerNameForErrorMessage, getName());
}
return chunkItr->second;
}
void FreeList::free(void* ptr) {
Chunk* chunk = getChunkAndRemoveFromMap(ptr, __PRETTY_FUNCTION__);
if (getLogLevel() > 1) {
FL_VLOG(2) << "FreeList::free(ptr=" << ptr << ") name=" << getName()
<< " chunk=" << chunk->prettyString();
}
// stats
stats_.free(chunk->sizeInBytes_, chunk->sizeInBlocks_);
stats_.addPerformanceCost(freeListSize_);
addToFreeList(chunk);
mergeWithNeighbors(chunk);
}
namespace {
constexpr size_t kBlockShowSizeThreshold = 10;
constexpr double kBlockSizeLogBase = 1.2;
const double kBlockSizeRatio = (1.0 / (std::log(kBlockSizeLogBase) * 2.0));
std::string formatBlock(bool isFree, size_t size) {
const char symbol = (isFree) ? ' ' : 'x';
std::stringstream ss;
if (size <= kBlockShowSizeThreshold) {
for (int i = 0; i < size; ++i) {
ss << symbol;
}
} else {
const int len = static_cast<int>(std::log(size) * kBlockSizeRatio);
for (int i = 0; i < len; ++i) {
ss << symbol;
}
ss << '(' << (isFree ? "free" : "used") << '=' << prettyStringCount(size)
<< ')';
for (int i = 0; i < len; ++i) {
ss << symbol;
}
}
return ss.str();
};
} // namespace
std::string FreeList::BlockMapFormatter::prettyString() const {
if (!chunk) {
return "BlockMapFormatter::prettyString() null chunk error";
}
return formatBlock(isFree, chunk->sizeInBlocks_);
}
std::string FreeList::blockMapPrettyString() const {
std::vector<BlockMapFormatter> chunksFormatter;
for (const Chunk* cur = freeList_; cur; cur = cur->next_) {
chunksFormatter.push_back({true, cur});
}
for (const auto& ptrAndChunk : pointerToAllocatedChunkMap_) {
chunksFormatter.push_back({false, ptrAndChunk.second});
}
std::sort(
chunksFormatter.begin(),
chunksFormatter.end(),
[](const BlockMapFormatter& lhs, const BlockMapFormatter& rhs) {
return lhs.chunk->blockStartIndex_ < rhs.chunk->blockStartIndex_;
});
std::vector<std::pair<bool, size_t>> chunksConsolidated;
chunksConsolidated.push_back({chunksFormatter.at(0).isFree,
chunksFormatter.at(0).chunk->sizeInBlocks_});
for (size_t i = 1; i < chunksFormatter.size(); ++i) {
BlockMapFormatter& cur = chunksFormatter[i];
if (((cur.isFree) ? 1 : 0) == ((chunksConsolidated.back().first) ? 1 : 0)) {
chunksConsolidated.back().second += cur.chunk->sizeInBlocks_;
} else {
chunksConsolidated.push_back({cur.isFree, cur.chunk->sizeInBlocks_});
}
}
std::stringstream ss;
ss << "Block-Map (Key: free=' ' used='x'):" << std::endl;
std::string ret = ss.str();
for (const auto& freeAndSize : chunksConsolidated) {
ret = ret + formatBlock(freeAndSize.first, freeAndSize.second);
}
return ret;
}
std::string FreeList::prettyString() const {
const Stats stats = getStats();
std::stringstream ss;
ss << "FreeList{name=" << getName() << " stats=" << stats_.prettyString()
<< " largestChunkInBlocks_=" << largestChunkInBlocks_
<< " totalNumberOfChunks_=" << totalNumberOfChunks_
<< " numberOfAllocatedChunks=" << pointerToAllocatedChunkMap_.size()
<< " maxFreeListSize_=" << maxFreeListSize_
<< " freeListSize_=" << freeListSize_ << " freeList_={";
int chunkNum = 0;
for (Chunk* cur = freeList_; cur && (chunkNum < kPrettyStringMaxChunks);
cur = cur->next_, ++chunkNum) {
ss << cur->prettyString() << " ";
}
if (freeListSize_ > kPrettyStringMaxChunks) {
ss << "... not showing the next_ "
<< (freeListSize_ - kPrettyStringMaxChunks) << " chunks.";
}
// Histogram and memory map.
{
std::vector<size_t> cureentAllocationSize(
pointerToAllocatedChunkMap_.size());
for (const auto& ptrAndChunk : pointerToAllocatedChunkMap_) {
cureentAllocationSize.push_back(ptrAndChunk.second->sizeInBytes_);
}
HistogramStats<size_t> hist = FixedBucketSizeHistogram<size_t>(
cureentAllocationSize.begin(),
cureentAllocationSize.end(),
kHistogramBucketCountPrettyString);
ss << std::endl
<< "FreeList currently allocated histogram:" << std::endl
<< hist.prettyString() << std::endl
<< "FreeList currently allocated memory map:" << std::endl
<< blockMapPrettyString() << std::endl;
}
ss << "}";
return ss.str();
}
FreeList::Chunk* FreeList::findBestFit(size_t nBlocksNeed) {
size_t smallestMatchSize = SIZE_MAX;
Chunk* bestFit = nullptr;
largestChunkInBlocks_ = 0;
for (Chunk* cur = freeList_; cur; cur = cur->next_) {
if (cur->sizeInBlocks_ >= nBlocksNeed &&
cur->sizeInBlocks_ <= smallestMatchSize) {
bestFit = cur;
smallestMatchSize = cur->sizeInBlocks_;
}
largestChunkInBlocks_ = std::max(largestChunkInBlocks_, cur->sizeInBlocks_);
}
if (getLogLevel() > 1) {
FL_VLOG(3) << "FreeList::findBestFit(nBlocksNeed=" << nBlocksNeed << ")"
<< " name=" << getName() << " return "
<< (bestFit ? bestFit->prettyString() : "null") << ')';
}
return bestFit;
}
void FreeList::chopChunkIfNeeded(FreeList::Chunk* chunk, size_t nBlocksNeed) {
const Chunk origChunk = *chunk;
if (chunk->sizeInBlocks_ > nBlocksNeed) {
Chunk* newChunk = new Chunk(
chunk->blockStartIndex_ + nBlocksNeed,
chunk->sizeInBlocks_ - nBlocksNeed);
newChunk->next_ = chunk->next_;
newChunk->prev_ = chunk;
if (chunk->next_) {
chunk->next_->prev_ = newChunk;
}
chunk->next_ = newChunk;
chunk->sizeInBlocks_ = nBlocksNeed;
// Stats
++freeListSize_;
maxFreeListSize_ = std::max(maxFreeListSize_, freeListSize_);
++totalNumberOfChunks_;
if (getLogLevel() > 1) {
FL_VLOG(3) << "FreeList::chopChunkIfNeeded(chunk="
<< origChunk.prettyString() << " nBlocksNeed=" << nBlocksNeed
<< ") name=" << getName()
<< " newChunk=" << newChunk->prettyString();
}
}
}
void FreeList::addToFreeList(FreeList::Chunk* chunk) {
if (!freeList_) {
chunk->prev_ = nullptr;
chunk->next_ = nullptr;
freeList_ = chunk;
} else if (freeList_->blockStartIndex_ > chunk->blockStartIndex_) {
chunk->prev_ = nullptr;
chunk->next_ = freeList_;
freeList_->prev_ = chunk;
freeList_ = chunk;
} else {
// Find the chunk right before the chunk we are adding.
Chunk* chunkBeforeNewChunk = freeList_;
while (chunkBeforeNewChunk->next_ &&
chunkBeforeNewChunk->next_->blockStartIndex_ <
chunk->blockStartIndex_) {
chunkBeforeNewChunk = chunkBeforeNewChunk->next_;
}
chunk->prev_ = chunkBeforeNewChunk;
chunk->next_ = chunkBeforeNewChunk->next_;
if (chunkBeforeNewChunk->next_) {
chunkBeforeNewChunk->next_->prev_ = chunk;
}
chunkBeforeNewChunk->next_ = chunk;
}
++freeListSize_;
maxFreeListSize_ = std::max(maxFreeListSize_, freeListSize_);
}
FreeList::Chunk* FreeList::mergeWithPrevNeighbors(FreeList::Chunk* chunk) {
Chunk* prevChunk = chunk->prev_;
if (prevChunk &&
(prevChunk->blockStartIndex_ + prevChunk->sizeInBlocks_) ==
chunk->blockStartIndex_) {
const size_t origSize = chunk->sizeInBlocks_;
prevChunk->next_ = chunk->next_;
prevChunk->sizeInBlocks_ += chunk->sizeInBlocks_;
Chunk* nextChunk = chunk->next_;
if (nextChunk) {
nextChunk->prev_ = prevChunk;
}
delete chunk;
// stats
if (freeListSize_ == 0 || totalNumberOfChunks_ == 0) {
std::stringstream ss;
ss << "FreeList::mergeWithPrevNeighbors() freeListSize_=" << freeListSize_
<< " totalNumberOfChunks_=" << totalNumberOfChunks_
<< " but both should be > 1.";
FL_LOG(fl::ERROR) << ss.str();
throw std::runtime_error(ss.str());
}
--freeListSize_;
--totalNumberOfChunks_;
if (getLogLevel() > 1) {
FL_VLOG(2) << "FreeList::mergeWithPrevNeighbors(). original size="
<< origSize << " new size=" << prevChunk->sizeInBlocks_
<< " new chunk details=" << prevChunk->prettyString() << ")";
}
return prevChunk;
}
return chunk;
}
void FreeList::mergeWithNextNeighbors(FreeList::Chunk* chunk) {
Chunk* nextChunk = chunk->next_;
if (nextChunk &&
(chunk->blockStartIndex_ + chunk->sizeInBlocks_) ==
nextChunk->blockStartIndex_) {
const size_t origSize = chunk->sizeInBlocks_;
chunk->sizeInBlocks_ += nextChunk->sizeInBlocks_;
chunk->next_ = nextChunk->next_;
if (nextChunk->next_) {
nextChunk->next_->prev_ = chunk;
}
delete nextChunk;
// stats
if (freeListSize_ == 0 || totalNumberOfChunks_ == 0) {
std::stringstream ss;
ss << "FreeList::mergeWithNextNeighbors() freeListSize_=" << freeListSize_
<< " totalNumberOfChunks_=" << totalNumberOfChunks_
<< " but both should be > 1.";
FL_LOG(fl::ERROR) << ss.str();
throw std::runtime_error(ss.str());
}
--freeListSize_;
--totalNumberOfChunks_;
if (getLogLevel() > 1) {
FL_VLOG(2) << "FreeList::mergeWithNextNeighbors(). original size="
<< origSize << " new size=" << chunk->sizeInBlocks_
<< " new chunk details=" << chunk->prettyString() << ")";
}
}
}
void FreeList::mergeWithNeighbors(FreeList::Chunk* chunk) {
chunk = mergeWithPrevNeighbors(chunk);
mergeWithNextNeighbors(chunk);
}
void FreeList::removeFromFreeList(FreeList::Chunk* chunk) {
// If chunk is the first in the freeList_.
if (freeList_ == chunk) {
freeList_ = chunk->next_;
}
if (chunk->prev_) {
chunk->prev_->next_ = chunk->next_;
} else {
freeList_ = chunk->next_;
}
if (chunk->next_) {
chunk->next_->prev_ = chunk->prev_;
}
chunk->prev_ = nullptr;
chunk->next_ = nullptr;
}
MemoryAllocator::Stats FreeList::getStats() const {
// Calculate ExternalFragmentationScore
largestChunkInBlocks_ = 0;
for (Chunk* cur = freeList_; cur; cur = cur->next_) {
largestChunkInBlocks_ = std::max(largestChunkInBlocks_, cur->sizeInBlocks_);
}
const double largetsChunkOutOfFreeChunks =
(stats_.statsInBlocks.freeCount > 0)
? (static_cast<double>(largestChunkInBlocks_) /
static_cast<double>(stats_.statsInBlocks.freeCount))
: 1.0;
stats_.setExternalFragmentationScore(1.0 - largetsChunkOutOfFreeChunks);
return stats_;
}
size_t FreeList::getAllocatedSizeInBytes(void* ptr) const {
const Chunk* chunk = getChunk(ptr, __PRETTY_FUNCTION__);
return chunk->sizeInBytes_;
}
}; // namespace fl
| 32.129344 | 80 | 0.653428 | [
"vector"
] |
8278968c218681e933f948843a3882ebb15d595d | 39,034 | cpp | C++ | deployed/Il2CppOutputProject/Source/il2cppOutput/Bulk_Assembly-CSharp_0.cpp | PaulDixon/HelloWorld | f73f1eb2f972b3bc03420727e3c383ff63041af9 | [
"MIT"
] | null | null | null | deployed/Il2CppOutputProject/Source/il2cppOutput/Bulk_Assembly-CSharp_0.cpp | PaulDixon/HelloWorld | f73f1eb2f972b3bc03420727e3c383ff63041af9 | [
"MIT"
] | null | null | null | deployed/Il2CppOutputProject/Source/il2cppOutput/Bulk_Assembly-CSharp_0.cpp | PaulDixon/HelloWorld | f73f1eb2f972b3bc03420727e3c383ff63041af9 | [
"MIT"
] | null | null | null | #include "il2cpp-config.h"
#ifndef _MSC_VER
# include <alloca.h>
#else
# include <malloc.h>
#endif
#include <cstring>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <limits>
#include <assert.h>
#include <stdint.h>
#include "il2cpp-class-internals.h"
#include "codegen/il2cpp-codegen.h"
#include "il2cpp-object-internals.h"
template <typename T1>
struct VirtActionInvoker1
{
typedef void (*Action)(void*, T1, const RuntimeMethod*);
static inline void Invoke (Il2CppMethodSlot slot, RuntimeObject* obj, T1 p1)
{
const VirtualInvokeData& invokeData = il2cpp_codegen_get_virtual_invoke_data(slot, obj);
((Action)invokeData.methodPtr)(obj, p1, invokeData.method);
}
};
// helloWorld
struct helloWorld_t934810763;
// UnityEngine.Object
struct Object_t631007953;
// UnityEngine.MonoBehaviour
struct MonoBehaviour_t3962482529;
// System.Void
struct Void_t1185182177;
// System.String
struct String_t;
// UnityEngine.UI.Text
struct Text_t1901882714;
// UnityEngine.Material
struct Material_t340375123;
// UnityEngine.Texture2D
struct Texture2D_t3840446185;
// UnityEngine.RectTransform
struct RectTransform_t3704657025;
// UnityEngine.CanvasRenderer
struct CanvasRenderer_t2598313366;
// UnityEngine.Canvas
struct Canvas_t3310196443;
// UnityEngine.Events.UnityAction
struct UnityAction_t3245792599;
// UnityEngine.Mesh
struct Mesh_t3648964284;
// UnityEngine.UI.VertexHelper
struct VertexHelper_t2453304189;
// UnityEngine.UI.CoroutineTween.TweenRunner`1<UnityEngine.UI.CoroutineTween.ColorTween>
struct TweenRunner_1_t3055525458;
// UnityEngine.UI.RectMask2D
struct RectMask2D_t3474889437;
// UnityEngine.UI.MaskableGraphic/CullStateChangedEvent
struct CullStateChangedEvent_t3661388177;
// UnityEngine.Vector3[]
struct Vector3U5BU5D_t1718750761;
// UnityEngine.UI.FontData
struct FontData_t746620069;
// UnityEngine.TextGenerator
struct TextGenerator_t3211863866;
// UnityEngine.UIVertex[]
struct UIVertexU5BU5D_t1981460040;
extern RuntimeClass* Object_t631007953_il2cpp_TypeInfo_var;
extern const uint32_t helloWorld_Update_m691499389_MetadataUsageId;
#ifndef RUNTIMEOBJECT_H
#define RUNTIMEOBJECT_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// System.Object
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // RUNTIMEOBJECT_H
#ifndef U3CMODULEU3E_T692745561_H
#define U3CMODULEU3E_T692745561_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// <Module>
struct U3CModuleU3E_t692745561
{
public:
public:
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // U3CMODULEU3E_T692745561_H
#ifndef STRING_T_H
#define STRING_T_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// System.String
struct String_t : public RuntimeObject
{
public:
// System.Int32 System.String::m_stringLength
int32_t ___m_stringLength_0;
// System.Char System.String::m_firstChar
Il2CppChar ___m_firstChar_1;
public:
inline static int32_t get_offset_of_m_stringLength_0() { return static_cast<int32_t>(offsetof(String_t, ___m_stringLength_0)); }
inline int32_t get_m_stringLength_0() const { return ___m_stringLength_0; }
inline int32_t* get_address_of_m_stringLength_0() { return &___m_stringLength_0; }
inline void set_m_stringLength_0(int32_t value)
{
___m_stringLength_0 = value;
}
inline static int32_t get_offset_of_m_firstChar_1() { return static_cast<int32_t>(offsetof(String_t, ___m_firstChar_1)); }
inline Il2CppChar get_m_firstChar_1() const { return ___m_firstChar_1; }
inline Il2CppChar* get_address_of_m_firstChar_1() { return &___m_firstChar_1; }
inline void set_m_firstChar_1(Il2CppChar value)
{
___m_firstChar_1 = value;
}
};
struct String_t_StaticFields
{
public:
// System.String System.String::Empty
String_t* ___Empty_5;
public:
inline static int32_t get_offset_of_Empty_5() { return static_cast<int32_t>(offsetof(String_t_StaticFields, ___Empty_5)); }
inline String_t* get_Empty_5() const { return ___Empty_5; }
inline String_t** get_address_of_Empty_5() { return &___Empty_5; }
inline void set_Empty_5(String_t* value)
{
___Empty_5 = value;
Il2CppCodeGenWriteBarrier((&___Empty_5), value);
}
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // STRING_T_H
#ifndef VALUETYPE_T3640485471_H
#define VALUETYPE_T3640485471_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// System.ValueType
struct ValueType_t3640485471 : public RuntimeObject
{
public:
public:
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
// Native definition for P/Invoke marshalling of System.ValueType
struct ValueType_t3640485471_marshaled_pinvoke
{
};
// Native definition for COM marshalling of System.ValueType
struct ValueType_t3640485471_marshaled_com
{
};
#endif // VALUETYPE_T3640485471_H
struct Il2CppArrayBounds;
#ifndef RUNTIMEARRAY_H
#define RUNTIMEARRAY_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// System.Array
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // RUNTIMEARRAY_H
#ifndef INTPTR_T_H
#define INTPTR_T_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// System.IntPtr
struct IntPtr_t
{
public:
// System.Void* System.IntPtr::m_value
void* ___m_value_0;
public:
inline static int32_t get_offset_of_m_value_0() { return static_cast<int32_t>(offsetof(IntPtr_t, ___m_value_0)); }
inline void* get_m_value_0() const { return ___m_value_0; }
inline void** get_address_of_m_value_0() { return &___m_value_0; }
inline void set_m_value_0(void* value)
{
___m_value_0 = value;
}
};
struct IntPtr_t_StaticFields
{
public:
// System.IntPtr System.IntPtr::Zero
intptr_t ___Zero_1;
public:
inline static int32_t get_offset_of_Zero_1() { return static_cast<int32_t>(offsetof(IntPtr_t_StaticFields, ___Zero_1)); }
inline intptr_t get_Zero_1() const { return ___Zero_1; }
inline intptr_t* get_address_of_Zero_1() { return &___Zero_1; }
inline void set_Zero_1(intptr_t value)
{
___Zero_1 = value;
}
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // INTPTR_T_H
#ifndef COLOR_T2555686324_H
#define COLOR_T2555686324_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// UnityEngine.Color
struct Color_t2555686324
{
public:
// System.Single UnityEngine.Color::r
float ___r_0;
// System.Single UnityEngine.Color::g
float ___g_1;
// System.Single UnityEngine.Color::b
float ___b_2;
// System.Single UnityEngine.Color::a
float ___a_3;
public:
inline static int32_t get_offset_of_r_0() { return static_cast<int32_t>(offsetof(Color_t2555686324, ___r_0)); }
inline float get_r_0() const { return ___r_0; }
inline float* get_address_of_r_0() { return &___r_0; }
inline void set_r_0(float value)
{
___r_0 = value;
}
inline static int32_t get_offset_of_g_1() { return static_cast<int32_t>(offsetof(Color_t2555686324, ___g_1)); }
inline float get_g_1() const { return ___g_1; }
inline float* get_address_of_g_1() { return &___g_1; }
inline void set_g_1(float value)
{
___g_1 = value;
}
inline static int32_t get_offset_of_b_2() { return static_cast<int32_t>(offsetof(Color_t2555686324, ___b_2)); }
inline float get_b_2() const { return ___b_2; }
inline float* get_address_of_b_2() { return &___b_2; }
inline void set_b_2(float value)
{
___b_2 = value;
}
inline static int32_t get_offset_of_a_3() { return static_cast<int32_t>(offsetof(Color_t2555686324, ___a_3)); }
inline float get_a_3() const { return ___a_3; }
inline float* get_address_of_a_3() { return &___a_3; }
inline void set_a_3(float value)
{
___a_3 = value;
}
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // COLOR_T2555686324_H
#ifndef VOID_T1185182177_H
#define VOID_T1185182177_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// System.Void
struct Void_t1185182177
{
public:
union
{
struct
{
};
uint8_t Void_t1185182177__padding[1];
};
public:
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // VOID_T1185182177_H
#ifndef BOOLEAN_T97287965_H
#define BOOLEAN_T97287965_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// System.Boolean
struct Boolean_t97287965
{
public:
// System.Boolean System.Boolean::m_value
bool ___m_value_0;
public:
inline static int32_t get_offset_of_m_value_0() { return static_cast<int32_t>(offsetof(Boolean_t97287965, ___m_value_0)); }
inline bool get_m_value_0() const { return ___m_value_0; }
inline bool* get_address_of_m_value_0() { return &___m_value_0; }
inline void set_m_value_0(bool value)
{
___m_value_0 = value;
}
};
struct Boolean_t97287965_StaticFields
{
public:
// System.String System.Boolean::TrueString
String_t* ___TrueString_5;
// System.String System.Boolean::FalseString
String_t* ___FalseString_6;
public:
inline static int32_t get_offset_of_TrueString_5() { return static_cast<int32_t>(offsetof(Boolean_t97287965_StaticFields, ___TrueString_5)); }
inline String_t* get_TrueString_5() const { return ___TrueString_5; }
inline String_t** get_address_of_TrueString_5() { return &___TrueString_5; }
inline void set_TrueString_5(String_t* value)
{
___TrueString_5 = value;
Il2CppCodeGenWriteBarrier((&___TrueString_5), value);
}
inline static int32_t get_offset_of_FalseString_6() { return static_cast<int32_t>(offsetof(Boolean_t97287965_StaticFields, ___FalseString_6)); }
inline String_t* get_FalseString_6() const { return ___FalseString_6; }
inline String_t** get_address_of_FalseString_6() { return &___FalseString_6; }
inline void set_FalseString_6(String_t* value)
{
___FalseString_6 = value;
Il2CppCodeGenWriteBarrier((&___FalseString_6), value);
}
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // BOOLEAN_T97287965_H
#ifndef OBJECT_T631007953_H
#define OBJECT_T631007953_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// UnityEngine.Object
struct Object_t631007953 : public RuntimeObject
{
public:
// System.IntPtr UnityEngine.Object::m_CachedPtr
intptr_t ___m_CachedPtr_0;
public:
inline static int32_t get_offset_of_m_CachedPtr_0() { return static_cast<int32_t>(offsetof(Object_t631007953, ___m_CachedPtr_0)); }
inline intptr_t get_m_CachedPtr_0() const { return ___m_CachedPtr_0; }
inline intptr_t* get_address_of_m_CachedPtr_0() { return &___m_CachedPtr_0; }
inline void set_m_CachedPtr_0(intptr_t value)
{
___m_CachedPtr_0 = value;
}
};
struct Object_t631007953_StaticFields
{
public:
// System.Int32 UnityEngine.Object::OffsetOfInstanceIDInCPlusPlusObject
int32_t ___OffsetOfInstanceIDInCPlusPlusObject_1;
public:
inline static int32_t get_offset_of_OffsetOfInstanceIDInCPlusPlusObject_1() { return static_cast<int32_t>(offsetof(Object_t631007953_StaticFields, ___OffsetOfInstanceIDInCPlusPlusObject_1)); }
inline int32_t get_OffsetOfInstanceIDInCPlusPlusObject_1() const { return ___OffsetOfInstanceIDInCPlusPlusObject_1; }
inline int32_t* get_address_of_OffsetOfInstanceIDInCPlusPlusObject_1() { return &___OffsetOfInstanceIDInCPlusPlusObject_1; }
inline void set_OffsetOfInstanceIDInCPlusPlusObject_1(int32_t value)
{
___OffsetOfInstanceIDInCPlusPlusObject_1 = value;
}
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
// Native definition for P/Invoke marshalling of UnityEngine.Object
struct Object_t631007953_marshaled_pinvoke
{
intptr_t ___m_CachedPtr_0;
};
// Native definition for COM marshalling of UnityEngine.Object
struct Object_t631007953_marshaled_com
{
intptr_t ___m_CachedPtr_0;
};
#endif // OBJECT_T631007953_H
#ifndef COMPONENT_T1923634451_H
#define COMPONENT_T1923634451_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// UnityEngine.Component
struct Component_t1923634451 : public Object_t631007953
{
public:
public:
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // COMPONENT_T1923634451_H
#ifndef BEHAVIOUR_T1437897464_H
#define BEHAVIOUR_T1437897464_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// UnityEngine.Behaviour
struct Behaviour_t1437897464 : public Component_t1923634451
{
public:
public:
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // BEHAVIOUR_T1437897464_H
#ifndef MONOBEHAVIOUR_T3962482529_H
#define MONOBEHAVIOUR_T3962482529_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// UnityEngine.MonoBehaviour
struct MonoBehaviour_t3962482529 : public Behaviour_t1437897464
{
public:
public:
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // MONOBEHAVIOUR_T3962482529_H
#ifndef UIBEHAVIOUR_T3495933518_H
#define UIBEHAVIOUR_T3495933518_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// UnityEngine.EventSystems.UIBehaviour
struct UIBehaviour_t3495933518 : public MonoBehaviour_t3962482529
{
public:
public:
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // UIBEHAVIOUR_T3495933518_H
#ifndef HELLOWORLD_T934810763_H
#define HELLOWORLD_T934810763_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// helloWorld
struct helloWorld_t934810763 : public MonoBehaviour_t3962482529
{
public:
// UnityEngine.UI.Text helloWorld::guiText
Text_t1901882714 * ___guiText_2;
// System.String helloWorld::someString
String_t* ___someString_3;
public:
inline static int32_t get_offset_of_guiText_2() { return static_cast<int32_t>(offsetof(helloWorld_t934810763, ___guiText_2)); }
inline Text_t1901882714 * get_guiText_2() const { return ___guiText_2; }
inline Text_t1901882714 ** get_address_of_guiText_2() { return &___guiText_2; }
inline void set_guiText_2(Text_t1901882714 * value)
{
___guiText_2 = value;
Il2CppCodeGenWriteBarrier((&___guiText_2), value);
}
inline static int32_t get_offset_of_someString_3() { return static_cast<int32_t>(offsetof(helloWorld_t934810763, ___someString_3)); }
inline String_t* get_someString_3() const { return ___someString_3; }
inline String_t** get_address_of_someString_3() { return &___someString_3; }
inline void set_someString_3(String_t* value)
{
___someString_3 = value;
Il2CppCodeGenWriteBarrier((&___someString_3), value);
}
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // HELLOWORLD_T934810763_H
#ifndef GRAPHIC_T1660335611_H
#define GRAPHIC_T1660335611_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// UnityEngine.UI.Graphic
struct Graphic_t1660335611 : public UIBehaviour_t3495933518
{
public:
// UnityEngine.Material UnityEngine.UI.Graphic::m_Material
Material_t340375123 * ___m_Material_4;
// UnityEngine.Color UnityEngine.UI.Graphic::m_Color
Color_t2555686324 ___m_Color_5;
// System.Boolean UnityEngine.UI.Graphic::m_RaycastTarget
bool ___m_RaycastTarget_6;
// UnityEngine.RectTransform UnityEngine.UI.Graphic::m_RectTransform
RectTransform_t3704657025 * ___m_RectTransform_7;
// UnityEngine.CanvasRenderer UnityEngine.UI.Graphic::m_CanvasRenderer
CanvasRenderer_t2598313366 * ___m_CanvasRenderer_8;
// UnityEngine.Canvas UnityEngine.UI.Graphic::m_Canvas
Canvas_t3310196443 * ___m_Canvas_9;
// System.Boolean UnityEngine.UI.Graphic::m_VertsDirty
bool ___m_VertsDirty_10;
// System.Boolean UnityEngine.UI.Graphic::m_MaterialDirty
bool ___m_MaterialDirty_11;
// UnityEngine.Events.UnityAction UnityEngine.UI.Graphic::m_OnDirtyLayoutCallback
UnityAction_t3245792599 * ___m_OnDirtyLayoutCallback_12;
// UnityEngine.Events.UnityAction UnityEngine.UI.Graphic::m_OnDirtyVertsCallback
UnityAction_t3245792599 * ___m_OnDirtyVertsCallback_13;
// UnityEngine.Events.UnityAction UnityEngine.UI.Graphic::m_OnDirtyMaterialCallback
UnityAction_t3245792599 * ___m_OnDirtyMaterialCallback_14;
// UnityEngine.UI.CoroutineTween.TweenRunner`1<UnityEngine.UI.CoroutineTween.ColorTween> UnityEngine.UI.Graphic::m_ColorTweenRunner
TweenRunner_1_t3055525458 * ___m_ColorTweenRunner_17;
// System.Boolean UnityEngine.UI.Graphic::<useLegacyMeshGeneration>k__BackingField
bool ___U3CuseLegacyMeshGenerationU3Ek__BackingField_18;
public:
inline static int32_t get_offset_of_m_Material_4() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_Material_4)); }
inline Material_t340375123 * get_m_Material_4() const { return ___m_Material_4; }
inline Material_t340375123 ** get_address_of_m_Material_4() { return &___m_Material_4; }
inline void set_m_Material_4(Material_t340375123 * value)
{
___m_Material_4 = value;
Il2CppCodeGenWriteBarrier((&___m_Material_4), value);
}
inline static int32_t get_offset_of_m_Color_5() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_Color_5)); }
inline Color_t2555686324 get_m_Color_5() const { return ___m_Color_5; }
inline Color_t2555686324 * get_address_of_m_Color_5() { return &___m_Color_5; }
inline void set_m_Color_5(Color_t2555686324 value)
{
___m_Color_5 = value;
}
inline static int32_t get_offset_of_m_RaycastTarget_6() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_RaycastTarget_6)); }
inline bool get_m_RaycastTarget_6() const { return ___m_RaycastTarget_6; }
inline bool* get_address_of_m_RaycastTarget_6() { return &___m_RaycastTarget_6; }
inline void set_m_RaycastTarget_6(bool value)
{
___m_RaycastTarget_6 = value;
}
inline static int32_t get_offset_of_m_RectTransform_7() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_RectTransform_7)); }
inline RectTransform_t3704657025 * get_m_RectTransform_7() const { return ___m_RectTransform_7; }
inline RectTransform_t3704657025 ** get_address_of_m_RectTransform_7() { return &___m_RectTransform_7; }
inline void set_m_RectTransform_7(RectTransform_t3704657025 * value)
{
___m_RectTransform_7 = value;
Il2CppCodeGenWriteBarrier((&___m_RectTransform_7), value);
}
inline static int32_t get_offset_of_m_CanvasRenderer_8() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_CanvasRenderer_8)); }
inline CanvasRenderer_t2598313366 * get_m_CanvasRenderer_8() const { return ___m_CanvasRenderer_8; }
inline CanvasRenderer_t2598313366 ** get_address_of_m_CanvasRenderer_8() { return &___m_CanvasRenderer_8; }
inline void set_m_CanvasRenderer_8(CanvasRenderer_t2598313366 * value)
{
___m_CanvasRenderer_8 = value;
Il2CppCodeGenWriteBarrier((&___m_CanvasRenderer_8), value);
}
inline static int32_t get_offset_of_m_Canvas_9() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_Canvas_9)); }
inline Canvas_t3310196443 * get_m_Canvas_9() const { return ___m_Canvas_9; }
inline Canvas_t3310196443 ** get_address_of_m_Canvas_9() { return &___m_Canvas_9; }
inline void set_m_Canvas_9(Canvas_t3310196443 * value)
{
___m_Canvas_9 = value;
Il2CppCodeGenWriteBarrier((&___m_Canvas_9), value);
}
inline static int32_t get_offset_of_m_VertsDirty_10() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_VertsDirty_10)); }
inline bool get_m_VertsDirty_10() const { return ___m_VertsDirty_10; }
inline bool* get_address_of_m_VertsDirty_10() { return &___m_VertsDirty_10; }
inline void set_m_VertsDirty_10(bool value)
{
___m_VertsDirty_10 = value;
}
inline static int32_t get_offset_of_m_MaterialDirty_11() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_MaterialDirty_11)); }
inline bool get_m_MaterialDirty_11() const { return ___m_MaterialDirty_11; }
inline bool* get_address_of_m_MaterialDirty_11() { return &___m_MaterialDirty_11; }
inline void set_m_MaterialDirty_11(bool value)
{
___m_MaterialDirty_11 = value;
}
inline static int32_t get_offset_of_m_OnDirtyLayoutCallback_12() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_OnDirtyLayoutCallback_12)); }
inline UnityAction_t3245792599 * get_m_OnDirtyLayoutCallback_12() const { return ___m_OnDirtyLayoutCallback_12; }
inline UnityAction_t3245792599 ** get_address_of_m_OnDirtyLayoutCallback_12() { return &___m_OnDirtyLayoutCallback_12; }
inline void set_m_OnDirtyLayoutCallback_12(UnityAction_t3245792599 * value)
{
___m_OnDirtyLayoutCallback_12 = value;
Il2CppCodeGenWriteBarrier((&___m_OnDirtyLayoutCallback_12), value);
}
inline static int32_t get_offset_of_m_OnDirtyVertsCallback_13() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_OnDirtyVertsCallback_13)); }
inline UnityAction_t3245792599 * get_m_OnDirtyVertsCallback_13() const { return ___m_OnDirtyVertsCallback_13; }
inline UnityAction_t3245792599 ** get_address_of_m_OnDirtyVertsCallback_13() { return &___m_OnDirtyVertsCallback_13; }
inline void set_m_OnDirtyVertsCallback_13(UnityAction_t3245792599 * value)
{
___m_OnDirtyVertsCallback_13 = value;
Il2CppCodeGenWriteBarrier((&___m_OnDirtyVertsCallback_13), value);
}
inline static int32_t get_offset_of_m_OnDirtyMaterialCallback_14() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_OnDirtyMaterialCallback_14)); }
inline UnityAction_t3245792599 * get_m_OnDirtyMaterialCallback_14() const { return ___m_OnDirtyMaterialCallback_14; }
inline UnityAction_t3245792599 ** get_address_of_m_OnDirtyMaterialCallback_14() { return &___m_OnDirtyMaterialCallback_14; }
inline void set_m_OnDirtyMaterialCallback_14(UnityAction_t3245792599 * value)
{
___m_OnDirtyMaterialCallback_14 = value;
Il2CppCodeGenWriteBarrier((&___m_OnDirtyMaterialCallback_14), value);
}
inline static int32_t get_offset_of_m_ColorTweenRunner_17() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___m_ColorTweenRunner_17)); }
inline TweenRunner_1_t3055525458 * get_m_ColorTweenRunner_17() const { return ___m_ColorTweenRunner_17; }
inline TweenRunner_1_t3055525458 ** get_address_of_m_ColorTweenRunner_17() { return &___m_ColorTweenRunner_17; }
inline void set_m_ColorTweenRunner_17(TweenRunner_1_t3055525458 * value)
{
___m_ColorTweenRunner_17 = value;
Il2CppCodeGenWriteBarrier((&___m_ColorTweenRunner_17), value);
}
inline static int32_t get_offset_of_U3CuseLegacyMeshGenerationU3Ek__BackingField_18() { return static_cast<int32_t>(offsetof(Graphic_t1660335611, ___U3CuseLegacyMeshGenerationU3Ek__BackingField_18)); }
inline bool get_U3CuseLegacyMeshGenerationU3Ek__BackingField_18() const { return ___U3CuseLegacyMeshGenerationU3Ek__BackingField_18; }
inline bool* get_address_of_U3CuseLegacyMeshGenerationU3Ek__BackingField_18() { return &___U3CuseLegacyMeshGenerationU3Ek__BackingField_18; }
inline void set_U3CuseLegacyMeshGenerationU3Ek__BackingField_18(bool value)
{
___U3CuseLegacyMeshGenerationU3Ek__BackingField_18 = value;
}
};
struct Graphic_t1660335611_StaticFields
{
public:
// UnityEngine.Material UnityEngine.UI.Graphic::s_DefaultUI
Material_t340375123 * ___s_DefaultUI_2;
// UnityEngine.Texture2D UnityEngine.UI.Graphic::s_WhiteTexture
Texture2D_t3840446185 * ___s_WhiteTexture_3;
// UnityEngine.Mesh UnityEngine.UI.Graphic::s_Mesh
Mesh_t3648964284 * ___s_Mesh_15;
// UnityEngine.UI.VertexHelper UnityEngine.UI.Graphic::s_VertexHelper
VertexHelper_t2453304189 * ___s_VertexHelper_16;
public:
inline static int32_t get_offset_of_s_DefaultUI_2() { return static_cast<int32_t>(offsetof(Graphic_t1660335611_StaticFields, ___s_DefaultUI_2)); }
inline Material_t340375123 * get_s_DefaultUI_2() const { return ___s_DefaultUI_2; }
inline Material_t340375123 ** get_address_of_s_DefaultUI_2() { return &___s_DefaultUI_2; }
inline void set_s_DefaultUI_2(Material_t340375123 * value)
{
___s_DefaultUI_2 = value;
Il2CppCodeGenWriteBarrier((&___s_DefaultUI_2), value);
}
inline static int32_t get_offset_of_s_WhiteTexture_3() { return static_cast<int32_t>(offsetof(Graphic_t1660335611_StaticFields, ___s_WhiteTexture_3)); }
inline Texture2D_t3840446185 * get_s_WhiteTexture_3() const { return ___s_WhiteTexture_3; }
inline Texture2D_t3840446185 ** get_address_of_s_WhiteTexture_3() { return &___s_WhiteTexture_3; }
inline void set_s_WhiteTexture_3(Texture2D_t3840446185 * value)
{
___s_WhiteTexture_3 = value;
Il2CppCodeGenWriteBarrier((&___s_WhiteTexture_3), value);
}
inline static int32_t get_offset_of_s_Mesh_15() { return static_cast<int32_t>(offsetof(Graphic_t1660335611_StaticFields, ___s_Mesh_15)); }
inline Mesh_t3648964284 * get_s_Mesh_15() const { return ___s_Mesh_15; }
inline Mesh_t3648964284 ** get_address_of_s_Mesh_15() { return &___s_Mesh_15; }
inline void set_s_Mesh_15(Mesh_t3648964284 * value)
{
___s_Mesh_15 = value;
Il2CppCodeGenWriteBarrier((&___s_Mesh_15), value);
}
inline static int32_t get_offset_of_s_VertexHelper_16() { return static_cast<int32_t>(offsetof(Graphic_t1660335611_StaticFields, ___s_VertexHelper_16)); }
inline VertexHelper_t2453304189 * get_s_VertexHelper_16() const { return ___s_VertexHelper_16; }
inline VertexHelper_t2453304189 ** get_address_of_s_VertexHelper_16() { return &___s_VertexHelper_16; }
inline void set_s_VertexHelper_16(VertexHelper_t2453304189 * value)
{
___s_VertexHelper_16 = value;
Il2CppCodeGenWriteBarrier((&___s_VertexHelper_16), value);
}
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // GRAPHIC_T1660335611_H
#ifndef MASKABLEGRAPHIC_T3839221559_H
#define MASKABLEGRAPHIC_T3839221559_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// UnityEngine.UI.MaskableGraphic
struct MaskableGraphic_t3839221559 : public Graphic_t1660335611
{
public:
// System.Boolean UnityEngine.UI.MaskableGraphic::m_ShouldRecalculateStencil
bool ___m_ShouldRecalculateStencil_19;
// UnityEngine.Material UnityEngine.UI.MaskableGraphic::m_MaskMaterial
Material_t340375123 * ___m_MaskMaterial_20;
// UnityEngine.UI.RectMask2D UnityEngine.UI.MaskableGraphic::m_ParentMask
RectMask2D_t3474889437 * ___m_ParentMask_21;
// System.Boolean UnityEngine.UI.MaskableGraphic::m_Maskable
bool ___m_Maskable_22;
// System.Boolean UnityEngine.UI.MaskableGraphic::m_IncludeForMasking
bool ___m_IncludeForMasking_23;
// UnityEngine.UI.MaskableGraphic/CullStateChangedEvent UnityEngine.UI.MaskableGraphic::m_OnCullStateChanged
CullStateChangedEvent_t3661388177 * ___m_OnCullStateChanged_24;
// System.Boolean UnityEngine.UI.MaskableGraphic::m_ShouldRecalculate
bool ___m_ShouldRecalculate_25;
// System.Int32 UnityEngine.UI.MaskableGraphic::m_StencilValue
int32_t ___m_StencilValue_26;
// UnityEngine.Vector3[] UnityEngine.UI.MaskableGraphic::m_Corners
Vector3U5BU5D_t1718750761* ___m_Corners_27;
public:
inline static int32_t get_offset_of_m_ShouldRecalculateStencil_19() { return static_cast<int32_t>(offsetof(MaskableGraphic_t3839221559, ___m_ShouldRecalculateStencil_19)); }
inline bool get_m_ShouldRecalculateStencil_19() const { return ___m_ShouldRecalculateStencil_19; }
inline bool* get_address_of_m_ShouldRecalculateStencil_19() { return &___m_ShouldRecalculateStencil_19; }
inline void set_m_ShouldRecalculateStencil_19(bool value)
{
___m_ShouldRecalculateStencil_19 = value;
}
inline static int32_t get_offset_of_m_MaskMaterial_20() { return static_cast<int32_t>(offsetof(MaskableGraphic_t3839221559, ___m_MaskMaterial_20)); }
inline Material_t340375123 * get_m_MaskMaterial_20() const { return ___m_MaskMaterial_20; }
inline Material_t340375123 ** get_address_of_m_MaskMaterial_20() { return &___m_MaskMaterial_20; }
inline void set_m_MaskMaterial_20(Material_t340375123 * value)
{
___m_MaskMaterial_20 = value;
Il2CppCodeGenWriteBarrier((&___m_MaskMaterial_20), value);
}
inline static int32_t get_offset_of_m_ParentMask_21() { return static_cast<int32_t>(offsetof(MaskableGraphic_t3839221559, ___m_ParentMask_21)); }
inline RectMask2D_t3474889437 * get_m_ParentMask_21() const { return ___m_ParentMask_21; }
inline RectMask2D_t3474889437 ** get_address_of_m_ParentMask_21() { return &___m_ParentMask_21; }
inline void set_m_ParentMask_21(RectMask2D_t3474889437 * value)
{
___m_ParentMask_21 = value;
Il2CppCodeGenWriteBarrier((&___m_ParentMask_21), value);
}
inline static int32_t get_offset_of_m_Maskable_22() { return static_cast<int32_t>(offsetof(MaskableGraphic_t3839221559, ___m_Maskable_22)); }
inline bool get_m_Maskable_22() const { return ___m_Maskable_22; }
inline bool* get_address_of_m_Maskable_22() { return &___m_Maskable_22; }
inline void set_m_Maskable_22(bool value)
{
___m_Maskable_22 = value;
}
inline static int32_t get_offset_of_m_IncludeForMasking_23() { return static_cast<int32_t>(offsetof(MaskableGraphic_t3839221559, ___m_IncludeForMasking_23)); }
inline bool get_m_IncludeForMasking_23() const { return ___m_IncludeForMasking_23; }
inline bool* get_address_of_m_IncludeForMasking_23() { return &___m_IncludeForMasking_23; }
inline void set_m_IncludeForMasking_23(bool value)
{
___m_IncludeForMasking_23 = value;
}
inline static int32_t get_offset_of_m_OnCullStateChanged_24() { return static_cast<int32_t>(offsetof(MaskableGraphic_t3839221559, ___m_OnCullStateChanged_24)); }
inline CullStateChangedEvent_t3661388177 * get_m_OnCullStateChanged_24() const { return ___m_OnCullStateChanged_24; }
inline CullStateChangedEvent_t3661388177 ** get_address_of_m_OnCullStateChanged_24() { return &___m_OnCullStateChanged_24; }
inline void set_m_OnCullStateChanged_24(CullStateChangedEvent_t3661388177 * value)
{
___m_OnCullStateChanged_24 = value;
Il2CppCodeGenWriteBarrier((&___m_OnCullStateChanged_24), value);
}
inline static int32_t get_offset_of_m_ShouldRecalculate_25() { return static_cast<int32_t>(offsetof(MaskableGraphic_t3839221559, ___m_ShouldRecalculate_25)); }
inline bool get_m_ShouldRecalculate_25() const { return ___m_ShouldRecalculate_25; }
inline bool* get_address_of_m_ShouldRecalculate_25() { return &___m_ShouldRecalculate_25; }
inline void set_m_ShouldRecalculate_25(bool value)
{
___m_ShouldRecalculate_25 = value;
}
inline static int32_t get_offset_of_m_StencilValue_26() { return static_cast<int32_t>(offsetof(MaskableGraphic_t3839221559, ___m_StencilValue_26)); }
inline int32_t get_m_StencilValue_26() const { return ___m_StencilValue_26; }
inline int32_t* get_address_of_m_StencilValue_26() { return &___m_StencilValue_26; }
inline void set_m_StencilValue_26(int32_t value)
{
___m_StencilValue_26 = value;
}
inline static int32_t get_offset_of_m_Corners_27() { return static_cast<int32_t>(offsetof(MaskableGraphic_t3839221559, ___m_Corners_27)); }
inline Vector3U5BU5D_t1718750761* get_m_Corners_27() const { return ___m_Corners_27; }
inline Vector3U5BU5D_t1718750761** get_address_of_m_Corners_27() { return &___m_Corners_27; }
inline void set_m_Corners_27(Vector3U5BU5D_t1718750761* value)
{
___m_Corners_27 = value;
Il2CppCodeGenWriteBarrier((&___m_Corners_27), value);
}
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // MASKABLEGRAPHIC_T3839221559_H
#ifndef TEXT_T1901882714_H
#define TEXT_T1901882714_H
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// UnityEngine.UI.Text
struct Text_t1901882714 : public MaskableGraphic_t3839221559
{
public:
// UnityEngine.UI.FontData UnityEngine.UI.Text::m_FontData
FontData_t746620069 * ___m_FontData_28;
// System.String UnityEngine.UI.Text::m_Text
String_t* ___m_Text_29;
// UnityEngine.TextGenerator UnityEngine.UI.Text::m_TextCache
TextGenerator_t3211863866 * ___m_TextCache_30;
// UnityEngine.TextGenerator UnityEngine.UI.Text::m_TextCacheForLayout
TextGenerator_t3211863866 * ___m_TextCacheForLayout_31;
// System.Boolean UnityEngine.UI.Text::m_DisableFontTextureRebuiltCallback
bool ___m_DisableFontTextureRebuiltCallback_33;
// UnityEngine.UIVertex[] UnityEngine.UI.Text::m_TempVerts
UIVertexU5BU5D_t1981460040* ___m_TempVerts_34;
public:
inline static int32_t get_offset_of_m_FontData_28() { return static_cast<int32_t>(offsetof(Text_t1901882714, ___m_FontData_28)); }
inline FontData_t746620069 * get_m_FontData_28() const { return ___m_FontData_28; }
inline FontData_t746620069 ** get_address_of_m_FontData_28() { return &___m_FontData_28; }
inline void set_m_FontData_28(FontData_t746620069 * value)
{
___m_FontData_28 = value;
Il2CppCodeGenWriteBarrier((&___m_FontData_28), value);
}
inline static int32_t get_offset_of_m_Text_29() { return static_cast<int32_t>(offsetof(Text_t1901882714, ___m_Text_29)); }
inline String_t* get_m_Text_29() const { return ___m_Text_29; }
inline String_t** get_address_of_m_Text_29() { return &___m_Text_29; }
inline void set_m_Text_29(String_t* value)
{
___m_Text_29 = value;
Il2CppCodeGenWriteBarrier((&___m_Text_29), value);
}
inline static int32_t get_offset_of_m_TextCache_30() { return static_cast<int32_t>(offsetof(Text_t1901882714, ___m_TextCache_30)); }
inline TextGenerator_t3211863866 * get_m_TextCache_30() const { return ___m_TextCache_30; }
inline TextGenerator_t3211863866 ** get_address_of_m_TextCache_30() { return &___m_TextCache_30; }
inline void set_m_TextCache_30(TextGenerator_t3211863866 * value)
{
___m_TextCache_30 = value;
Il2CppCodeGenWriteBarrier((&___m_TextCache_30), value);
}
inline static int32_t get_offset_of_m_TextCacheForLayout_31() { return static_cast<int32_t>(offsetof(Text_t1901882714, ___m_TextCacheForLayout_31)); }
inline TextGenerator_t3211863866 * get_m_TextCacheForLayout_31() const { return ___m_TextCacheForLayout_31; }
inline TextGenerator_t3211863866 ** get_address_of_m_TextCacheForLayout_31() { return &___m_TextCacheForLayout_31; }
inline void set_m_TextCacheForLayout_31(TextGenerator_t3211863866 * value)
{
___m_TextCacheForLayout_31 = value;
Il2CppCodeGenWriteBarrier((&___m_TextCacheForLayout_31), value);
}
inline static int32_t get_offset_of_m_DisableFontTextureRebuiltCallback_33() { return static_cast<int32_t>(offsetof(Text_t1901882714, ___m_DisableFontTextureRebuiltCallback_33)); }
inline bool get_m_DisableFontTextureRebuiltCallback_33() const { return ___m_DisableFontTextureRebuiltCallback_33; }
inline bool* get_address_of_m_DisableFontTextureRebuiltCallback_33() { return &___m_DisableFontTextureRebuiltCallback_33; }
inline void set_m_DisableFontTextureRebuiltCallback_33(bool value)
{
___m_DisableFontTextureRebuiltCallback_33 = value;
}
inline static int32_t get_offset_of_m_TempVerts_34() { return static_cast<int32_t>(offsetof(Text_t1901882714, ___m_TempVerts_34)); }
inline UIVertexU5BU5D_t1981460040* get_m_TempVerts_34() const { return ___m_TempVerts_34; }
inline UIVertexU5BU5D_t1981460040** get_address_of_m_TempVerts_34() { return &___m_TempVerts_34; }
inline void set_m_TempVerts_34(UIVertexU5BU5D_t1981460040* value)
{
___m_TempVerts_34 = value;
Il2CppCodeGenWriteBarrier((&___m_TempVerts_34), value);
}
};
struct Text_t1901882714_StaticFields
{
public:
// UnityEngine.Material UnityEngine.UI.Text::s_DefaultText
Material_t340375123 * ___s_DefaultText_32;
public:
inline static int32_t get_offset_of_s_DefaultText_32() { return static_cast<int32_t>(offsetof(Text_t1901882714_StaticFields, ___s_DefaultText_32)); }
inline Material_t340375123 * get_s_DefaultText_32() const { return ___s_DefaultText_32; }
inline Material_t340375123 ** get_address_of_s_DefaultText_32() { return &___s_DefaultText_32; }
inline void set_s_DefaultText_32(Material_t340375123 * value)
{
___s_DefaultText_32 = value;
Il2CppCodeGenWriteBarrier((&___s_DefaultText_32), value);
}
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // TEXT_T1901882714_H
// System.Boolean UnityEngine.Object::op_Inequality(UnityEngine.Object,UnityEngine.Object)
extern "C" bool Object_op_Inequality_m4071470834 (RuntimeObject * __this /* static, unused */, Object_t631007953 * p0, Object_t631007953 * p1, const RuntimeMethod* method) IL2CPP_METHOD_ATTR;
// System.Void UnityEngine.MonoBehaviour::.ctor()
extern "C" void MonoBehaviour__ctor_m1579109191 (MonoBehaviour_t3962482529 * __this, const RuntimeMethod* method) IL2CPP_METHOD_ATTR;
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
// System.Void helloWorld::Start()
extern "C" void helloWorld_Start_m260435389 (helloWorld_t934810763 * __this, const RuntimeMethod* method)
{
{
// }
return;
}
}
// System.Void helloWorld::Update()
extern "C" void helloWorld_Update_m691499389 (helloWorld_t934810763 * __this, const RuntimeMethod* method)
{
static bool s_Il2CppMethodInitialized;
if (!s_Il2CppMethodInitialized)
{
il2cpp_codegen_initialize_method (helloWorld_Update_m691499389_MetadataUsageId);
s_Il2CppMethodInitialized = true;
}
{
// if (guiText != null)
Text_t1901882714 * L_0 = __this->get_guiText_2();
IL2CPP_RUNTIME_CLASS_INIT(Object_t631007953_il2cpp_TypeInfo_var);
bool L_1 = Object_op_Inequality_m4071470834(NULL /*static, unused*/, L_0, (Object_t631007953 *)NULL, /*hidden argument*/NULL);
if (!L_1)
{
goto IL_001f;
}
}
{
// guiText.text = someString;
Text_t1901882714 * L_2 = __this->get_guiText_2();
String_t* L_3 = __this->get_someString_3();
NullCheck(L_2);
VirtActionInvoker1< String_t* >::Invoke(73 /* System.Void UnityEngine.UI.Text::set_text(System.String) */, L_2, L_3);
}
IL_001f:
{
// }
return;
}
}
// System.Void helloWorld::.ctor()
extern "C" void helloWorld__ctor_m1524645871 (helloWorld_t934810763 * __this, const RuntimeMethod* method)
{
{
MonoBehaviour__ctor_m1579109191(__this, /*hidden argument*/NULL);
return;
}
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
| 36.446312 | 202 | 0.816007 | [
"mesh",
"object"
] |
827d7d6bb2332df20e2d29a0b7cb5b8d98f3f39a | 2,604 | cpp | C++ | LifeBrush/Source/LifeBrush/Algorithm/tcods/Problem.cpp | timdecode/LifeBrush | dbc65bcc0ec77f9168e08cf7b39539af94420725 | [
"MIT"
] | 33 | 2019-04-23T23:00:09.000Z | 2021-11-09T11:44:09.000Z | LifeBrush/Source/LifeBrush/Algorithm/tcods/Problem.cpp | MyelinsheathXD/LifeBrush | dbc65bcc0ec77f9168e08cf7b39539af94420725 | [
"MIT"
] | 1 | 2019-10-09T15:57:56.000Z | 2020-03-05T20:01:01.000Z | LifeBrush/Source/LifeBrush/Algorithm/tcods/Problem.cpp | MyelinsheathXD/LifeBrush | dbc65bcc0ec77f9168e08cf7b39539af94420725 | [
"MIT"
] | 6 | 2019-04-25T00:10:55.000Z | 2021-04-12T05:16:28.000Z | #include "LifeBrush.h"
#include "Problem.h"
#include "HalfEdge.h"
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
namespace tcods
{
Problem :: Problem( void )
{}
Problem :: Problem( istream& in )
{
read( in );
}
void Problem :: solve( void ) const
{
Mesh mesh;
mesh.read( inputPath.c_str() );
int V = mesh.vertices.size();
for( vector<Singularity>::const_iterator v = singularities.begin();
v != singularities.end();
v ++ )
{
int i = v->first;
double k = v->second;
if( i < 0 || i >= V )
{
cerr << "Warning: singularity requested at vertex " << i+1 << " (mesh has only " << V << " vertices!)" << endl;
}
else
{
mesh.vertex( i )->k = k;
}
}
int G = mesh.nGenerators();
for( vector<Generator>::const_iterator g = generators.begin();
g != generators.end();
g ++ )
{
int i = g->first;
double k = g->second;
if( i < 0 || i >= G )
{
cerr << "Warning: additional holonomy requested around generator " << i+1 << " (mesh has only " << G << " generators!)" << endl;
}
else
{
mesh.generatorIndices[ i ] = k;
}
}
mesh.fieldAngle = fieldAngle;
mesh.computeTrivialConnection();
mesh.write( outputPath.c_str() );
}
void Problem :: read( istream& in )
{
singularities.clear();
generators.clear();
string s;
while( getline( in, s ))
{
stringstream line( s );
string token;
line >> token;
transform( token.begin(), token.end(), token.begin(), ::tolower );
if( token == "in" )
{
line >> inputPath;
}
else if( token == "out" )
{
line >> outputPath;
}
else if( token == "vertex" )
{
Singularity s;
line >> s.first >> s.second;
singularities.push_back( s );
}
else if( token == "generator" )
{
Generator g;
line >> g.first >> g.second;
generators.push_back( g );
}
else if( token == "angle" )
{
line >> fieldAngle;
}
}
}
}
| 23.25 | 140 | 0.422427 | [
"mesh",
"vector",
"transform"
] |
82865a082252f07257b5e7da7a85855d5dddff9a | 9,344 | hpp | C++ | mysql-server/storage/ndb/src/kernel/vm/TransientPool.hpp | silenc3502/MYSQL-Arch-Doc-Summary | fcc6bb65f72a385b9f56debc9b2c00cee5914bae | [
"MIT"
] | null | null | null | mysql-server/storage/ndb/src/kernel/vm/TransientPool.hpp | silenc3502/MYSQL-Arch-Doc-Summary | fcc6bb65f72a385b9f56debc9b2c00cee5914bae | [
"MIT"
] | null | null | null | mysql-server/storage/ndb/src/kernel/vm/TransientPool.hpp | silenc3502/MYSQL-Arch-Doc-Summary | fcc6bb65f72a385b9f56debc9b2c00cee5914bae | [
"MIT"
] | null | null | null | /*
Copyright (c) 2017, 2020, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
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, version 2.0, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef TRANSPOOL_HPP
#define TRANSPOOL_HPP
#include "TransientSlotPool.hpp"
#include "debugger/EventLogger.hpp"
#include "vm/ComposedSlotPool.hpp"
#include "vm/Slot.hpp"
#define JAM_FILE_ID 506
extern EventLogger * g_eventLogger;
#define SIZEOF_IN_WORDS(T) ((sizeof(T) + sizeof(Uint32) - 1) / sizeof(Uint32))
typedef ComposedSlotPool<StaticSlotPool,TransientSlotPool> TransientFastSlotPool;
template <typename T,
Uint32 Slot_size = SIZEOF_IN_WORDS(T)>
class TransientPool
: public TransientFastSlotPool
{
public:
typedef T Type;
void init(Uint32 type_id, const Pool_context &pool_ctx, Uint32 min_recs, Uint32 max_recs);
#if defined(VM_TRACE) || defined(ERROR_INSERT)
void resetMaxSize();
void setMaxSize(Uint32 max_recs);
#endif
bool startup();
bool seize(Ptr<T> &p);
void release(Ptr<T> p);
T *getPtr(Uint32 i) const;
void getPtr(Ptr<T> &p) const;
/**
* getValidPtr is often called on an operation record from a thread that
* doesn't own the operation record. A few examples are:
* 1) The current operation changing the record has its i-value written
* into the row header. This write only happens in LDM threads since
* Query threads are not allowed to change row data. In addition a linked
* list of operation records are used on this operation on all other
* changes or locked reads happening on this row.
*
* Even though the query thread cannot insert its own operation records
* into this list, it must be able to read those operation records
* efficiently to quickly find the correct version to use in the index
* or to know which record to read in key lookup based on the transaction
* id.
*
* see tuxReadAttrsOpt, tuxReadPk and before calling find_savepoint.
*
* 2) getValidPtr is also called on scan records in the TUX index. Each
* scan operation record in TUX insert its scan operation record into
* the index pages to ensure that it can resume its scan operation
* after returning from a real-time break. This writing happens both
* from Query threads and from LDM threads and is protected by a
* mutex on the index fragment record.
*
* 3) In DBACC we need to get the lock owners operation record when
* accessing a key in the hash table, this is only written by LDM thread,
* but needs to be readable from all query threads.
*
* All these accesses are in a sense insecure since the owner of the
* pool object is allowed to continue inserting and removing objects from
* pool concurrently with our call to getValidPtr.
*
* However the caller knows that the operation record that we want to get
* a valid pointer is not released. This means that we rely on that the
* translation of i-value is not changed as long as at least one operation
* record remains on a page. This must hold also for any intermediate
* pages used to find the page that houses the operation record.
*
* This principle must be upheld by the TransientPool. If this is no longer
* true one must use real pointers between all operation records in those
* lists. In addition the i-value stored in the row must be translated
* by a special map index that maps from a 32-bit value to a pointer to
* an operation record.
*/
bool getValidPtr(Ptr<T> &p) const;
bool getUncheckedPtrRO(Ptr<T> &p) const;
bool getUncheckedPtrRW(Ptr<T> &p) const;
Uint32 getUncheckedPtrs(Uint32* from, Ptr<T> ptrs[], Uint32 cnt) const;
Uint32 getEntrySize() const { return sizeof(Type); }
Uint32 getNoOfFree() const { return SlotPool::getNoOfFree(); }
Uint32 getSize() const { return SlotPool::getSize(); }
Uint32 getUsed() const { return SlotPool::getUsed(); }
Uint32 getUsedHi() const { return SlotPool::getUsedHi(); }
void resetUsedHi() { SlotPool::resetUsedHi(); }
static Uint64 getMemoryNeed(Uint32 entry_count);
private:
typedef TransientFastSlotPool SlotPool;
//typedef TransientSlotPool SlotPool;
typedef typename SlotPool::Type SlotType;
static void static_asserts()
{
NDB_STATIC_ASSERT( offsetof(T, m_magic) == 0);
NDB_STATIC_ASSERT( sizeof(T::m_magic) == 4);
}
};
template<typename T, Uint32 Slot_size> inline bool TransientPool<T, Slot_size>::seize(Ptr<T> &p)
{
Ptr<SlotType> slot;
if (unlikely(!SlotPool::seize(slot, Slot_size)))
{
return false;
}
p.i = slot.i;
#if defined VM_TRACE || defined ERROR_INSERT
memset(reinterpret_cast<void*>(slot.p), 0xF4, Slot_size * sizeof(Uint32));
#endif
p.p = new (slot.p) T;
if (unlikely(!Magic::match(p.p->m_magic, T::TYPE_ID)))
{
g_eventLogger->info("Magic::match failed in %s: "
"type_id %08x rg %u tid %u: "
"slot_size %u: ptr.i %u: ptr.p %p: "
"magic %08x expected %08x",
__func__,
T::TYPE_ID,
GET_RG(T::TYPE_ID),
GET_TID(T::TYPE_ID),
Slot_size,
p.i,
p.p,
p.p->m_magic,
Magic::make(T::TYPE_ID));
require(Magic::match(p.p->m_magic, T::TYPE_ID));
}
return true;
}
template<typename T, Uint32 Slot_size> inline void TransientPool<T, Slot_size>::release(Ptr<T> p)
{
Ptr<SlotType> slot;
slot.i = p.i;
p.p->~T();
#if defined VM_TRACE || defined ERROR_INSERT
memset(reinterpret_cast<void*>(p.p), 0xF4, Slot_size * sizeof(Uint32));
#endif
slot.p = new (p.p) SlotType;
SlotPool::release(slot, Slot_size);
}
template<typename T, Uint32 Slot_size> inline T *TransientPool<T, Slot_size>::getPtr(Uint32 i) const
{
Ptr<SlotType> p;
p.i = i;
require(SlotPool::getValidPtr(p, Magic::make(T::TYPE_ID), Slot_size));
return reinterpret_cast<T*>(p.p);
}
template<typename T, Uint32 Slot_size> inline void TransientPool<T, Slot_size>::getPtr(Ptr<T> &p) const
{
p.p = getPtr(p.i);
}
template<typename T, Uint32 Slot_size> inline bool TransientPool<T, Slot_size>::getValidPtr(Ptr<T> &p) const
{
Ptr<SlotType> slot;
slot.i = p.i;
if (unlikely(!SlotPool::getValidPtr(slot, Magic::make(T::TYPE_ID), Slot_size)))
{
return false;
}
p.p = reinterpret_cast<T*>(slot.p);
return true;
}
template<typename T, Uint32 Slot_size> inline bool TransientPool<T, Slot_size>::getUncheckedPtrRO(Ptr<T> &p) const
{
Ptr<SlotType> slot;
slot.i = p.i;
if (unlikely(!SlotPool::getUncheckedPtrRO(slot, Slot_size)))
{
return false;
}
p.p = reinterpret_cast<T*>(slot.p);
return true;
}
template<typename T, Uint32 Slot_size> inline bool TransientPool<T, Slot_size>::getUncheckedPtrRW(Ptr<T> &p) const
{
Ptr<SlotType> slot;
slot.i = p.i;
if (unlikely(!SlotPool::getUncheckedPtrRW(slot, Slot_size)))
{
return false;
}
p.p = reinterpret_cast<T*>(slot.p);
return true;
}
template<typename T, Uint32 Slot_size>
inline void TransientPool<T, Slot_size>::init(Uint32 type_id,
const Pool_context& pool_ctx,
Uint32 min_recs,
Uint32 max_recs)
{
SlotPool::init(type_id, Slot_size, &min_recs, max_recs, pool_ctx);
}
template<typename T, Uint32 Slot_size>
inline bool TransientPool<T, Slot_size>::startup()
{
return SlotPool::startup(Slot_size);
}
template<typename T, Uint32 Slot_size>
inline Uint64 TransientPool<T, Slot_size>::getMemoryNeed(Uint32 entry_count)
{
return SlotPool::getMemoryNeed(Slot_size, entry_count);
}
template<typename T, Uint32 Slot_size>
inline Uint32 TransientPool<T, Slot_size>::getUncheckedPtrs(Uint32* from, Ptr<T> ptrs[], Uint32 cnt) const
{
Ptr<SlotType>* slots = reinterpret_cast<Ptr<SlotType>*>(ptrs);
return SlotPool::getUncheckedPtrs(from, slots, cnt, Slot_size);
}
#if defined(VM_TRACE) || defined(ERROR_INSERT)
template<typename T, Uint32 Slot_size>
inline void TransientPool<T, Slot_size>::resetMaxSize()
{
SlotPool::resetMaxSize();
}
template<typename T, Uint32 Slot_size>
inline void TransientPool<T, Slot_size>::setMaxSize(Uint32 max_recs)
{
SlotPool::setMaxSize(max_recs);
}
#endif
#undef JAM_FILE_ID
#endif
| 35.12782 | 114 | 0.693386 | [
"object"
] |
82881e67f85b150b6569446fa757e1d8c3108c26 | 1,212 | hpp | C++ | core/Parser.hpp | arn-all/pafi | ec15ee30835eea5740953eb1fa9e52c0e5f24d8f | [
"MIT"
] | null | null | null | core/Parser.hpp | arn-all/pafi | ec15ee30835eea5740953eb1fa9e52c0e5f24d8f | [
"MIT"
] | null | null | null | core/Parser.hpp | arn-all/pafi | ec15ee30835eea5740953eb1fa9e52c0e5f24d8f | [
"MIT"
] | null | null | null | #ifndef PARSER_H
#define PARSER_H
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <random>
#include "rapidxml.hpp"
class Parser {
public:
// Loads config file, lammps scripts etc
Parser(std::string file, bool test);
// remove trailing whitespace - avoids RapidXML parsing bug
std::string rtws(std::string s);
std::string welcome_message();
void overwrite_xml(int nProcs);
void set_parameters();
std::vector<std::string> split_lines(std::string r);
std::vector<std::string> Script(std::string sn);
void seed(unsigned _random_seed);
std::string seed_str(bool reseed=true);
rapidxml::xml_document<> xml_doc;
rapidxml::xml_node<> * root_node;
rapidxml::xml_node<> * child_node;
std::map<std::string,std::string> parameters;
std::map<std::string,std::string> scripts;
std::vector<std::string> PathwayConfigurations;
double lowT,highT,Friction,startr,stopr,maxjump_thresh,redo_thresh;
int CoresPerWorker, nPlanes, TSteps, nRepeats, maxExtraRepeats;
unsigned random_seed;
std::string dump_dir;
bool seeded,loglammps,postMin,preMin,xml_success,spline_path,match_planes,real_coord;
private:
std::mt19937 rng;
};
#endif // PARSER_H
| 21.263158 | 85 | 0.762376 | [
"vector"
] |
8288a0388a970e0a8a5277c03a994a068a7e5499 | 16,739 | cpp | C++ | Sources/Internal/Render/Highlevel/StaticOcclusion.cpp | Serviak/dava.engine | d51a26173a3e1b36403f846ca3b2e183ac298a1a | [
"BSD-3-Clause"
] | 1 | 2020-11-14T10:18:24.000Z | 2020-11-14T10:18:24.000Z | Sources/Internal/Render/Highlevel/StaticOcclusion.cpp | Serviak/dava.engine | d51a26173a3e1b36403f846ca3b2e183ac298a1a | [
"BSD-3-Clause"
] | null | null | null | Sources/Internal/Render/Highlevel/StaticOcclusion.cpp | Serviak/dava.engine | d51a26173a3e1b36403f846ca3b2e183ac298a1a | [
"BSD-3-Clause"
] | 1 | 2020-09-05T21:16:17.000Z | 2020-09-05T21:16:17.000Z | #include "Render/RenderHelper.h"
#include "Render/Highlevel/StaticOcclusion.h"
#include "Render/Highlevel/StaticOcclusionRenderPass.h"
#include "Render/Highlevel/RenderBatchArray.h"
#include "Render/Highlevel/Camera.h"
#include "Render/Image/Image.h"
#include "Utils/StringFormat.h"
#include "Utils/Random.h"
#include "Time/SystemTimer.h"
#include "Render/Highlevel/Landscape.h"
#include "Render/Image/ImageSystem.h"
#include "Render/2D/Systems/RenderSystem2D.h"
namespace DAVA
{
StaticOcclusion::StaticOcclusion()
{
for (uint32 k = 0; k < 6; ++k)
{
cameras[k] = new Camera();
cameras[k]->SetupPerspective(95.0f, 1.0f, 1.0f, 2500.0f); //aspect of one is anyway required to avoid side occlusion errors
}
}
StaticOcclusion::~StaticOcclusion()
{
for (uint32 k = 0; k < 6; ++k)
{
SafeRelease(cameras[k]);
}
SafeDelete(staticOcclusionRenderPass);
}
void StaticOcclusion::StartBuildOcclusion(StaticOcclusionData* _currentData, RenderSystem* _renderSystem, Landscape* _landscape, uint32 _occlusionPixelThreshold, uint32 _occlusionPixelThresholdForSpeedtree)
{
lastInfoMessage = "Preparing to build static occlusion...";
staticOcclusionRenderPass = new StaticOcclusionRenderPass(PASS_FORWARD);
currentData = _currentData;
occlusionAreaRect = currentData->bbox;
cellHeightOffset = currentData->cellHeightOffset;
xBlockCount = currentData->sizeX;
yBlockCount = currentData->sizeY;
zBlockCount = currentData->sizeZ;
stats.buildStartTime = SystemTimer::GetNs();
stats.blockProcessingTime = stats.buildStartTime;
stats.buildDuration = 0.0;
stats.totalRenderPasses = 0;
currentFrameX = -1; // we increasing this, before rendering, so we will start from zero
currentFrameY = 0;
currentFrameZ = 0;
renderSystem = _renderSystem;
landscape = _landscape;
occlusionPixelThreshold = _occlusionPixelThreshold;
occlusionPixelThresholdForSpeedtree = _occlusionPixelThresholdForSpeedtree;
}
AABBox3 StaticOcclusion::GetCellBox(uint32 x, uint32 y, uint32 z)
{
Vector3 size = occlusionAreaRect.GetSize();
size.x /= xBlockCount;
size.y /= yBlockCount;
size.z /= zBlockCount;
Vector3 min(occlusionAreaRect.min.x + x * size.x,
occlusionAreaRect.min.y + y * size.y,
occlusionAreaRect.min.z + z * size.z);
if (cellHeightOffset)
{
min.z += cellHeightOffset[x + y * xBlockCount];
}
AABBox3 blockBBox(min, Vector3(min.x + size.x, min.y + size.y, min.z + size.z));
return blockBBox;
}
void StaticOcclusion::AdvanceToNextBlock()
{
currentFrameX++;
if (currentFrameX >= xBlockCount)
{
currentFrameX = 0;
currentFrameY++;
if (currentFrameY >= yBlockCount)
{
currentFrameY = 0;
currentFrameZ++;
}
}
}
bool StaticOcclusion::ProccessBlock()
{
if (!ProcessRecorderQueries())
{
RenderCurrentBlock();
UpdateInfoString();
return false;
}
if (renderPassConfigs.empty())
{
AdvanceToNextBlock();
auto currentTime = SystemTimer::GetNs();
stats.buildDuration += static_cast<double>(currentTime - stats.blockProcessingTime) / 1e+9;
stats.blockProcessingTime = currentTime;
if (currentFrameZ >= zBlockCount) // all blocks processed
{
UpdateInfoString();
return true;
}
BuildRenderPassConfigsForCurrentBlock();
}
RenderCurrentBlock();
UpdateInfoString();
return false;
}
uint32 StaticOcclusion::GetCurrentStepsCount()
{
return currentFrameX + (currentFrameY * xBlockCount) + (currentFrameZ * xBlockCount * yBlockCount);
}
uint32 StaticOcclusion::GetTotalStepsCount()
{
return xBlockCount * yBlockCount * zBlockCount;
}
const String& StaticOcclusion::GetInfoMessage() const
{
return lastInfoMessage;
}
void StaticOcclusion::BuildRenderPassConfigsForCurrentBlock()
{
const uint32 stepCount = 10;
const Vector3 viewDirections[6] =
{
Vector3(1.0f, 0.0f, 0.0f), // x 0
Vector3(0.0f, 1.0f, 0.0f), // y 1
Vector3(-1.0f, 0.0f, 0.0f), // -x 2
Vector3(0.0f, -1.0f, 0.0f), // -y 3
Vector3(0.0f, 0.0f, 1.0f), // +z 4
Vector3(0.0f, 0.0f, -1.0f), // -z 5
};
const uint32 effectiveSideCount[6] = { 3, 3, 3, 3, 1, 1 };
const uint32 effectiveSides[6][3] =
{
{ 0, 1, 3 },
{ 1, 0, 2 },
{ 2, 1, 3 },
{ 3, 0, 2 },
{ 4, 4, 4 },
{ 5, 5, 5 },
};
uint32 blockIndex = currentFrameX + currentFrameY * xBlockCount + currentFrameZ * xBlockCount * yBlockCount;
AABBox3 cellBox = GetCellBox(currentFrameX, currentFrameY, currentFrameZ);
Vector3 stepSize = cellBox.GetSize();
stepSize /= float32(stepCount);
DVASSERT(occlusionFrameResults.size() == 0); // previous results are processed - at least for now
for (uint32 side = 0; side < 6; ++side)
{
Vector3 startPosition, directionX, directionY;
if (side == 0) // +x
{
startPosition = Vector3(cellBox.max.x, cellBox.min.y, cellBox.min.z);
directionX = Vector3(0.0f, 1.0f, 0.0f);
directionY = Vector3(0.0f, 0.0f, 1.0f);
}
else if (side == 2) // -x
{
startPosition = Vector3(cellBox.min.x, cellBox.min.y, cellBox.min.z);
directionX = Vector3(0.0f, 1.0f, 0.0f);
directionY = Vector3(0.0f, 0.0f, 1.0f);
}
else if (side == 1) // +y
{
startPosition = Vector3(cellBox.min.x, cellBox.max.y, cellBox.min.z);
directionX = Vector3(1.0f, 0.0f, 0.0f);
directionY = Vector3(0.0f, 0.0f, 1.0f);
}
else if (side == 3) // -y
{
startPosition = Vector3(cellBox.min.x, cellBox.min.y, cellBox.min.z);
directionX = Vector3(1.0f, 0.0f, 0.0f);
directionY = Vector3(0.0f, 0.0f, 1.0f);
}
else if (side == 4) // +z
{
startPosition = Vector3(cellBox.min.x, cellBox.min.y, cellBox.max.z);
directionX = Vector3(1.0f, 0.0f, 0.0f);
directionY = Vector3(0.0f, 1.0f, 0.0f);
}
else if (side == 5) // -z
{
startPosition = Vector3(cellBox.min.x, cellBox.min.y, cellBox.min.z);
directionX = Vector3(1.0f, 0.0f, 0.0f);
directionY = Vector3(0.0f, 1.0f, 0.0f);
}
for (uint32 realSideIndex = 0; realSideIndex < effectiveSideCount[side]; ++realSideIndex)
{
for (uint32 stepX = 0; stepX <= stepCount; ++stepX)
{
for (uint32 stepY = 0; stepY <= stepCount; ++stepY)
{
Vector3 renderPosition = startPosition + directionX * float32(stepX) * stepSize + directionY * float32(stepY) * stepSize;
if (landscape)
{
Vector3 pointOnLandscape;
if (landscape->PlacePoint(renderPosition, pointOnLandscape))
{
if (renderPosition.z < pointOnLandscape.z)
continue;
}
}
RenderPassCameraConfig config;
config.blockIndex = blockIndex;
config.side = side;
config.position = renderPosition;
config.direction = viewDirections[effectiveSides[side][realSideIndex]];
if (effectiveSides[side][realSideIndex] == 4 || effectiveSides[side][realSideIndex] == 5)
{
config.up = Vector3(0.0f, 1.0f, 0.0f);
config.left = Vector3(1.0f, 0.0f, 0.0f);
}
else
{
config.up = Vector3(0.0f, 0.0f, 1.0f);
config.left = Vector3(1.0f, 0.0f, 0.0f);
}
renderPassConfigs.push_back(config);
}
}
}
}
stats.totalRenderPasses = renderPassConfigs.size();
}
bool StaticOcclusion::PerformRender(const RenderPassCameraConfig& rpc)
{
Camera* camera = cameras[rpc.side];
camera->SetPosition(rpc.position);
camera->SetLeft(rpc.left);
camera->SetUp(rpc.up);
camera->SetDirection(rpc.direction);
occlusionFrameResults.emplace_back();
StaticOcclusionFrameResult& res = occlusionFrameResults.back();
staticOcclusionRenderPass->DrawOcclusionFrame(renderSystem, camera, res, *currentData, rpc.blockIndex);
if (res.queryBuffer == rhi::InvalidHandle)
{
occlusionFrameResults.pop_back();
return false;
}
return true;
}
bool StaticOcclusion::RenderCurrentBlock()
{
uint64 renders = 0;
#if (SAVE_OCCLUSION_IMAGES)
uint64 maxRenders = 1;
#else
uint64 maxRenders = 48;
#endif
while ((renders < maxRenders) && !renderPassConfigs.empty())
{
auto i = renderPassConfigs.begin();
std::advance(i, DAVA::Random::Instance()->Rand() % renderPassConfigs.size());
PerformRender(*i);
renderPassConfigs.erase(i);
++renders;
}
return renderPassConfigs.empty();
}
void StaticOcclusion::MarkQueriesAsCompletedForObjectInBlock(uint16 objectIndex, uint32 blockIndex)
{
for (auto& ofr : occlusionFrameResults)
{
if (ofr.blockIndex == blockIndex)
{
for (auto& req : ofr.frameRequests)
{
if ((req != nullptr) && (req->GetStaticOcclusionIndex() == objectIndex))
req = nullptr;
}
}
}
}
bool StaticOcclusion::ProcessRecorderQueries()
{
auto fr = occlusionFrameResults.begin();
while (fr != occlusionFrameResults.end())
{
uint32 processedRequests = 0;
uint32 index = 0;
for (auto& req : fr->frameRequests)
{
if (req == nullptr)
{
++processedRequests;
++index;
continue;
}
DVASSERT(req->GetStaticOcclusionIndex() != INVALID_STATIC_OCCLUSION_INDEX);
if (rhi::QueryIsReady(fr->queryBuffer, index))
{
int32& samplesPassed = fr->samplesPassed[req->GetStaticOcclusionIndex()];
samplesPassed += rhi::QueryValue(fr->queryBuffer, index);
uint32 threshold = req->GetType() != RenderObject::TYPE_SPEED_TREE ?
occlusionPixelThreshold :
occlusionPixelThresholdForSpeedtree;
if (static_cast<uint32>(samplesPassed) > threshold)
{
bool alreadyVisible = currentData->IsObjectVisibleFromBlock(fr->blockIndex, req->GetStaticOcclusionIndex());
DVASSERT(!alreadyVisible);
currentData->EnableVisibilityForObject(fr->blockIndex, req->GetStaticOcclusionIndex());
MarkQueriesAsCompletedForObjectInBlock(req->GetStaticOcclusionIndex(), fr->blockIndex);
}
++processedRequests;
req = nullptr;
}
++index;
}
if (processedRequests == static_cast<uint32>(fr->frameRequests.size()))
{
rhi::DeleteQueryBuffer(fr->queryBuffer, true);
fr = occlusionFrameResults.erase(fr);
}
else
{
++fr;
}
}
return occlusionFrameResults.empty();
}
// helper function, see implementation below
namespace helper
{
String FormatTime(double fSeconds);
}
void StaticOcclusion::UpdateInfoString()
{
auto totalBlocks = xBlockCount * yBlockCount * zBlockCount;
auto blockIndex = currentFrameX + currentFrameY * xBlockCount + currentFrameZ * xBlockCount * yBlockCount;
if (blockIndex >= totalBlocks)
{
lastInfoMessage = Format("Completed. Total time spent: %s", helper::FormatTime(stats.buildDuration).c_str());
}
else
{
float32 fTotalRenders = static_cast<float32>(stats.totalRenderPasses);
float32 fRemainingRenders = static_cast<float32>(renderPassConfigs.size());
float32 rendersCompleted = (stats.totalRenderPasses == 0) ? 1.0f : (1.0f - fRemainingRenders / fTotalRenders);
auto averageTime = (blockIndex == 0) ? 0.0 : (stats.buildDuration / static_cast<double>(blockIndex));
auto remainingBlocks = totalBlocks - blockIndex;
auto remainingTime = static_cast<double>(remainingBlocks) * averageTime;
lastInfoMessage = Format("Processing block: %u from %u (%d%% completed) \n\nTotal time spent: %s\nEstimated remaining time: %s",
blockIndex + 1, totalBlocks, static_cast<int>(100.0f * rendersCompleted),
helper::FormatTime(stats.buildDuration).c_str(), helper::FormatTime(remainingTime).c_str());
}
}
StaticOcclusionData::StaticOcclusionData()
: sizeX(5)
, sizeY(5)
, sizeZ(2)
, blockCount(0)
, objectCount(0)
, cellHeightOffset(0)
{
}
StaticOcclusionData::~StaticOcclusionData()
{
SafeDeleteArray(cellHeightOffset);
}
StaticOcclusionData& StaticOcclusionData::operator=(const StaticOcclusionData& other)
{
sizeX = other.sizeX;
sizeY = other.sizeY;
sizeZ = other.sizeZ;
objectCount = other.objectCount;
blockCount = other.blockCount;
bbox = other.bbox;
dataHolder = other.dataHolder;
SafeDeleteArray(cellHeightOffset);
if (other.cellHeightOffset)
{
cellHeightOffset = new float32[sizeX * sizeY];
memcpy(cellHeightOffset, other.cellHeightOffset, sizeof(float32) * sizeX * sizeY);
}
return *this;
}
void StaticOcclusionData::Init(uint32 _sizeX, uint32 _sizeY, uint32 _sizeZ, uint32 _objectCount,
const AABBox3& _bbox, const float32* _cellHeightOffset)
{
SafeDeleteArray(cellHeightOffset);
objectCount = _objectCount;
sizeX = _sizeX;
sizeY = _sizeY;
sizeZ = _sizeZ;
blockCount = sizeX * sizeY * sizeZ;
bbox = _bbox;
objectCount += (32 - objectCount & 31);
auto numElements = blockCount * objectCount / 32;
dataHolder.resize(numElements);
std::fill(dataHolder.begin(), dataHolder.end(), 0);
if (_cellHeightOffset)
{
cellHeightOffset = new float32[sizeX * sizeY];
memcpy(cellHeightOffset, _cellHeightOffset, sizeof(float32) * sizeX * sizeY);
}
}
bool StaticOcclusionData::IsObjectVisibleFromBlock(uint32 blockIndex, uint32 objectIndex) const
{
auto objIndex = 1 << (objectIndex & 31);
auto index = (blockIndex * objectCount / 32) + (objectIndex / 32);
DVASSERT(index < dataHolder.size());
return (dataHolder[index] & objIndex) != 0;
}
void StaticOcclusionData::EnableVisibilityForObject(uint32 blockIndex, uint32 objectIndex)
{
auto index = (blockIndex * objectCount / 32) + (objectIndex / 32);
DVASSERT(index < dataHolder.size());
dataHolder[index] |= 1 << (objectIndex & 31);
}
void StaticOcclusionData::DisableVisibilityForObject(uint32 blockIndex, uint32 objectIndex)
{
auto index = (blockIndex * objectCount / 32) + (objectIndex / 32);
DVASSERT(index < dataHolder.size());
dataHolder[index] &= ~(1 << (objectIndex & 31));
}
uint32* StaticOcclusionData::GetBlockVisibilityData(uint32 blockIndex)
{
auto index = blockIndex * objectCount / 32;
DVASSERT(index < dataHolder.size());
return dataHolder.data() + index;
}
const uint32* StaticOcclusionData::GetData() const
{
return dataHolder.data();
}
void StaticOcclusionData::SetData(const uint32* _data, uint32 dataSize)
{
auto elements = dataSize / sizeof(uint32);
dataHolder.resize(elements);
std::copy(_data, _data + elements, dataHolder.begin());
}
namespace helper
{
String FormatTime(double fSeconds)
{
uint64 seconds = static_cast<uint64>(fSeconds);
uint64 minutes = seconds / 60;
seconds -= minutes * 60;
uint64 hours = minutes / 60;
minutes -= hours * 60;
char buffer[1024] = {};
sprintf(buffer, "%02llu:%02llu:%02llu", hours, minutes, seconds);
return String(buffer);
}
}
};
| 32.439922 | 207 | 0.59454 | [
"render"
] |
828dd94c6b6a61dd64d58fd4fc681dda3a6b25d2 | 1,961 | cpp | C++ | unranged/1568.cpp | Taowyoo/LeetCodeLog | cb05798538dd10675bf81011a419d0e33d85e4e0 | [
"MIT"
] | null | null | null | unranged/1568.cpp | Taowyoo/LeetCodeLog | cb05798538dd10675bf81011a419d0e33d85e4e0 | [
"MIT"
] | null | null | null | unranged/1568.cpp | Taowyoo/LeetCodeLog | cb05798538dd10675bf81011a419d0e33d85e4e0 | [
"MIT"
] | null | null | null | // Time: O((m*n)^2)
// Space: O(m*n)
class Solution {
public:
vector<int> dx = {1, -1, 0, 0};
vector<int> dy = {0, 0, 1, -1};
void dfs(int x, int y, vector<vector<int>> &grid, vector<vector<int>> & vis)
{
int n = grid.size();
int m = grid[0].size();
vis[x][y] = 1;
for (int a = 0; a < 4; a++)
{
int nx = x + dx[a];
int ny = y + dy[a];
if (nx >= 0 and ny >= 0 and nx < n and ny < m and !vis[nx][ny] and grid[nx][ny])
{
dfs(nx, ny, grid, vis);
}
}
}
int count_islands(vector<vector<int>> & grid)
{
int islands = 0;
int n = grid.size();
int m = grid[0].size();
vector<vector<int>> vis(n, vector<int> (m, 0));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (!vis[i][j] and grid[i][j])
{
dfs(i, j, grid, vis);
islands ++;
}
}
}
return islands;
}
int minDays(vector<vector<int>>& grid) {
int islands = count_islands(grid);
int n = grid.size();
int m = grid[0].size();
// check for 0 ans
if (islands > 1 or islands == 0)
{
return 0;
}
else
{
// check for 1 ans
for (int i = 0 ; i < n; i ++)
{
for (int j = 0; j < m; j++)
{
if (grid[i][j])
{
grid[i][j] = 0;
// remove this block
islands = count_islands(grid);
// add back the block
grid[i][j] = 1;
if (islands > 1 or islands == 0)
return 1;
}
}
}
}
// else
return 2;
}
}; | 26.5 | 92 | 0.345742 | [
"vector"
] |
8292451f1945570b748bd2dfff36a825208f21d4 | 7,870 | cpp | C++ | main/src/Objects/CNodePoint2DSlope1.cpp | eapcivil/EXUDYN | 52bddc8c258cda07e51373f68e1198b66c701d03 | [
"BSD-3-Clause-Open-MPI"
] | 1 | 2020-10-06T08:06:25.000Z | 2020-10-06T08:06:25.000Z | main/src/Objects/CNodePoint2DSlope1.cpp | eapcivil/EXUDYN | 52bddc8c258cda07e51373f68e1198b66c701d03 | [
"BSD-3-Clause-Open-MPI"
] | null | null | null | main/src/Objects/CNodePoint2DSlope1.cpp | eapcivil/EXUDYN | 52bddc8c258cda07e51373f68e1198b66c701d03 | [
"BSD-3-Clause-Open-MPI"
] | null | null | null | /** ***********************************************************************************************
* @brief Implementation for NodePoint2DSlope1
*
* @author Gerstmayr Johannes
* @date 2019-06-15 (generated)
* @pre ...
*
* @copyright This file is part of Exudyn. Exudyn is free software: you can redistribute it and/or modify it under the terms of the Exudyn license. See 'LICENSE.txt' for more details.
* @note Bug reports, support and further information:
* - email: johannes.gerstmayr@uibk.ac.at
* - weblink: missing
*
*
* *** Example code ***
*
************************************************************************************************ */
#include "Main/CSystemData.h"
#include "Autogenerated/CNodePoint2DSlope1.h" //includes ReleaseAssert.h, BasicDefinitions.h, ResizeableArray.h, LinkedDataVector.h
//for CallFunction(...)
#include "Main/MainSystem.h"
#include "Pymodules/PybindUtilities.h"
#include "Autogenerated/MainNodePoint2DSlope1.h"
Vector3D CNodePoint2DSlope1::GetPosition(ConfigurationType configuration) const
{
//p = pRef + u = reference position + displacement
LinkedDataVector pRef2D = GetReferenceCoordinateVector();
Vector3D pRef({ pRef2D[0], pRef2D[1], 0. });
if (configuration == ConfigurationType::Reference) { return pRef; }
LinkedDataVector u2D = GetCoordinateVector(configuration);
Vector3D displacement({ u2D[0], u2D[1], 0. });
return pRef + displacement;
}
Vector3D CNodePoint2DSlope1::GetVelocity(ConfigurationType configuration) const
{
LinkedDataVector u2D_t = GetCoordinateVector_t(configuration);
return Vector3D({ u2D_t[0], u2D_t[1], 0. });
}
//! AUTO: provide position jacobian of node; derivative of 3D Position with respect to 4 coordinates ux,uy and x/y "displacements" of slopex
void CNodePoint2DSlope1::GetPositionJacobian(Matrix& value) const
{
//derivative of position with respect to all coordinates
value.SetMatrix(3, 4, {1.,0.,0.,0., 0.,1.,0.,0., 0.,0.,0.,0.});
}
Matrix3D CNodePoint2DSlope1::GetRotationMatrix(ConfigurationType configuration) const
{
//slope vector = pRef' + u'
LinkedDataVector vRef = GetCoordinateVector(ConfigurationType::Reference);
Real phi;
if (!(configuration == ConfigurationType::Reference))
{
LinkedDataVector v = GetCoordinateVector(configuration);
phi = atan2(vRef[3] + v[3], vRef[2] + v[2]); //slope vector [1,0] is defined as zero angle
}
else
{ //Reference configuration:
phi = atan2(vRef[3], vRef[2]); //slope vector [0,1] is defined as zero angle
}
//phi is the total angle
return Matrix3D(3,3,{ cos(phi),-sin(phi),0., sin(phi),cos(phi),0., 0.,0.,1.});
}
//! AUTO: return configuration dependent velocity of node; returns always a 3D Vector
Vector3D CNodePoint2DSlope1::GetAngularVelocity(ConfigurationType configuration) const
{
//atan2(y,x) = atan(y/x)
//diff(atan2(y,x),x) = -y/(x^2+y^2)
//diff(atan2(y,x),y) = x/(x^2+y^2)
LinkedDataVector ref = GetCoordinateVector(ConfigurationType::Reference);
LinkedDataVector u = GetCoordinateVector(configuration);
LinkedDataVector u_t = GetCoordinateVector_t(configuration);
Real x = u[2]; //x-slopex
Real y = u[3]; //y-slopex
if (configuration != ConfigurationType::Reference)
{
x += ref[2];
y += ref[3];
}
//SysError("CNodePoint2DSlope1::GetAngularVelocity: check if computation of angular velocity is correct!");
//Real diffX = -y / (x*x + y * y)*u_t[2];
//Real diffY = x / (x*x + y * y)*u_t[3];
//return Vector3D({ 0., 0., atan2(diffY,diffX) }); //rotation ignored
return Vector3D({ 0., 0., (-y*u_t[2] + x*u_t[3]) / (x*x + y*y) });
}
void CNodePoint2DSlope1::GetRotationJacobian(Matrix& value) const
{
//only in current configuration!
LinkedDataVector ref = GetCoordinateVector(ConfigurationType::Reference);
LinkedDataVector u = GetCurrentCoordinateVector();
Real x = u[2] + ref[2]; //x-slopex
Real y = u[3] + ref[3]; //y-slopex
value.SetMatrix(3, 4, { 0.,0.,0.,0., 0.,0.,0.,0., 0.,0.,-y / (x*x + y*y), x / (x*x + y*y) });
}
//! provide according output variable in "value"
void CNodePoint2DSlope1::GetOutputVariable(OutputVariableType variableType, ConfigurationType configuration, Vector& value) const
{
switch (variableType)
{
case OutputVariableType::Position: value.CopyFrom(GetPosition(configuration)); break;
case OutputVariableType::Displacement: value.CopyFrom(GetPosition(configuration) - GetPosition(ConfigurationType::Reference)); break;
case OutputVariableType::Velocity: value.CopyFrom(GetVelocity(configuration)); break;
case OutputVariableType::Coordinates:
{
if (IsConfigurationInitialCurrentReferenceVisualization(configuration)) //((Index)configuration & ((Index)ConfigurationType::Current + (Index)ConfigurationType::Initial + (Index)ConfigurationType::Reference + (Index)ConfigurationType::Visualization))
{
value = GetCoordinateVector(configuration);
}
else
{
PyError("CNodePoint2DSlope1::GetOutputVariable: invalid configuration");
}
break;
}
case OutputVariableType::Coordinates_t:
{
if (IsConfigurationInitialCurrentVisualization(configuration)) //((Index)configuration & ((Index)ConfigurationType::Current + (Index)ConfigurationType::Initial + (Index)ConfigurationType::Visualization))
{
value = GetCoordinateVector_t(configuration);
}
else
{
PyError("CNodePoint2DSlope1::GetOutputVariable: invalid configuration");
}
break;
}
default:
SysError("CNodePoint2DSlope1::GetOutputVariable failed"); //error should not occur, because types are checked!
}
}
//! call a certain function of object (autogenerated in future!)
py::object MainNodePoint2DSlope1::CallFunction(STDstring functionName, py::dict args) const
{
//these calls should be automated by python script ...
if (functionName == "GetTypeName")
{
return py::str(GetTypeName());
}
else if (functionName == "GetNodeType")
{
return py::cast(GetCNodePoint2DSlope1()->GetType());
}
else if (functionName == "GetNodeGroup")
{
return py::cast(GetCNodePoint2DSlope1()->GetNodeGroup());
}
else if (functionName == "GetNumberOfODE2Coordinates")
{
return py::int_(GetCNodePoint2DSlope1()->GetNumberOfODE2Coordinates());
}
else if (functionName == "GetGlobalODE2CoordinateIndex")
{
return py::int_(GetCNodePoint2DSlope1()->GetGlobalODE2CoordinateIndex());
}
else if (functionName == "GetCurrentCoordinateVector")
{
LinkedDataVector v(GetCNodePoint2DSlope1()->GetCurrentCoordinateVector());
return py::array_t<Real>(v.NumberOfItems(), v.GetDataPointer());
}
else if (functionName == "GetInitialCoordinateVector")
{
LinkedDataVector v(GetCNodePoint2DSlope1()->GetInitialCoordinateVector());
return py::array_t<Real>(v.NumberOfItems(), v.GetDataPointer());
}
else if (functionName == "GetCurrentCoordinateVector_t")
{
LinkedDataVector v(GetCNodePoint2DSlope1()->GetCurrentCoordinateVector_t());
return py::array_t<Real>(v.NumberOfItems(), v.GetDataPointer());
}
else if (functionName == "GetInitialCoordinateVector_t")
{
LinkedDataVector v(GetCNodePoint2DSlope1()->GetInitialCoordinateVector_t());
return py::array_t<Real>(v.NumberOfItems(), v.GetDataPointer());
}
else if (functionName == "GetCurrentPosition")
{
Vector3D v = GetCNodePoint2DSlope1()->GetPosition(ConfigurationType::Current);
return py::array_t<Real>(v.NumberOfItems(), v.GetDataPointer());
}
//before doing so, use : https://pybind11.readthedocs.io/en/master/advanced/pycpp/numpy.html?highlight=numpy#f
// and matrix example : https://github.com/pybind/pybind11/blob/master/tests/test_buffers.cpp
//else if (functionName == "GetCurrentRotationMatrix")
//{
// Matrix3D m = GetCNodeRigidBody2D()->GetRotationMatrix(ConfigurationType::Current);
// return py::array_t<Real>(m.NumberOfItems(), m.GetDataPointer());
//}
PyError(STDstring("MainNodePoint2DSlope1::CallFunction called with invalid functionName '" + functionName + "'"));
return py::int_(EXUstd::InvalidIndex);
}
| 38.203883 | 252 | 0.715375 | [
"object",
"vector",
"3d"
] |
829333e833eaa706962b2a765617bf222a60b96e | 10,063 | cpp | C++ | GA/old_GA.cpp | donRumata03/PowerfulGA | e4e2370287a7b654caf92adac8a64a39e23468c9 | [
"MIT"
] | 3 | 2020-04-11T10:48:01.000Z | 2021-02-09T11:43:12.000Z | GA/old_GA.cpp | donRumata03/PowerfulGA | e4e2370287a7b654caf92adac8a64a39e23468c9 | [
"MIT"
] | 6 | 2020-12-03T15:37:45.000Z | 2020-12-09T11:02:37.000Z | GA/old_GA.cpp | donRumata03/PowerfulGA | e4e2370287a7b654caf92adac8a64a39e23468c9 | [
"MIT"
] | 1 | 2021-04-25T21:50:09.000Z | 2021-04-25T21:50:09.000Z | #include "old_GA.h"
namespace GA {
// TODO: add possibility to run 2 GA's at once!!!
Population p;
std::vector<double> fitnesses;
volatile bool thread_count_time = false;
std::vector<bool> threads_ready;
volatile bool threads_work_collected = false;
inline bool check_threads() { return std::all_of(threads_ready.begin(), threads_ready.end(), [](const bool stuff) { return stuff; }); }
bool thread_task_ready = false;
void count_fitness_function_thread(
const size_t thread_index, const std::function< double(std::vector<double>&) >& fitness_function, const std::pair<size_t, size_t>& range)
{
// cout << "Thread " << thread_index << " started working! " << range << "\n";
while(!thread_task_ready)
{
while(!thread_count_time && !thread_task_ready) { /*std::this_thread::yield();*/ }
if (thread_task_ready)
{
break;
}
for(size_t task_index = range.first; task_index < range.second; task_index++)
{
fitnesses[task_index] = fitness_function(p[task_index]);
}
threads_ready[thread_index] = true;
while (!threads_work_collected) { /*std::this_thread::yield();*/ }
}
}
std::pair<double, Genome> ga_optimize (const std::function<double (std::vector<double> &)> &fitness_function,
const std::vector<std::pair<double, double>> &point_ranges, const single_run_GA_params& params,
const std::function<void (double, double, const Genome &)> &informer,
std::vector<double> *to_store_fitness,
const std::function<void (const Population &, size_t, logging_type)> *logger)
{
// Unpacking parameters:
/*
auto population_size = params.population_size;
auto epoch_num = params.epoch_num;
auto mutation_percent_sigma = params.mutation_percent_sigma;
bool allow_multithreading = params.allow_multithreading;
size_t thread_number = params.threads;
*/
/*
bool best_genome_guarantee = params.best_genome_percent != 0;
auto best_genome_number = size_t(std::round(params.best_genome_percent * population_size));
*/
/*
size_t non_best_number = population_size - best_genome_number;
double hazing_percent = params.hazing_percent;
auto all_elite_number = size_t(cut(std::round(hazing_percent * non_best_number), 0, population_size));
auto hyper_elite_number = size_t(cut(std::round(hazing_percent * all_elite_number), 0, population_size));
size_t usual_elite_number = cut(all_elite_number - hyper_elite_number, 0, population_size);
size_t child_number = non_best_number - all_elite_number;
auto matting_mode = params.crossover_mode;
*/
/*
std::cout << "People distribution: Non best: " << non_best_number << " Childs: " << child_number <<
" All elite: " << all_elite_number << " Usual elite: " << usual_elite_number << " Hyper elite: " << hyper_elite_number
<< " Best genome: " << best_genome_number << std::endl;
*/
/*
double temp_pop = population_size * parents_percent;
size_t pop_parents_number = (size_t(temp_pop) % 2) ? size_t(temp_pop) + 1 : size_t(temp_pop);
if constexpr (DEBUG_GA) cout << "Replications per iteration: " << pop_parents_number << endl << endl;
*/
/**
* Parameter Interpretation and other preparations:
*/
std::vector<double> mutation_sigmas;
if (params.mutation_params.individual_mutation_sigmas) mutation_sigmas = *params.mutation_params.individual_mutation_sigmas;
else {
mutation_sigmas.reserve(point_ranges.size());
for (auto &range : point_ranges)
mutation_sigmas.push_back((range.second - range.first) * params.mutation_params.mutation_percent_sigma);
// if constexpr (DEBUG_GA) std::cout << "Mutation sigmas: " << mutation_sigmas << std::endl << std::endl;
}
// Generating initial population
p = params.custom_operations.population_generation(point_ranges, params.population_size);
// if constexpr (DEBUG_GA) std::cout << "Initial population: " << p << std::endl << std::endl;
// Init fitness vectors:
fitnesses.assign(params.population_size, 0.);
if (to_store_fitness) to_store_fitness->reserve(params.epoch_num);
// Making threads
std::vector<std::thread> threads;
if(params.threading_params.allow_multithreading)
{
threads_ready.assign(params.threading_params.threads, false);
auto task_ranges = distribute_task_ranges(params.population_size, params.threading_params.threads);
threads.reserve(params.threading_params.threads);
for (size_t thread_index = 0; thread_index < params.threading_params.threads; thread_index++)
{
threads.emplace_back(count_fitness_function_thread, thread_index, ref(fitness_function), task_ranges[thread_index]);
}
}
// Init fast normalizer:
normalizer normaaaaa(10000);
/// Beginning of the main loop:
double current_fitness = 0;
Genome best_genome;
for (size_t epoch = 0; epoch < params.epoch_num; epoch++) {
if (logger) (*logger)(p, epoch, logging_type::new_epoch);
/// Mutation
for (auto& g : p) params.custom_operations.mutation(g, mutation_sigmas, params.mutation_params.target_gene_mutation_number, normaaaaa);
if (logger) (*logger)(p, epoch, logging_type::after_mutation);
if (params.mutation_params.cut_mutations) params.custom_operations.genome_constraint(p, point_ranges); // cut_mutations(p, point_ranges);
if (logger) (*logger)(p, epoch, logging_type::after_constraining);
std::cout << "[GA]: Counting fitness..." << std::endl;
// Calculating fitnesses : MULTITHREADINGLY!
if (params.threading_params.allow_multithreading) {
threads_work_collected = false;
// ReSet thread states:
std::fill(threads_ready.begin(), threads_ready.end(), false);
// Say other threads, that it`s time to count:
thread_count_time = true;
/*
* Threads are counting now
*/
// Wait while they`re not ready:
while(!check_threads()) {}
thread_count_time = false;
threads_work_collected = true;
// fitnesses = thread_results;
}
else { // If multithreading in`t allowed:
for (size_t index = 0; index < params.population_size; index++) {
fitnesses[index] = fitness_function(p[index]);
}
}
std::cout << "[GA]: Counted fitness";
// for(auto& fit : fitnesses) std::cout << fit << ", ";
// std::cout << "]" << std::endl;
// Find the best genome and its fitness:
auto [_best_fitness, _best_genome] = find_best_genome(p, fitnesses);
best_genome = _best_genome;
current_fitness = _best_fitness;
if (params.exiting_fitness_value && current_fitness > *params.exiting_fitness_value) break;
if (to_store_fitness) to_store_fitness->push_back(current_fitness);
// Calculating population quantities:
auto population_quantities = calculate_genome_quantities(params.population_size,
{
params.hazing_params.hazing_percent,
double(epoch) / params.epoch_num,
params.hazing_params.parent_fit_pow,
params.hazing_params.elite_fit_pow,
params.hazing_params.hyper_elite_fit_pow,
epoch != 0
});
// std::cout << "Population Quantities: " << population_quantities << std::endl;
// Making new population, the most interesting part:
make_new_generation(p, fitnesses, normaaaaa, best_genome, population_quantities, params.crossover_mode, params.custom_operations);
// if constexpr (DEBUG_GA) std::cout << "Fitness functions: " << fitnesses << std::endl;
// Output information:
informer(100 * double(epoch) / params.epoch_num, current_fitness, best_genome);
if (epoch && logger) (*logger)({ best_genome }, epoch, logging_type::best_genome);
}
/// ^^^ End Of Main Loop ^^^
if(params.threading_params.allow_multithreading) {
// Stop other threads:
thread_task_ready = true;
for (auto &this_thread : threads) this_thread.join();
}
// Here's the actual result:
return { current_fitness, best_genome };
}
// Log Wrapper
std::pair<double, Genome> log_ga_optimize(const std::function<double(std::vector<double>&)>& target_function, std::vector<std::pair<double, double>>& point_ranges,
const single_run_GA_params& params, const bool generate_fitness_from_loss, std::vector<bool> to_logariphmate,
const std::function< void(double, double, const Genome&) >& informer, std::vector<double>* to_store_fitness)
{
if (to_logariphmate.empty()) to_logariphmate.assign(point_ranges.size(), false);
else assert(to_logariphmate.size() == point_ranges.size());
// Cook fake ranges:
auto real_point_ranges = point_ranges;
for (size_t r_index = 0; r_index < point_ranges.size(); r_index++) if (to_logariphmate[r_index]) {
real_point_ranges[r_index] = { log(point_ranges[r_index].first), log(point_ranges[r_index].second) };
}
auto wrapper_lambda = [&](std::vector<double>& values) -> double
{
std::vector<double> fake_values;
fake_values.reserve(values.size());
for (size_t value_index = 0; value_index < values.size(); value_index++)
{
fake_values.push_back(to_logariphmate[value_index] ? exp(values[value_index]) : values[value_index]);
}
auto function_result = target_function(fake_values);
return generate_fitness_from_loss ? 1 / function_result : function_result;
};
auto informer_wrapper = [&](const double GA_percent, const double best_fitness, const std::vector<double>& best_genome)
{
std::vector<double> fake_genome = best_genome;
for (size_t index = 0; index < best_genome.size(); index++) if (to_logariphmate[index]) fake_genome[index] = exp(fake_genome[index]);
informer(GA_percent, best_fitness, fake_genome);
};
std::pair<double, Genome> ga_result = ga_optimize(wrapper_lambda, real_point_ranges, params, informer_wrapper,
to_store_fitness, nullptr);
std::pair<double, Genome> real_result = { ((generate_fitness_from_loss) ? (1 / ga_result.first) : (ga_result.first)), ga_result.second };
return real_result;
}
}
| 38.408397 | 164 | 0.697506 | [
"vector"
] |
82a05c74b0ad96bfcc368ae6ee3e0979a78c4100 | 1,486 | cpp | C++ | src/CompositionEventInitImp.cpp | esrille/escudo | 1ba68f6930f1ddb97385a5b488644b6dfa132152 | [
"Apache-2.0"
] | 29 | 2015-01-25T15:12:02.000Z | 2021-12-01T17:58:17.000Z | src/CompositionEventInitImp.h | esrille/escudo | 1ba68f6930f1ddb97385a5b488644b6dfa132152 | [
"Apache-2.0"
] | null | null | null | src/CompositionEventInitImp.h | esrille/escudo | 1ba68f6930f1ddb97385a5b488644b6dfa132152 | [
"Apache-2.0"
] | 7 | 2015-04-15T02:05:21.000Z | 2020-06-16T03:53:37.000Z | // Generated by esidl 0.3.0.
// This file is expected to be modified for the Web IDL interface
// implementation. Permission to use, copy, modify and distribute
// this file in any software license is hereby granted.
#ifndef ORG_W3C_DOM_BOOTSTRAP_COMPOSITIONEVENTINITIMP_H_INCLUDED
#define ORG_W3C_DOM_BOOTSTRAP_COMPOSITIONEVENTINITIMP_H_INCLUDED
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <org/w3c/dom/events/CompositionEventInit.h>
#include <org/w3c/dom/html/Window.h>
namespace org
{
namespace w3c
{
namespace dom
{
namespace bootstrap
{
class CompositionEventInitImp : public ObjectMixin<CompositionEventInitImp>
{
public:
// CompositionEventInit
bool getBubbles();
void setBubbles(bool bubbles);
bool getCancelable();
void setCancelable(bool cancelable);
html::Window getView();
void setView(html::Window view);
int getDetail();
void setDetail(int detail);
Nullable<std::u16string> getData();
void setData(const Nullable<std::u16string>& data);
std::u16string getLocale();
void setLocale(const std::u16string& locale);
// Object
virtual Any message_(uint32_t selector, const char* id, int argc, Any* argv)
{
return events::CompositionEventInit::dispatch(this, selector, id, argc, argv);
}
static const char* const getMetaData()
{
return events::CompositionEventInit::getMetaData();
}
};
}
}
}
}
#endif // ORG_W3C_DOM_BOOTSTRAP_COMPOSITIONEVENTINITIMP_H_INCLUDED
| 25.62069 | 86 | 0.735532 | [
"object"
] |
82a26dffe1070cba3e5ddad5df16e861e75c65ef | 119,401 | cc | C++ | re2c/bootstrap/src/parse/lex.cc | adesutherland/crexx | e8d17152c565e9387ee8c33c653b4910b56f5165 | [
"MIT"
] | 8 | 2020-11-08T15:36:14.000Z | 2022-03-27T13:50:07.000Z | re2c/bootstrap/src/parse/lex.cc | adesutherland/crexx | e8d17152c565e9387ee8c33c653b4910b56f5165 | [
"MIT"
] | 98 | 2020-11-12T11:49:41.000Z | 2022-03-27T17:24:13.000Z | re2c/bootstrap/src/parse/lex.cc | adesutherland/crexx | e8d17152c565e9387ee8c33c653b4910b56f5165 | [
"MIT"
] | 10 | 2021-03-31T13:50:52.000Z | 2021-12-02T03:34:42.000Z | /* Generated by re2c 2.1.1 on Fri May 28 10:53:19 2021 */
#line 1 "../src/parse/lex.re"
#include <ctype.h>
#include "src/util/c99_stdint.h"
#include <algorithm>
#include <limits>
#include <string>
#include <utility>
#include <vector>
#include "src/codegen/code.h"
#include "src/encoding/enc.h"
#include "src/msg/location.h"
#include "src/msg/msg.h"
#include "src/msg/warn.h"
#include "src/options/opt.h"
#include "src/parse/ast.h"
#include "src/parse/input.h"
#include "src/parse/lex.h"
#include "src/parse/scanner.h"
#include "src/parse/parse.h" // needed by "parser.h"
#include "src/parse/unescape.h"
#include "src/regexp/rule.h"
#include "src/util/s_to_n32_unsafe.h"
#include "src/util/string_utils.h"
#include "parser.h"
extern YYSTYPE yylval;
namespace re2c {
#define YYCTYPE unsigned char
#define YYCURSOR cur
#define YYLIMIT lim
#define YYMARKER mar
#define YYFILL(n) do { if (!fill(n)) { error("unexpected end of input"); exit(1); }} while(0)
#line 62 "../src/parse/lex.re"
#line 121 "../src/parse/lex.re"
static inline void save_string(std::string &str, const char *s, const char *e)
{
if (s == NULL) {
str.clear();
} else {
str.assign(s, e);
}
}
void Scanner::error_block_start(const char *block) const
{
msg.error(cur_loc(), "ill-formed start of a block: expected `/*!%s`"
" followed by a space, a newline or the end of block `*/`", block);
}
void Scanner::error_named_block_start(const char *block) const
{
msg.error(cur_loc(), "ill-formed start of a block: expected `/*!%s`"
", optionally followed by a name of the form `:[a-zA-Z_][a-zA-Z0-9_]*`"
", followed by a space, a newline or the end of block `*/`", block);
}
void Scanner::error_include_directive() const
{
msg.error(cur_loc(), "ill-formed include directive: expected `/*"
// split string to prevent re2c from lexing this as a real directive
"!include:re2c \"<file>\" */`");
}
void Scanner::error_header_directive() const
{
msg.error(cur_loc(), "ill-formed header directive: expected `/*"
// split string to prevent re2c from lexing this as a real directive
"!header:re2c:<on|off>`"
" followed by a space, a newline or the end of block `*/`");
}
Scanner::ParseMode Scanner::echo(Output &out)
{
const opt_t *opts = out.block().opts;
code_alc_t &alc = out.allocator;
const char *x, *y;
if (is_eof()) return Stop;
next:
tok = cur;
loop:
location = cur_loc();
ptr = cur;
#line 96 "src/parse/lex.cc"
{
YYCTYPE yych;
unsigned int yyaccept = 0;
static const unsigned char yybm[] = {
0, 64, 64, 64, 64, 64, 64, 64,
64, 80, 0, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
80, 64, 0, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
224, 224, 224, 224, 224, 224, 224, 224,
224, 224, 64, 64, 64, 64, 64, 64,
64, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 64, 0, 64, 64, 192,
64, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 192, 192, 192, 192, 192,
192, 192, 192, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64,
};
if ((YYLIMIT - YYCURSOR) < 20) YYFILL(20);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '\r') {
if (yych <= '\t') {
if (yych >= 0x01) goto yy4;
} else {
if (yych <= '\n') goto yy6;
if (yych <= '\f') goto yy4;
goto yy8;
}
} else {
if (yych <= '%') {
if (yych <= '$') goto yy4;
goto yy9;
} else {
if (yych == '/') goto yy10;
goto yy4;
}
}
++YYCURSOR;
#line 286 "../src/parse/lex.re"
{
if (is_eof()) {
out.wraw(tok, ptr);
return Stop;
}
goto loop;
}
#line 162 "src/parse/lex.cc"
yy4:
++YYCURSOR;
yy5:
#line 306 "../src/parse/lex.re"
{ goto loop; }
#line 168 "src/parse/lex.cc"
yy6:
yyaccept = 0;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yybm[0+yych] & 16) {
goto yy11;
}
if (yych == '#') goto yy14;
yy7:
#line 301 "../src/parse/lex.re"
{
next_line();
goto loop;
}
#line 182 "src/parse/lex.cc"
yy8:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy6;
goto yy5;
yy9:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '{') goto yy16;
goto yy5;
yy10:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych == '*') goto yy18;
goto yy5;
yy11:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 16) {
goto yy11;
}
if (yych == '#') goto yy14;
yy13:
YYCURSOR = YYMARKER;
if (yyaccept <= 6) {
if (yyaccept <= 3) {
if (yyaccept <= 1) {
if (yyaccept == 0) {
goto yy7;
} else {
goto yy5;
}
} else {
if (yyaccept == 2) {
goto yy64;
} else {
goto yy121;
}
}
} else {
if (yyaccept <= 5) {
if (yyaccept == 4) {
goto yy128;
} else {
goto yy151;
}
} else {
goto yy153;
}
}
} else {
if (yyaccept <= 10) {
if (yyaccept <= 8) {
if (yyaccept == 7) {
goto yy155;
} else {
goto yy157;
}
} else {
if (yyaccept == 9) {
goto yy162;
} else {
goto yy164;
}
}
} else {
if (yyaccept <= 12) {
if (yyaccept == 11) {
goto yy186;
} else {
goto yy191;
}
} else {
goto yy204;
}
}
}
yy14:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 5) YYFILL(5);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x1F) {
if (yych == '\t') goto yy14;
goto yy13;
} else {
if (yych <= ' ') goto yy14;
if (yych == 'l') goto yy19;
goto yy13;
}
yy16:
++YYCURSOR;
#line 173 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
return Parse;
}
#line 278 "src/parse/lex.cc"
yy18:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '!') goto yy20;
goto yy13;
yy19:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'i') goto yy21;
goto yy13;
yy20:
yych = (YYCTYPE)*++YYCURSOR;
switch (yych) {
case 'g': goto yy22;
case 'h': goto yy23;
case 'i': goto yy24;
case 'm': goto yy25;
case 'r': goto yy26;
case 's': goto yy27;
case 't': goto yy28;
case 'u': goto yy29;
default: goto yy13;
}
yy21:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'n') goto yy30;
goto yy13;
yy22:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy31;
goto yy13;
yy23:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy32;
goto yy13;
yy24:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'g') goto yy33;
if (yych == 'n') goto yy34;
goto yy13;
yy25:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'a') goto yy35;
if (yych == 't') goto yy36;
goto yy13;
yy26:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy37;
if (yych == 'u') goto yy38;
goto yy13;
yy27:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 't') goto yy39;
goto yy13;
yy28:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'y') goto yy40;
goto yy13;
yy29:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 's') goto yy41;
goto yy13;
yy30:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy42;
goto yy13;
yy31:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 't') goto yy43;
goto yy13;
yy32:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'a') goto yy44;
goto yy13;
yy33:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'n') goto yy45;
goto yy13;
yy34:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy46;
goto yy13;
yy35:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'x') goto yy47;
goto yy13;
yy36:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'a') goto yy48;
goto yy13;
yy37:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy49;
goto yy13;
yy38:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'l') goto yy50;
goto yy13;
yy39:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'a') goto yy51;
goto yy13;
yy40:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'p') goto yy52;
goto yy13;
yy41:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy53;
goto yy13;
yy42:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '0') goto yy55;
if (yych <= '9') goto yy13;
goto yy55;
yy43:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 's') goto yy56;
goto yy13;
yy44:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'd') goto yy57;
goto yy13;
yy45:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'o') goto yy58;
goto yy13;
yy46:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'l') goto yy59;
goto yy13;
yy47:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy60;
if (yych == 'n') goto yy61;
goto yy13;
yy48:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'g') goto yy62;
goto yy13;
yy49:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy63;
goto yy13;
yy50:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy65;
goto yy13;
yy51:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'g') goto yy66;
goto yy13;
yy52:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy67;
goto yy13;
yy53:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy68;
goto yy13;
yy54:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
yy55:
if (yych <= 0x1F) {
if (yych == '\t') goto yy54;
goto yy13;
} else {
if (yych <= ' ') goto yy54;
if (yych <= '0') goto yy13;
if (yych <= '9') {
yyt1 = YYCURSOR;
goto yy69;
}
goto yy13;
}
yy56:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 't') goto yy71;
goto yy13;
yy57:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy72;
goto yy13;
yy58:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy73;
goto yy13;
yy59:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'u') goto yy74;
goto yy13;
yy60:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy75;
goto yy13;
yy61:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'm') goto yy76;
goto yy13;
yy62:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 's') goto yy77;
goto yy13;
yy63:
yyaccept = 2;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '\r') {
if (yych <= 0x08) goto yy64;
if (yych <= '\n') {
yyt1 = YYCURSOR;
goto yy78;
}
if (yych >= '\r') {
yyt1 = YYCURSOR;
goto yy78;
}
} else {
if (yych <= ' ') {
if (yych >= ' ') {
yyt1 = YYCURSOR;
goto yy78;
}
} else {
if (yych == '*') {
yyt1 = YYCURSOR;
goto yy80;
}
}
}
yy64:
#line 273 "../src/parse/lex.re"
{ error_block_start("re2c"); exit(1); }
#line 511 "src/parse/lex.cc"
yy65:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 's') goto yy81;
goto yy13;
yy66:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 's') goto yy82;
goto yy13;
yy67:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 's') goto yy83;
goto yy13;
yy68:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy84;
goto yy13;
yy69:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 32) {
goto yy69;
}
if (yych <= '\f') {
if (yych <= 0x08) goto yy13;
if (yych <= '\t') goto yy85;
if (yych <= '\n') goto yy87;
goto yy13;
} else {
if (yych <= '\r') goto yy89;
if (yych == ' ') goto yy85;
goto yy13;
}
yy71:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'a') goto yy90;
goto yy13;
yy72:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy91;
goto yy13;
yy73:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy92;
goto yy13;
yy74:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'd') goto yy93;
goto yy13;
yy75:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy94;
goto yy13;
yy76:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'a') goto yy95;
goto yy13;
yy77:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy96;
goto yy13;
yy78:
++YYCURSOR;
YYCURSOR = yyt1;
#line 178 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
return Parse;
}
#line 581 "src/parse/lex.cc"
yy80:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy78;
goto yy13;
yy81:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy97;
goto yy13;
yy82:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy98;
goto yy13;
yy83:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy99;
goto yy13;
yy84:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy100;
goto yy13;
yy85:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x1F) {
if (yych == '\t') goto yy85;
goto yy13;
} else {
if (yych <= ' ') goto yy85;
if (yych == '"') goto yy101;
goto yy13;
}
yy87:
++YYCURSOR;
YYCURSOR = yyt1;
#line 294 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
out.wdelay_stmt(0, code_newline(alc));
set_sourceline();
goto next;
}
#line 624 "src/parse/lex.cc"
yy89:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy87;
goto yy13;
yy90:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 't') goto yy103;
goto yy13;
yy91:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy104;
goto yy13;
yy92:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy105;
goto yy13;
yy93:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy106;
goto yy13;
yy94:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy107;
goto yy13;
yy95:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 't') goto yy108;
goto yy13;
yy96:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy109;
goto yy13;
yy97:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy110;
goto yy13;
yy98:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy111;
goto yy13;
yy99:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy112;
goto yy13;
yy100:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy113;
goto yy13;
yy101:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 64) {
goto yy101;
}
if (yych <= '\n') goto yy13;
if (yych <= '"') goto yy114;
goto yy115;
yy103:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy116;
goto yy13;
yy104:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy117;
goto yy13;
yy105:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy118;
goto yy13;
yy106:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy119;
goto yy13;
yy107:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy120;
goto yy13;
yy108:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy122;
goto yy13;
yy109:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy123;
goto yy13;
yy110:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy124;
goto yy13;
yy111:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy125;
goto yy13;
yy112:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy126;
goto yy13;
yy113:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy127;
goto yy13;
yy114:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy87;
if (yych == '\r') goto yy89;
goto yy13;
yy115:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x00) goto yy13;
if (yych == '\n') goto yy13;
goto yy101;
yy116:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy129;
goto yy13;
yy117:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy130;
goto yy13;
yy118:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy131;
goto yy13;
yy119:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy132;
goto yy13;
yy120:
yyaccept = 3;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '\r') {
if (yych <= 0x08) goto yy121;
if (yych <= '\n') {
yyt1 = YYCURSOR;
goto yy133;
}
if (yych >= '\r') {
yyt1 = YYCURSOR;
goto yy133;
}
} else {
if (yych <= ' ') {
if (yych >= ' ') {
yyt1 = YYCURSOR;
goto yy133;
}
} else {
if (yych == '*') {
yyt1 = YYCURSOR;
goto yy135;
}
}
}
yy121:
#line 275 "../src/parse/lex.re"
{ error_block_start("max:re2c"); exit(1); }
#line 784 "src/parse/lex.cc"
yy122:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'h') goto yy136;
goto yy13;
yy123:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy137;
goto yy13;
yy124:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy138;
goto yy13;
yy125:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy139;
goto yy13;
yy126:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy140;
goto yy13;
yy127:
yyaccept = 4;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x1F) {
if (yych <= '\n') {
if (yych >= '\t') {
yyt1 = yyt3 = NULL;
yyt2 = YYCURSOR;
goto yy141;
}
} else {
if (yych == '\r') {
yyt1 = yyt3 = NULL;
yyt2 = YYCURSOR;
goto yy141;
}
}
} else {
if (yych <= '*') {
if (yych <= ' ') {
yyt1 = yyt3 = NULL;
yyt2 = YYCURSOR;
goto yy141;
}
if (yych >= '*') {
yyt1 = yyt3 = NULL;
yyt2 = YYCURSOR;
goto yy143;
}
} else {
if (yych == ':') goto yy144;
}
}
yy128:
#line 282 "../src/parse/lex.re"
{ error_named_block_start("use:re2c"); exit(1); }
#line 841 "src/parse/lex.cc"
yy129:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy145;
goto yy13;
yy130:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy146;
goto yy13;
yy131:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy147;
goto yy13;
yy132:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy148;
goto yy13;
yy133:
++YYCURSOR;
YYCURSOR = yyt1;
#line 202 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
out.wdelay_stmt(0, code_yymaxfill(alc));
// historically allows garbage before the end of the comment
lex_end_of_comment(out, true);
goto next;
}
#line 869 "src/parse/lex.cc"
yy135:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy133;
goto yy13;
yy136:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy149;
goto yy13;
yy137:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy150;
goto yy13;
yy138:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy152;
goto yy13;
yy139:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy154;
goto yy13;
yy140:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy156;
goto yy13;
yy141:
++YYCURSOR;
x = yyt3;
y = yyt1;
YYCURSOR = yyt2;
#line 189 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
save_string(out.rules_block_name, x, y);
return Reuse;
}
#line 905 "src/parse/lex.cc"
yy143:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy141;
goto yy13;
yy144:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '^') {
if (yych <= '@') goto yy13;
if (yych <= 'Z') {
yyt3 = YYCURSOR;
goto yy158;
}
goto yy13;
} else {
if (yych == '`') goto yy13;
if (yych <= 'z') {
yyt3 = YYCURSOR;
goto yy158;
}
goto yy13;
}
yy145:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy160;
goto yy13;
yy146:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy161;
goto yy13;
yy147:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy163;
goto yy13;
yy148:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy165;
goto yy13;
yy149:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy166;
goto yy13;
yy150:
yyaccept = 5;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '\r') {
if (yych <= 0x08) goto yy151;
if (yych <= '\n') {
yyt1 = YYCURSOR;
goto yy167;
}
if (yych >= '\r') {
yyt1 = YYCURSOR;
goto yy167;
}
} else {
if (yych <= ' ') {
if (yych >= ' ') {
yyt1 = YYCURSOR;
goto yy167;
}
} else {
if (yych == '*') {
yyt1 = YYCURSOR;
goto yy169;
}
}
}
yy151:
#line 280 "../src/parse/lex.re"
{ error_block_start("mtags:re2c"); exit(1); }
#line 976 "src/parse/lex.cc"
yy152:
yyaccept = 6;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x1F) {
if (yych <= '\n') {
if (yych >= '\t') {
yyt1 = yyt3 = NULL;
yyt2 = YYCURSOR;
goto yy170;
}
} else {
if (yych == '\r') {
yyt1 = yyt3 = NULL;
yyt2 = YYCURSOR;
goto yy170;
}
}
} else {
if (yych <= '*') {
if (yych <= ' ') {
yyt1 = yyt3 = NULL;
yyt2 = YYCURSOR;
goto yy170;
}
if (yych >= '*') {
yyt1 = yyt3 = NULL;
yyt2 = YYCURSOR;
goto yy172;
}
} else {
if (yych == ':') goto yy173;
}
}
yy153:
#line 281 "../src/parse/lex.re"
{ error_named_block_start("rules:re2c"); exit(1); }
#line 1013 "src/parse/lex.cc"
yy154:
yyaccept = 7;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '\r') {
if (yych <= 0x08) goto yy155;
if (yych <= '\n') {
yyt1 = YYCURSOR;
goto yy174;
}
if (yych >= '\r') {
yyt1 = YYCURSOR;
goto yy174;
}
} else {
if (yych <= ' ') {
if (yych >= ' ') {
yyt1 = YYCURSOR;
goto yy174;
}
} else {
if (yych == '*') {
yyt1 = YYCURSOR;
goto yy176;
}
}
}
yy155:
#line 279 "../src/parse/lex.re"
{ error_block_start("stags:re2c"); exit(1); }
#line 1043 "src/parse/lex.cc"
yy156:
yyaccept = 8;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '\r') {
if (yych <= 0x08) goto yy157;
if (yych <= '\n') {
yyt1 = YYCURSOR;
goto yy177;
}
if (yych >= '\r') {
yyt1 = YYCURSOR;
goto yy177;
}
} else {
if (yych <= ' ') {
if (yych >= ' ') {
yyt1 = YYCURSOR;
goto yy177;
}
} else {
if (yych == '*') {
yyt1 = YYCURSOR;
goto yy179;
}
}
}
yy157:
#line 278 "../src/parse/lex.re"
{ error_block_start("types:re2c"); exit(1); }
#line 1073 "src/parse/lex.cc"
yy158:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 128) {
goto yy158;
}
if (yych <= '\r') {
if (yych <= 0x08) goto yy13;
if (yych <= '\n') {
yyt1 = yyt2 = YYCURSOR;
goto yy141;
}
if (yych <= '\f') goto yy13;
yyt1 = yyt2 = YYCURSOR;
goto yy141;
} else {
if (yych <= ' ') {
if (yych <= 0x1F) goto yy13;
yyt1 = yyt2 = YYCURSOR;
goto yy141;
} else {
if (yych == '*') {
yyt1 = yyt2 = YYCURSOR;
goto yy143;
}
goto yy13;
}
}
yy160:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy180;
goto yy13;
yy161:
yyaccept = 9;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych == ':') goto yy181;
yy162:
#line 284 "../src/parse/lex.re"
{ error_header_directive(); exit(1); }
#line 1114 "src/parse/lex.cc"
yy163:
yyaccept = 10;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '\r') {
if (yych <= 0x08) goto yy164;
if (yych <= '\n') {
yyt1 = YYCURSOR;
goto yy182;
}
if (yych >= '\r') {
yyt1 = YYCURSOR;
goto yy182;
}
} else {
if (yych <= ' ') {
if (yych >= ' ') {
yyt1 = YYCURSOR;
goto yy182;
}
} else {
if (yych == '*') {
yyt1 = YYCURSOR;
goto yy184;
}
}
}
yy164:
#line 274 "../src/parse/lex.re"
{ error_block_start("ignore:re2c"); exit(1); }
#line 1144 "src/parse/lex.cc"
yy165:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy185;
goto yy13;
yy166:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy187;
goto yy13;
yy167:
++YYCURSOR;
YYCURSOR = yyt1;
#line 244 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
lex_tags(out, true);
goto next;
}
#line 1162 "src/parse/lex.cc"
yy169:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy167;
goto yy13;
yy170:
++YYCURSOR;
x = yyt3;
y = yyt1;
YYCURSOR = yyt2;
#line 183 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
save_string(out.rules_block_name, x, y);
return Rules;
}
#line 1178 "src/parse/lex.cc"
yy172:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy170;
goto yy13;
yy173:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '^') {
if (yych <= '@') goto yy13;
if (yych <= 'Z') {
yyt3 = YYCURSOR;
goto yy188;
}
goto yy13;
} else {
if (yych == '`') goto yy13;
if (yych <= 'z') {
yyt3 = YYCURSOR;
goto yy188;
}
goto yy13;
}
yy174:
++YYCURSOR;
YYCURSOR = yyt1;
#line 238 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
lex_tags(out, false);
goto next;
}
#line 1209 "src/parse/lex.cc"
yy176:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy174;
goto yy13;
yy177:
++YYCURSOR;
YYCURSOR = yyt1;
#line 227 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
out.wdelay_stmt(0, code_line_info_output(alc));
out.wdelay_stmt(opts->topIndent, code_cond_enum(alc));
out.cond_enum_in_hdr = out.in_header();
out.warn_condition_order = false; // see note [condition order]
out.wdelay_stmt(0, code_line_info_input(alc, cur_loc()));
lex_end_of_comment(out);
goto next;
}
#line 1228 "src/parse/lex.cc"
yy179:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy177;
goto yy13;
yy180:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy190;
goto yy13;
yy181:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'o') goto yy192;
goto yy13;
yy182:
++YYCURSOR;
YYCURSOR = yyt1;
#line 195 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
// allows arbitrary garbage before the end of the comment
lex_end_of_comment(out, true);
goto next;
}
#line 1251 "src/parse/lex.cc"
yy184:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy182;
goto yy13;
yy185:
yyaccept = 11;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych == '\t') goto yy193;
if (yych == ' ') goto yy193;
yy186:
#line 283 "../src/parse/lex.re"
{ error_include_directive(); exit(1); }
#line 1264 "src/parse/lex.cc"
yy187:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy195;
goto yy13;
yy188:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '*') {
if (yych <= '\r') {
if (yych <= 0x08) goto yy13;
if (yych <= '\n') {
yyt1 = yyt2 = YYCURSOR;
goto yy170;
}
if (yych <= '\f') goto yy13;
yyt1 = yyt2 = YYCURSOR;
goto yy170;
} else {
if (yych == ' ') {
yyt1 = yyt2 = YYCURSOR;
goto yy170;
}
if (yych <= ')') goto yy13;
yyt1 = yyt2 = YYCURSOR;
goto yy172;
}
} else {
if (yych <= 'Z') {
if (yych <= '/') goto yy13;
if (yych <= '9') goto yy188;
if (yych <= '@') goto yy13;
goto yy188;
} else {
if (yych <= '_') {
if (yych <= '^') goto yy13;
goto yy188;
} else {
if (yych <= '`') goto yy13;
if (yych <= 'z') goto yy188;
goto yy13;
}
}
}
yy190:
yyaccept = 12;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '\r') {
if (yych <= 0x08) goto yy191;
if (yych <= '\n') {
yyt1 = YYCURSOR;
goto yy196;
}
if (yych >= '\r') {
yyt1 = YYCURSOR;
goto yy196;
}
} else {
if (yych <= ' ') {
if (yych >= ' ') {
yyt1 = YYCURSOR;
goto yy196;
}
} else {
if (yych == '*') {
yyt1 = YYCURSOR;
goto yy198;
}
}
}
yy191:
#line 277 "../src/parse/lex.re"
{ error_block_start("getstate:re2c"); exit(1); }
#line 1338 "src/parse/lex.cc"
yy192:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'f') goto yy199;
if (yych == 'n') goto yy200;
goto yy13;
yy193:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x1F) {
if (yych == '\t') goto yy193;
goto yy13;
} else {
if (yych <= ' ') goto yy193;
if (yych == '"') {
yyt1 = YYCURSOR;
goto yy201;
}
goto yy13;
}
yy195:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy203;
goto yy13;
yy196:
++YYCURSOR;
YYCURSOR = yyt1;
#line 217 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
if (opts->fFlag && opts->target == TARGET_CODE && !out.state_goto) {
out.wdelay_stmt(opts->topIndent, code_state_goto(alc));
out.state_goto = true;
}
lex_end_of_comment(out);
goto next;
}
#line 1376 "src/parse/lex.cc"
yy198:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy196;
goto yy13;
yy199:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'f') goto yy205;
goto yy13;
yy200:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '\r') {
if (yych <= 0x08) goto yy13;
if (yych <= '\n') {
yyt1 = YYCURSOR;
goto yy206;
}
if (yych <= '\f') goto yy13;
yyt1 = YYCURSOR;
goto yy206;
} else {
if (yych <= ' ') {
if (yych <= 0x1F) goto yy13;
yyt1 = YYCURSOR;
goto yy206;
} else {
if (yych == '*') {
yyt1 = YYCURSOR;
goto yy208;
}
goto yy13;
}
}
yy201:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '!') {
if (yych <= 0x00) goto yy13;
if (yych == '\n') goto yy13;
goto yy201;
} else {
if (yych <= '"') goto yy209;
if (yych == '\\') goto yy210;
goto yy201;
}
yy203:
yyaccept = 13;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '\r') {
if (yych <= 0x08) goto yy204;
if (yych <= '\n') {
yyt1 = YYCURSOR;
goto yy211;
}
if (yych >= '\r') {
yyt1 = YYCURSOR;
goto yy211;
}
} else {
if (yych <= ' ') {
if (yych >= ' ') {
yyt1 = YYCURSOR;
goto yy211;
}
} else {
if (yych == '*') {
yyt1 = YYCURSOR;
goto yy213;
}
}
}
yy204:
#line 276 "../src/parse/lex.re"
{ error_block_start("maxnmatch:re2c"); exit(1); }
#line 1451 "src/parse/lex.cc"
yy205:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '\r') {
if (yych <= 0x08) goto yy13;
if (yych <= '\n') {
yyt1 = YYCURSOR;
goto yy214;
}
if (yych <= '\f') goto yy13;
yyt1 = YYCURSOR;
goto yy214;
} else {
if (yych <= ' ') {
if (yych <= 0x1F) goto yy13;
yyt1 = YYCURSOR;
goto yy214;
} else {
if (yych == '*') {
yyt1 = YYCURSOR;
goto yy216;
}
goto yy13;
}
}
yy206:
++YYCURSOR;
YYCURSOR = yyt1;
#line 250 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
out.header_mode(true);
out.need_header = opts->target == TARGET_CODE;
lex_end_of_comment(out);
goto next;
}
#line 1487 "src/parse/lex.cc"
yy208:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy206;
goto yy13;
yy209:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '\r') {
if (yych <= 0x08) goto yy13;
if (yych <= '\n') {
yyt2 = YYCURSOR;
goto yy217;
}
if (yych <= '\f') goto yy13;
yyt2 = YYCURSOR;
goto yy217;
} else {
if (yych <= ' ') {
if (yych <= 0x1F) goto yy13;
yyt2 = YYCURSOR;
goto yy217;
} else {
if (yych == '*') {
yyt2 = YYCURSOR;
goto yy219;
}
goto yy13;
}
}
yy210:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x00) goto yy13;
if (yych == '\n') goto yy13;
goto yy201;
yy211:
++YYCURSOR;
YYCURSOR = yyt1;
#line 210 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
out.wdelay_stmt(0, code_yymaxnmatch(alc));
lex_end_of_comment(out);
goto next;
}
#line 1533 "src/parse/lex.cc"
yy213:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy211;
goto yy13;
yy214:
++YYCURSOR;
YYCURSOR = yyt1;
#line 258 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
out.header_mode(false);
out.wdelay_stmt(0, code_line_info_input(alc, cur_loc()));
lex_end_of_comment(out);
goto next;
}
#line 1549 "src/parse/lex.cc"
yy216:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy214;
goto yy13;
yy217:
++YYCURSOR;
x = yyt1;
YYCURSOR = yyt2;
y = yyt2;
#line 266 "../src/parse/lex.re"
{
out.wraw(tok, ptr);
lex_end_of_comment(out);
include(getstr(x + 1, y - 1));
goto next;
}
#line 1566 "src/parse/lex.cc"
yy219:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy217;
goto yy13;
}
#line 307 "../src/parse/lex.re"
}
void Scanner::lex_end_of_comment(Output &out, bool allow_garbage)
{
bool multiline = false;
loop:
#line 1581 "src/parse/lex.cc"
{
YYCTYPE yych;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '\r') {
if (yych <= '\t') {
if (yych >= '\t') goto yy224;
} else {
if (yych <= '\n') goto yy226;
if (yych >= '\r') goto yy228;
}
} else {
if (yych <= ' ') {
if (yych >= ' ') goto yy224;
} else {
if (yych == '*') goto yy229;
}
}
++YYCURSOR;
yy223:
#line 315 "../src/parse/lex.re"
{
if (allow_garbage && !is_eof()) goto loop;
msg.error(cur_loc(), "expected end of block");
exit(1);
}
#line 1608 "src/parse/lex.cc"
yy224:
++YYCURSOR;
#line 320 "../src/parse/lex.re"
{ goto loop; }
#line 1613 "src/parse/lex.cc"
yy226:
++YYCURSOR;
#line 321 "../src/parse/lex.re"
{
next_line();
multiline = true;
goto loop;
}
#line 1622 "src/parse/lex.cc"
yy228:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy226;
goto yy223;
yy229:
yych = (YYCTYPE)*++YYCURSOR;
if (yych != '/') goto yy223;
++YYCURSOR;
#line 326 "../src/parse/lex.re"
{
if (multiline) {
out.wdelay_stmt(0, code_line_info_input(out.allocator, cur_loc()));
}
return;
}
#line 1638 "src/parse/lex.cc"
}
#line 332 "../src/parse/lex.re"
}
void Scanner::lex_tags(Output &out, bool mtags)
{
const opt_t *opts = out.block().opts;
std::string fmt, sep;
loop:
#line 1650 "src/parse/lex.cc"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
128, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
if ((YYLIMIT - YYCURSOR) < 9) YYFILL(9);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 128) {
goto yy236;
}
if (yych <= ')') {
if (yych <= '\n') {
if (yych >= '\t') goto yy239;
} else {
if (yych == '\r') goto yy241;
}
} else {
if (yych <= 'f') {
if (yych <= '*') goto yy242;
if (yych >= 'f') goto yy243;
} else {
if (yych == 's') goto yy244;
}
}
++YYCURSOR;
yy235:
#line 341 "../src/parse/lex.re"
{
msg.error(cur_loc(), "unrecognized configuration");
exit(1);
}
#line 1713 "src/parse/lex.cc"
yy236:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 128) {
goto yy236;
}
#line 353 "../src/parse/lex.re"
{
goto loop;
}
#line 1725 "src/parse/lex.cc"
yy239:
++YYCURSOR;
#line 356 "../src/parse/lex.re"
{
next_line();
goto loop;
}
#line 1733 "src/parse/lex.cc"
yy241:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy239;
goto yy235;
yy242:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy245;
goto yy235;
yy243:
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych == 'o') goto yy247;
goto yy235;
yy244:
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych == 'e') goto yy249;
goto yy235;
yy245:
++YYCURSOR;
#line 360 "../src/parse/lex.re"
{
if (opts->target == TARGET_CODE) {
out.wdelay_stmt(opts->topIndent, code_tags(out.allocator, fmt, sep, mtags));
}
return;
}
#line 1759 "src/parse/lex.cc"
yy247:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy250;
yy248:
YYCURSOR = YYMARKER;
goto yy235;
yy249:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'p') goto yy251;
goto yy248;
yy250:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'm') goto yy252;
goto yy248;
yy251:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'a') goto yy253;
goto yy248;
yy252:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'a') goto yy254;
goto yy248;
yy253:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'r') goto yy255;
goto yy248;
yy254:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 't') goto yy256;
goto yy248;
yy255:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'a') goto yy258;
goto yy248;
yy256:
++YYCURSOR;
#line 345 "../src/parse/lex.re"
{
fmt = lex_conf_string();
goto loop;
}
#line 1801 "src/parse/lex.cc"
yy258:
yych = (YYCTYPE)*++YYCURSOR;
if (yych != 't') goto yy248;
yych = (YYCTYPE)*++YYCURSOR;
if (yych != 'o') goto yy248;
yych = (YYCTYPE)*++YYCURSOR;
if (yych != 'r') goto yy248;
++YYCURSOR;
#line 349 "../src/parse/lex.re"
{
sep = lex_conf_string();
goto loop;
}
#line 1815 "src/parse/lex.cc"
}
#line 366 "../src/parse/lex.re"
}
int Scanner::scan()
{
const char *p, *x, *y;
scan:
tok = cur;
location = cur_loc();
#line 1828 "src/parse/lex.cc"
{
YYCTYPE yych;
unsigned int yyaccept = 0;
static const unsigned char yybm[] = {
0, 128, 128, 128, 128, 128, 128, 128,
128, 144, 0, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
144, 128, 0, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
224, 224, 224, 224, 224, 224, 224, 224,
224, 224, 128, 128, 128, 128, 128, 128,
128, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 128, 0, 128, 128, 160,
128, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 160, 160, 160,
160, 160, 160, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
};
if ((YYLIMIT - YYCURSOR) < 9) YYFILL(9);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 16) {
goto yy267;
}
if (yych <= '9') {
if (yych <= '$') {
if (yych <= '\r') {
if (yych <= 0x08) goto yy265;
if (yych <= '\n') goto yy270;
if (yych >= '\r') goto yy272;
} else {
if (yych <= '!') {
if (yych >= ' ') goto yy273;
} else {
if (yych <= '"') goto yy274;
if (yych <= '#') goto yy276;
goto yy277;
}
}
} else {
if (yych <= '*') {
if (yych <= '&') {
if (yych <= '%') goto yy279;
} else {
if (yych <= '\'') goto yy280;
if (yych <= ')') goto yy277;
goto yy282;
}
} else {
if (yych <= '-') {
if (yych <= '+') goto yy277;
} else {
if (yych <= '.') goto yy283;
if (yych <= '/') goto yy285;
}
}
}
} else {
if (yych <= '[') {
if (yych <= '=') {
if (yych <= ':') goto yy286;
if (yych <= ';') goto yy277;
if (yych <= '<') goto yy287;
goto yy289;
} else {
if (yych <= '?') {
if (yych >= '?') goto yy277;
} else {
if (yych <= '@') goto yy276;
if (yych <= 'Z') goto yy290;
goto yy293;
}
}
} else {
if (yych <= 'q') {
if (yych <= '^') {
if (yych <= '\\') goto yy277;
} else {
if (yych != '`') goto yy290;
}
} else {
if (yych <= 'z') {
if (yych <= 'r') goto yy295;
goto yy290;
} else {
if (yych <= '{') goto yy296;
if (yych <= '|') goto yy277;
}
}
}
}
yy265:
++YYCURSOR;
yy266:
#line 518 "../src/parse/lex.re"
{
msg.error(tok_loc(), "unexpected character: '%c'", *tok);
exit(1);
}
#line 1946 "src/parse/lex.cc"
yy267:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 16) {
goto yy267;
}
#line 500 "../src/parse/lex.re"
{ goto scan; }
#line 1956 "src/parse/lex.cc"
yy270:
yyaccept = 0;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x1F) {
if (yych == '\t') goto yy298;
} else {
if (yych <= ' ') goto yy298;
if (yych == '#') goto yy301;
}
yy271:
#line 507 "../src/parse/lex.re"
{
next_line();
if (lexer_state == LEX_FLEX_NAME) {
lexer_state = LEX_NORMAL;
return TOKEN_FID_END;
}
else {
goto scan;
}
}
#line 1978 "src/parse/lex.cc"
yy272:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy270;
goto yy266;
yy273:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych == 'i') goto yy303;
if (yych == 'u') goto yy304;
goto yy266;
yy274:
++YYCURSOR;
#line 392 "../src/parse/lex.re"
{ yylval.regexp = lex_str('"'); return TOKEN_REGEXP; }
#line 1993 "src/parse/lex.cc"
yy276:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '^') {
if (yych <= '@') goto yy266;
if (yych <= 'Z') goto yy305;
goto yy266;
} else {
if (yych == '`') goto yy266;
if (yych <= 'z') goto yy305;
goto yy266;
}
yy277:
++YYCURSOR;
yy278:
#line 401 "../src/parse/lex.re"
{ return *tok; }
#line 2010 "src/parse/lex.cc"
yy279:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '}') goto yy308;
goto yy266;
yy280:
++YYCURSOR;
#line 391 "../src/parse/lex.re"
{ yylval.regexp = lex_str('\''); return TOKEN_REGEXP; }
#line 2019 "src/parse/lex.cc"
yy282:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '/') goto yy308;
goto yy278;
yy283:
++YYCURSOR;
#line 495 "../src/parse/lex.re"
{
yylval.regexp = ast_dot(tok_loc());
return TOKEN_REGEXP;
}
#line 2031 "src/parse/lex.cc"
yy285:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '*') goto yy310;
if (yych == '/') goto yy312;
goto yy278;
yy286:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '=') goto yy314;
goto yy266;
yy287:
++YYCURSOR;
#line 384 "../src/parse/lex.re"
{ return lex_clist(); }
#line 2045 "src/parse/lex.cc"
yy289:
yyaccept = 2;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych == '>') goto yy316;
goto yy278;
yy290:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
yy291:
if (yybm[0+yych] & 32) {
goto yy290;
}
#line 450 "../src/parse/lex.re"
{
if (!globopts->FFlag || lex_namedef_context_re2c()) {
yylval.str = newstr(tok, cur);
return TOKEN_ID;
}
else if (lex_namedef_context_flex()) {
yylval.str = newstr(tok, cur);
lexer_state = LEX_FLEX_NAME;
return TOKEN_FID;
}
else {
// consume one character, otherwise we risk breaking operator
// precedence in cases like ab*: it should be a(b)*, not (ab)*
cur = tok + 1;
ASTChar c = {static_cast<uint8_t>(tok[0]), tok_loc()};
std::vector<ASTChar> *str = new std::vector<ASTChar>;
str->push_back(c);
yylval.regexp = ast_str(tok_loc(), str, false);
return TOKEN_REGEXP;
}
}
#line 2082 "src/parse/lex.cc"
yy293:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '^') goto yy318;
#line 393 "../src/parse/lex.re"
{ yylval.regexp = lex_cls(false); return TOKEN_REGEXP; }
#line 2088 "src/parse/lex.cc"
yy295:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy320;
goto yy291;
yy296:
yyaccept = 3;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yybm[0+yych] & 64) {
goto yy323;
}
if (yych <= 'Z') {
if (yych == ',') goto yy321;
if (yych >= 'A') goto yy325;
} else {
if (yych <= '_') {
if (yych >= '_') goto yy325;
} else {
if (yych <= '`') goto yy297;
if (yych <= 'z') goto yy325;
}
}
yy297:
#line 376 "../src/parse/lex.re"
{ lex_code_in_braces(); return TOKEN_CODE; }
#line 2113 "src/parse/lex.cc"
yy298:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x1F) {
if (yych == '\t') goto yy298;
} else {
if (yych <= ' ') goto yy298;
if (yych == '#') goto yy301;
}
yy300:
YYCURSOR = YYMARKER;
if (yyaccept <= 3) {
if (yyaccept <= 1) {
if (yyaccept == 0) {
goto yy271;
} else {
goto yy266;
}
} else {
if (yyaccept == 2) {
goto yy278;
} else {
goto yy297;
}
}
} else {
if (yyaccept <= 5) {
if (yyaccept == 4) {
goto yy315;
} else {
goto yy322;
}
} else {
if (yyaccept == 6) {
goto yy342;
} else {
goto yy366;
}
}
}
yy301:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 5) YYFILL(5);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x1F) {
if (yych == '\t') goto yy301;
goto yy300;
} else {
if (yych <= ' ') goto yy301;
if (yych == 'l') goto yy327;
goto yy300;
}
yy303:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'n') goto yy328;
goto yy300;
yy304:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 's') goto yy329;
goto yy300;
yy305:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 'Z') {
if (yych <= '/') goto yy307;
if (yych <= '9') goto yy305;
if (yych >= 'A') goto yy305;
} else {
if (yych <= '_') {
if (yych >= '_') goto yy305;
} else {
if (yych <= '`') goto yy307;
if (yych <= 'z') goto yy305;
}
}
yy307:
#line 396 "../src/parse/lex.re"
{
yylval.regexp = ast_tag(tok_loc(), newstr(tok + 1, cur), tok[0] == '#');
return TOKEN_REGEXP;
}
#line 2197 "src/parse/lex.cc"
yy308:
++YYCURSOR;
#line 389 "../src/parse/lex.re"
{ tok = cur; return 0; }
#line 2202 "src/parse/lex.cc"
yy310:
++YYCURSOR;
#line 387 "../src/parse/lex.re"
{ lex_c_comment(); goto scan; }
#line 2207 "src/parse/lex.cc"
yy312:
++YYCURSOR;
#line 386 "../src/parse/lex.re"
{ lex_cpp_comment(); goto scan; }
#line 2212 "src/parse/lex.cc"
yy314:
yyaccept = 4;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych == '>') goto yy316;
yy315:
#line 377 "../src/parse/lex.re"
{ lex_code_indented(); return TOKEN_CODE; }
#line 2220 "src/parse/lex.cc"
yy316:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '@') {
if (yych <= '\t') {
if (yych <= 0x08) goto yy300;
goto yy316;
} else {
if (yych == ' ') goto yy316;
goto yy300;
}
} else {
if (yych <= '_') {
if (yych <= 'Z') {
yyt1 = YYCURSOR;
goto yy330;
}
if (yych <= '^') goto yy300;
yyt1 = YYCURSOR;
goto yy330;
} else {
if (yych <= '`') goto yy300;
if (yych <= 'z') {
yyt1 = YYCURSOR;
goto yy330;
}
goto yy300;
}
}
yy318:
++YYCURSOR;
#line 394 "../src/parse/lex.re"
{ yylval.regexp = lex_cls(true); return TOKEN_REGEXP; }
#line 2255 "src/parse/lex.cc"
yy320:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '2') goto yy333;
goto yy291;
yy321:
++YYCURSOR;
yy322:
#line 433 "../src/parse/lex.re"
{
msg.error(tok_loc(), "illegal closure form, use '{n}', '{n,}', '{n,m}' "
"where n and m are numbers");
exit(1);
}
#line 2269 "src/parse/lex.cc"
yy323:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 64) {
goto yy323;
}
if (yych == ',') {
yyt1 = YYCURSOR;
goto yy334;
}
if (yych == '}') goto yy335;
goto yy300;
yy325:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '^') {
if (yych <= '9') {
if (yych <= '/') goto yy300;
goto yy325;
} else {
if (yych <= '@') goto yy300;
if (yych <= 'Z') goto yy325;
goto yy300;
}
} else {
if (yych <= 'z') {
if (yych == '`') goto yy300;
goto yy325;
} else {
if (yych == '}') goto yy337;
goto yy300;
}
}
yy327:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'i') goto yy339;
goto yy300;
yy328:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy340;
goto yy300;
yy329:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy341;
goto yy300;
yy330:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 'Z') {
if (yych <= '/') goto yy332;
if (yych <= '9') goto yy330;
if (yych >= 'A') goto yy330;
} else {
if (yych <= '_') {
if (yych >= '_') goto yy330;
} else {
if (yych <= '`') goto yy332;
if (yych <= 'z') goto yy330;
}
}
yy332:
p = yyt1;
#line 379 "../src/parse/lex.re"
{
yylval.str = newstr(p, cur);
return tok[0] == ':' ? TOKEN_CJUMP : TOKEN_CNEXT;
}
#line 2340 "src/parse/lex.cc"
yy333:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'c') goto yy343;
goto yy291;
yy334:
yyaccept = 5;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy322;
if (yych <= '9') goto yy344;
if (yych == '}') goto yy346;
goto yy322;
yy335:
++YYCURSOR;
#line 403 "../src/parse/lex.re"
{
if (!s_to_u32_unsafe (tok + 1, cur - 1, yylval.bounds.min)) {
msg.error(tok_loc(), "repetition count overflow");
exit(1);
}
yylval.bounds.max = yylval.bounds.min;
return TOKEN_CLOSESIZE;
}
#line 2363 "src/parse/lex.cc"
yy337:
++YYCURSOR;
#line 439 "../src/parse/lex.re"
{
if (!globopts->FFlag) {
msg.error(tok_loc(), "curly braces for names only allowed with -F switch");
exit(1);
}
yylval.str = newstr(tok + 1, cur - 1);
return TOKEN_ID;
}
#line 2375 "src/parse/lex.cc"
yy339:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'n') goto yy348;
goto yy300;
yy340:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'l') goto yy349;
goto yy300;
yy341:
yyaccept = 6;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych == ':') goto yy350;
yy342:
#line 489 "../src/parse/lex.re"
{
msg.error(tok_loc(), "ill-formed use directive"
", expected format: `!use:<block-name> ; <newline>`");
exit(1);
}
#line 2395 "src/parse/lex.cc"
yy343:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == ':') goto yy351;
goto yy291;
yy344:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '/') goto yy300;
if (yych <= '9') goto yy344;
if (yych == '}') goto yy353;
goto yy300;
yy346:
++YYCURSOR;
#line 424 "../src/parse/lex.re"
{
if (!s_to_u32_unsafe (tok + 1, cur - 2, yylval.bounds.min)) {
msg.error(tok_loc(), "repetition lower bound overflow");
exit(1);
}
yylval.bounds.max = std::numeric_limits<uint32_t>::max();
return TOKEN_CLOSESIZE;
}
#line 2419 "src/parse/lex.cc"
yy348:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy355;
goto yy300;
yy349:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'u') goto yy356;
goto yy300;
yy350:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '^') {
if (yych <= '@') goto yy300;
if (yych <= 'Z') {
yyt1 = YYCURSOR;
goto yy357;
}
goto yy300;
} else {
if (yych == '`') goto yy300;
if (yych <= 'z') {
yyt1 = YYCURSOR;
goto yy357;
}
goto yy300;
}
yy351:
++YYCURSOR;
#line 448 "../src/parse/lex.re"
{ return TOKEN_CONF; }
#line 2449 "src/parse/lex.cc"
yy353:
++YYCURSOR;
p = yyt1;
#line 412 "../src/parse/lex.re"
{
if (!s_to_u32_unsafe (tok + 1, p, yylval.bounds.min)) {
msg.error(tok_loc(), "repetition lower bound overflow");
exit(1);
}
if (!s_to_u32_unsafe (p + 1, cur - 1, yylval.bounds.max)) {
msg.error(tok_loc(), "repetition upper bound overflow");
exit(1);
}
return TOKEN_CLOSESIZE;
}
#line 2465 "src/parse/lex.cc"
yy355:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '0') goto yy360;
if (yych <= '9') goto yy300;
goto yy360;
yy356:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'd') goto yy361;
goto yy300;
yy357:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '@') {
if (yych <= '9') {
if (yych <= '/') goto yy300;
goto yy357;
} else {
if (yych == ';') {
yyt2 = YYCURSOR;
goto yy362;
}
goto yy300;
}
} else {
if (yych <= '_') {
if (yych <= 'Z') goto yy357;
if (yych <= '^') goto yy300;
goto yy357;
} else {
if (yych <= '`') goto yy300;
if (yych <= 'z') goto yy357;
goto yy300;
}
}
yy359:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
yy360:
if (yych <= 0x1F) {
if (yych == '\t') goto yy359;
goto yy300;
} else {
if (yych <= ' ') goto yy359;
if (yych <= '0') goto yy300;
if (yych <= '9') {
yyt1 = YYCURSOR;
goto yy363;
}
goto yy300;
}
yy361:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == 'e') goto yy365;
goto yy300;
yy362:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy367;
if (yych == '\r') goto yy369;
goto yy300;
yy363:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '\r') {
if (yych <= '\t') {
if (yych <= 0x08) goto yy300;
goto yy370;
} else {
if (yych <= '\n') goto yy372;
if (yych <= '\f') goto yy300;
goto yy374;
}
} else {
if (yych <= ' ') {
if (yych <= 0x1F) goto yy300;
goto yy370;
} else {
if (yych <= '/') goto yy300;
if (yych <= '9') goto yy363;
goto yy300;
}
}
yy365:
yyaccept = 7;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych == '\t') goto yy375;
if (yych == ' ') goto yy375;
yy366:
#line 478 "../src/parse/lex.re"
{
msg.error(tok_loc(), "ill-formed include directive"
", expected format: `!include \"<file>\" ; <newline>`");
exit(1);
}
#line 2562 "src/parse/lex.cc"
yy367:
++YYCURSOR;
x = yyt1;
y = yyt2;
#line 484 "../src/parse/lex.re"
{
next_line();
yylval.str = newstr(x, y); // save the name of the used block
return TOKEN_BLOCK;
}
#line 2573 "src/parse/lex.cc"
yy369:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy367;
goto yy300;
yy370:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x1F) {
if (yych == '\t') goto yy370;
goto yy300;
} else {
if (yych <= ' ') goto yy370;
if (yych == '"') goto yy377;
goto yy300;
}
yy372:
++YYCURSOR;
YYCURSOR = yyt1;
#line 502 "../src/parse/lex.re"
{
set_sourceline ();
return TOKEN_LINE_INFO;
}
#line 2598 "src/parse/lex.cc"
yy374:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy372;
goto yy300;
yy375:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x1F) {
if (yych == '\t') goto yy375;
goto yy300;
} else {
if (yych <= ' ') goto yy375;
if (yych == '"') {
yyt1 = YYCURSOR;
goto yy379;
}
goto yy300;
}
yy377:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 128) {
goto yy377;
}
if (yych <= '\n') goto yy300;
if (yych <= '"') goto yy381;
goto yy382;
yy379:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '!') {
if (yych <= 0x00) goto yy300;
if (yych == '\n') goto yy300;
goto yy379;
} else {
if (yych <= '"') goto yy383;
if (yych == '\\') goto yy384;
goto yy379;
}
yy381:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy372;
if (yych == '\r') goto yy374;
goto yy300;
yy382:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x00) goto yy300;
if (yych == '\n') goto yy300;
goto yy377;
yy383:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x1F) {
if (yych == '\t') {
yyt2 = YYCURSOR;
goto yy385;
}
goto yy300;
} else {
if (yych <= ' ') {
yyt2 = YYCURSOR;
goto yy385;
}
if (yych == ';') {
yyt2 = YYCURSOR;
goto yy387;
}
goto yy300;
}
yy384:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x00) goto yy300;
if (yych == '\n') goto yy300;
goto yy379;
yy385:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x1F) {
if (yych == '\t') goto yy385;
goto yy300;
} else {
if (yych <= ' ') goto yy385;
if (yych != ';') goto yy300;
}
yy387:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy388;
if (yych == '\r') goto yy390;
goto yy300;
yy388:
++YYCURSOR;
x = yyt1;
y = yyt2;
#line 473 "../src/parse/lex.re"
{
next_line();
include(getstr(x + 1, y - 1));
goto scan;
}
#line 2705 "src/parse/lex.cc"
yy390:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy388;
goto yy300;
}
#line 522 "../src/parse/lex.re"
}
bool Scanner::lex_namedef_context_re2c()
{
#line 2718 "src/parse/lex.cc"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
128, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*(YYMARKER = YYCURSOR);
if (yych <= 0x1F) {
if (yych == '\t') {
yyt1 = YYCURSOR;
goto yy394;
}
} else {
if (yych <= ' ') {
yyt1 = YYCURSOR;
goto yy394;
}
if (yych == '=') {
yyt1 = YYCURSOR;
goto yy397;
}
}
yy393:
#line 529 "../src/parse/lex.re"
{ return false; }
#line 2775 "src/parse/lex.cc"
yy394:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 128) {
goto yy394;
}
if (yych == '=') goto yy397;
yy396:
YYCURSOR = YYMARKER;
goto yy393;
yy397:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '>') goto yy396;
++YYCURSOR;
YYCURSOR = yyt1;
#line 528 "../src/parse/lex.re"
{ return true; }
#line 2794 "src/parse/lex.cc"
}
#line 530 "../src/parse/lex.re"
}
bool Scanner::lex_namedef_context_flex()
{
#line 2803 "src/parse/lex.cc"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
128, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych == '\t') {
yyt1 = YYCURSOR;
goto yy403;
}
if (yych == ' ') {
yyt1 = YYCURSOR;
goto yy403;
}
#line 538 "../src/parse/lex.re"
{ return false; }
#line 2852 "src/parse/lex.cc"
yy403:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 128) {
goto yy403;
}
if (yych <= '<') {
if (yych == ':') goto yy406;
} else {
if (yych <= '=') goto yy406;
if (yych == '{') goto yy406;
}
YYCURSOR = yyt1;
#line 537 "../src/parse/lex.re"
{ return true; }
#line 2869 "src/parse/lex.cc"
yy406:
++YYCURSOR;
YYCURSOR = yyt1;
#line 536 "../src/parse/lex.re"
{ return false; }
#line 2875 "src/parse/lex.cc"
}
#line 539 "../src/parse/lex.re"
}
int Scanner::lex_clist()
{
int kind = TOKEN_CLIST;
CondList *cl = new CondList;
#line 2886 "src/parse/lex.cc"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
128, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
goto yy408;
yy409:
++YYCURSOR;
yy408:
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 128) {
goto yy409;
}
if (yych <= 0x1F) goto yy411;
if (yych <= '!') goto yy412;
if (yych == '>') goto yy415;
yy411:
#line 549 "../src/parse/lex.re"
{ goto cond; }
#line 2938 "src/parse/lex.cc"
yy412:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych == '\t') goto yy412;
if (yych == ' ') goto yy412;
#line 547 "../src/parse/lex.re"
{ kind = TOKEN_CSETUP; goto cond; }
#line 2947 "src/parse/lex.cc"
yy415:
++YYCURSOR;
#line 548 "../src/parse/lex.re"
{ kind = TOKEN_CZERO; goto end; }
#line 2952 "src/parse/lex.cc"
}
#line 550 "../src/parse/lex.re"
cond:
tok = cur;
#line 2959 "src/parse/lex.cc"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 0, 0, 0, 0, 0, 0,
0, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 0, 0, 0, 0, 128,
0, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 'Z') {
if (yych == '*') goto yy421;
if (yych >= 'A') goto yy423;
} else {
if (yych <= '_') {
if (yych >= '_') goto yy423;
} else {
if (yych <= '`') goto yy419;
if (yych <= 'z') goto yy423;
}
}
yy419:
++YYCURSOR;
#line 556 "../src/parse/lex.re"
{ goto error; }
#line 3013 "src/parse/lex.cc"
yy421:
++YYCURSOR;
#line 555 "../src/parse/lex.re"
{ if (!cl->empty()) goto error; cl->insert("*"); goto next; }
#line 3018 "src/parse/lex.cc"
yy423:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 128) {
goto yy423;
}
#line 554 "../src/parse/lex.re"
{ cl->insert(getstr(tok, cur)); goto next; }
#line 3028 "src/parse/lex.cc"
}
#line 557 "../src/parse/lex.re"
next:
#line 3034 "src/parse/lex.cc"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 128, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
128, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= ' ') {
if (yych == '\t') goto yy430;
if (yych >= ' ') goto yy430;
} else {
if (yych <= ',') {
if (yych >= ',') goto yy431;
} else {
if (yych == '>') goto yy434;
}
}
++YYCURSOR;
yy429:
#line 562 "../src/parse/lex.re"
{ goto error; }
#line 3087 "src/parse/lex.cc"
yy430:
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= ' ') {
if (yych == '\t') goto yy436;
if (yych <= 0x1F) goto yy429;
goto yy436;
} else {
if (yych <= ',') {
if (yych <= '+') goto yy429;
} else {
if (yych == '>') goto yy434;
goto yy429;
}
}
yy431:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 128) {
goto yy431;
}
#line 560 "../src/parse/lex.re"
{ goto cond; }
#line 3111 "src/parse/lex.cc"
yy434:
++YYCURSOR;
#line 561 "../src/parse/lex.re"
{ goto end; }
#line 3116 "src/parse/lex.cc"
yy436:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= ' ') {
if (yych == '\t') goto yy436;
if (yych >= ' ') goto yy436;
} else {
if (yych <= ',') {
if (yych >= ',') goto yy431;
} else {
if (yych == '>') goto yy434;
}
}
YYCURSOR = YYMARKER;
goto yy429;
}
#line 563 "../src/parse/lex.re"
end:
yylval.clist = cl;
return kind;
error:
delete cl;
msg.error(cur_loc(), "syntax error in condition list");
exit(1);
}
void Scanner::lex_code_indented()
{
const loc_t &loc = tok_loc();
tok = cur;
code:
#line 3151 "src/parse/lex.cc"
{
YYCTYPE yych;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '&') {
if (yych <= '\f') {
if (yych <= 0x00) goto yy441;
if (yych == '\n') goto yy445;
goto yy443;
} else {
if (yych <= '\r') goto yy447;
if (yych == '"') goto yy448;
goto yy443;
}
} else {
if (yych <= 'z') {
if (yych <= '\'') goto yy448;
if (yych == '/') goto yy450;
goto yy443;
} else {
if (yych == '|') goto yy443;
if (yych <= '}') goto yy451;
goto yy443;
}
}
yy441:
++YYCURSOR;
#line 589 "../src/parse/lex.re"
{ fail_if_eof(); goto code; }
#line 3181 "src/parse/lex.cc"
yy443:
++YYCURSOR;
yy444:
#line 597 "../src/parse/lex.re"
{ goto code; }
#line 3187 "src/parse/lex.cc"
yy445:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '\f') {
if (yych <= 0x08) goto yy446;
if (yych <= '\n') goto yy453;
} else {
if (yych <= '\r') goto yy453;
if (yych == ' ') goto yy453;
}
yy446:
#line 580 "../src/parse/lex.re"
{
next_line();
while (isspace(tok[0])) ++tok;
char *p = cur;
while (p > tok && isspace(p[-1])) --p;
yylval.semact = new SemAct(loc, getstr(tok, p));
return;
}
#line 3207 "src/parse/lex.cc"
yy447:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy445;
goto yy444;
yy448:
++YYCURSOR;
#line 596 "../src/parse/lex.re"
{ lex_string(cur[-1]); goto code; }
#line 3216 "src/parse/lex.cc"
yy450:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '*') goto yy455;
if (yych == '/') goto yy457;
goto yy444;
yy451:
++YYCURSOR;
#line 590 "../src/parse/lex.re"
{
msg.error(cur_loc(), "Curly braces are not allowed after ':='");
exit(1);
}
#line 3229 "src/parse/lex.cc"
yy453:
++YYCURSOR;
YYCURSOR -= 1;
#line 579 "../src/parse/lex.re"
{ next_line(); goto code; }
#line 3235 "src/parse/lex.cc"
yy455:
++YYCURSOR;
#line 594 "../src/parse/lex.re"
{ lex_c_comment(); goto code; }
#line 3240 "src/parse/lex.cc"
yy457:
++YYCURSOR;
#line 595 "../src/parse/lex.re"
{ lex_cpp_comment(); goto code; }
#line 3245 "src/parse/lex.cc"
}
#line 598 "../src/parse/lex.re"
}
void Scanner::lex_code_in_braces()
{
const loc_t &loc = tok_loc();
uint32_t depth = 1;
code:
#line 3257 "src/parse/lex.cc"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
0, 128, 128, 128, 128, 128, 128, 128,
128, 160, 0, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
160, 128, 0, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
192, 192, 192, 192, 192, 192, 192, 192,
192, 192, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 0, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
};
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '&') {
if (yych <= '\f') {
if (yych <= 0x00) goto yy461;
if (yych == '\n') goto yy465;
goto yy463;
} else {
if (yych <= '\r') goto yy467;
if (yych == '"') goto yy468;
goto yy463;
}
} else {
if (yych <= 'z') {
if (yych <= '\'') goto yy468;
if (yych == '/') goto yy470;
goto yy463;
} else {
if (yych <= '{') goto yy471;
if (yych == '}') goto yy473;
goto yy463;
}
}
yy461:
++YYCURSOR;
#line 618 "../src/parse/lex.re"
{ fail_if_eof(); goto code; }
#line 3321 "src/parse/lex.cc"
yy463:
++YYCURSOR;
yy464:
#line 622 "../src/parse/lex.re"
{ goto code; }
#line 3327 "src/parse/lex.cc"
yy465:
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yybm[0+yych] & 32) {
goto yy475;
}
if (yych == '#') goto yy478;
yy466:
#line 617 "../src/parse/lex.re"
{ next_line(); goto code; }
#line 3337 "src/parse/lex.cc"
yy467:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy465;
goto yy464;
yy468:
++YYCURSOR;
#line 621 "../src/parse/lex.re"
{ lex_string(cur[-1]); goto code; }
#line 3346 "src/parse/lex.cc"
yy470:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '*') goto yy480;
if (yych == '/') goto yy482;
goto yy464;
yy471:
++YYCURSOR;
#line 615 "../src/parse/lex.re"
{ ++depth; goto code; }
#line 3356 "src/parse/lex.cc"
yy473:
++YYCURSOR;
#line 607 "../src/parse/lex.re"
{
if (--depth == 0) {
yylval.semact = new SemAct(loc, getstr(tok, cur));
return;
}
goto code;
}
#line 3367 "src/parse/lex.cc"
yy475:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 32) {
goto yy475;
}
if (yych == '#') goto yy478;
yy477:
YYCURSOR = YYMARKER;
goto yy466;
yy478:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 5) YYFILL(5);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x1F) {
if (yych == '\t') goto yy478;
goto yy477;
} else {
if (yych <= ' ') goto yy478;
if (yych == 'l') goto yy484;
goto yy477;
}
yy480:
++YYCURSOR;
#line 619 "../src/parse/lex.re"
{ lex_c_comment(); goto code; }
#line 3395 "src/parse/lex.cc"
yy482:
++YYCURSOR;
#line 620 "../src/parse/lex.re"
{ lex_cpp_comment(); goto code; }
#line 3400 "src/parse/lex.cc"
yy484:
yych = (YYCTYPE)*++YYCURSOR;
if (yych != 'i') goto yy477;
yych = (YYCTYPE)*++YYCURSOR;
if (yych != 'n') goto yy477;
yych = (YYCTYPE)*++YYCURSOR;
if (yych != 'e') goto yy477;
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '0') goto yy489;
if (yych <= '9') goto yy477;
goto yy489;
yy488:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
yy489:
if (yych <= 0x1F) {
if (yych == '\t') goto yy488;
goto yy477;
} else {
if (yych <= ' ') goto yy488;
if (yych <= '0') goto yy477;
if (yych >= ':') goto yy477;
yyt1 = YYCURSOR;
}
yy490:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 64) {
goto yy490;
}
if (yych <= '\f') {
if (yych <= 0x08) goto yy477;
if (yych <= '\t') goto yy492;
if (yych <= '\n') goto yy494;
goto yy477;
} else {
if (yych <= '\r') goto yy496;
if (yych != ' ') goto yy477;
}
yy492:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x1F) {
if (yych == '\t') goto yy492;
goto yy477;
} else {
if (yych <= ' ') goto yy492;
if (yych == '"') goto yy497;
goto yy477;
}
yy494:
++YYCURSOR;
YYCURSOR = yyt1;
#line 616 "../src/parse/lex.re"
{ set_sourceline (); goto code; }
#line 3459 "src/parse/lex.cc"
yy496:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy494;
goto yy477;
yy497:
++YYCURSOR;
if ((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 128) {
goto yy497;
}
if (yych <= '\n') goto yy477;
if (yych >= '#') goto yy500;
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy494;
if (yych == '\r') goto yy496;
goto yy477;
yy500:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x00) goto yy477;
if (yych == '\n') goto yy477;
goto yy497;
}
#line 623 "../src/parse/lex.re"
}
void Scanner::lex_string(char delim)
{
loop:
#line 3493 "src/parse/lex.cc"
{
YYCTYPE yych;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '!') {
if (yych <= '\n') {
if (yych <= 0x00) goto yy503;
if (yych <= '\t') goto yy505;
goto yy507;
} else {
if (yych == '\r') goto yy509;
goto yy505;
}
} else {
if (yych <= '\'') {
if (yych <= '"') goto yy510;
if (yych <= '&') goto yy505;
goto yy510;
} else {
if (yych == '\\') goto yy512;
goto yy505;
}
}
yy503:
++YYCURSOR;
#line 633 "../src/parse/lex.re"
{ fail_if_eof(); goto loop; }
#line 3521 "src/parse/lex.cc"
yy505:
++YYCURSOR;
yy506:
#line 634 "../src/parse/lex.re"
{ goto loop; }
#line 3527 "src/parse/lex.cc"
yy507:
++YYCURSOR;
#line 632 "../src/parse/lex.re"
{ next_line(); goto loop; }
#line 3532 "src/parse/lex.cc"
yy509:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy507;
goto yy506;
yy510:
++YYCURSOR;
#line 630 "../src/parse/lex.re"
{ if (cur[-1] == delim) return; else goto loop; }
#line 3541 "src/parse/lex.cc"
yy512:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '&') {
if (yych != '"') goto yy506;
} else {
if (yych <= '\'') goto yy513;
if (yych != '\\') goto yy506;
}
yy513:
++YYCURSOR;
#line 631 "../src/parse/lex.re"
{ goto loop; }
#line 3554 "src/parse/lex.cc"
}
#line 635 "../src/parse/lex.re"
}
void Scanner::lex_c_comment()
{
loop:
#line 3564 "src/parse/lex.cc"
{
YYCTYPE yych;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '\f') {
if (yych <= 0x00) goto yy517;
if (yych == '\n') goto yy521;
goto yy519;
} else {
if (yych <= '\r') goto yy523;
if (yych == '*') goto yy524;
goto yy519;
}
yy517:
++YYCURSOR;
#line 644 "../src/parse/lex.re"
{ fail_if_eof(); goto loop; }
#line 3582 "src/parse/lex.cc"
yy519:
++YYCURSOR;
yy520:
#line 645 "../src/parse/lex.re"
{ goto loop; }
#line 3588 "src/parse/lex.cc"
yy521:
++YYCURSOR;
#line 643 "../src/parse/lex.re"
{ next_line(); goto loop; }
#line 3593 "src/parse/lex.cc"
yy523:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy521;
goto yy520;
yy524:
yych = (YYCTYPE)*++YYCURSOR;
if (yych != '/') goto yy520;
++YYCURSOR;
#line 642 "../src/parse/lex.re"
{ return; }
#line 3604 "src/parse/lex.cc"
}
#line 646 "../src/parse/lex.re"
}
void Scanner::lex_cpp_comment()
{
loop:
#line 3614 "src/parse/lex.cc"
{
YYCTYPE yych;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '\n') {
if (yych <= 0x00) goto yy529;
if (yych <= '\t') goto yy531;
goto yy533;
} else {
if (yych == '\r') goto yy535;
goto yy531;
}
yy529:
++YYCURSOR;
#line 654 "../src/parse/lex.re"
{ fail_if_eof(); goto loop; }
#line 3631 "src/parse/lex.cc"
yy531:
++YYCURSOR;
yy532:
#line 655 "../src/parse/lex.re"
{ goto loop; }
#line 3637 "src/parse/lex.cc"
yy533:
++YYCURSOR;
#line 653 "../src/parse/lex.re"
{ next_line(); return; }
#line 3642 "src/parse/lex.cc"
yy535:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy533;
goto yy532;
}
#line 656 "../src/parse/lex.re"
}
const AST *Scanner::lex_cls(bool neg)
{
std::vector<ASTRange> *cls = new std::vector<ASTRange>;
uint32_t u, l;
const loc_t &loc0 = tok_loc();
loc_t loc = cur_loc();
fst:
tok = cur;
#line 3661 "src/parse/lex.cc"
{
YYCTYPE yych;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych == ']') goto yy539;
#line 669 "../src/parse/lex.re"
{ l = lex_cls_chr(); goto snd; }
#line 3669 "src/parse/lex.cc"
yy539:
++YYCURSOR;
#line 668 "../src/parse/lex.re"
{ return ast_cls(loc0, cls, neg); }
#line 3674 "src/parse/lex.cc"
}
#line 670 "../src/parse/lex.re"
snd:
#line 3680 "src/parse/lex.cc"
{
YYCTYPE yych;
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*(YYMARKER = YYCURSOR);
if (yych == '-') goto yy544;
yy543:
#line 673 "../src/parse/lex.re"
{ u = l; goto add; }
#line 3689 "src/parse/lex.cc"
yy544:
yych = (YYCTYPE)*++YYCURSOR;
if (yych != ']') goto yy546;
YYCURSOR = YYMARKER;
goto yy543;
yy546:
++YYCURSOR;
YYCURSOR -= 1;
#line 674 "../src/parse/lex.re"
{
u = lex_cls_chr();
if (l > u) {
msg.warn.swapped_range(loc, l, u);
std::swap(l, u);
}
goto add;
}
#line 3707 "src/parse/lex.cc"
}
#line 682 "../src/parse/lex.re"
add:
cls->push_back(ASTRange(l, u, loc));
loc = cur_loc();
goto fst;
}
uint32_t Scanner::lex_cls_chr()
{
tok = cur;
const loc_t &loc = cur_loc();
#line 719 "../src/parse/lex.re"
if (globopts->input_encoding == Enc::ASCII) {
#line 3725 "src/parse/lex.cc"
{
YYCTYPE yych;
unsigned int yyaccept = 0;
if ((YYLIMIT - YYCURSOR) < 10) YYFILL(10);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '\f') {
if (yych <= 0x00) goto yy550;
if (yych == '\n') goto yy554;
goto yy552;
} else {
if (yych <= '\r') goto yy556;
if (yych == '\\') goto yy557;
goto yy552;
}
yy550:
++YYCURSOR;
#line 700 "../src/parse/lex.re"
{ fail_if_eof(); return 0; }
#line 3744 "src/parse/lex.cc"
yy552:
++YYCURSOR;
yy553:
#line 702 "../src/parse/lex.re"
{ return decode(tok); }
#line 3750 "src/parse/lex.cc"
yy554:
++YYCURSOR;
#line 694 "../src/parse/lex.re"
{ msg.error(loc, "newline in character class"); exit(1); }
#line 3755 "src/parse/lex.cc"
yy556:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy554;
goto yy553;
yy557:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '\\') {
if (yych <= '/') {
if (yych <= '\f') {
if (yych <= 0x00) goto yy558;
if (yych == '\n') goto yy554;
goto yy559;
} else {
if (yych <= '\r') goto yy561;
if (yych == '-') goto yy562;
goto yy559;
}
} else {
if (yych <= 'U') {
if (yych <= '3') goto yy564;
if (yych <= '7') goto yy566;
if (yych <= 'T') goto yy559;
goto yy567;
} else {
if (yych == 'X') goto yy569;
if (yych <= '[') goto yy559;
goto yy570;
}
}
} else {
if (yych <= 'n') {
if (yych <= 'b') {
if (yych <= ']') goto yy572;
if (yych <= '`') goto yy559;
if (yych <= 'a') goto yy574;
goto yy576;
} else {
if (yych == 'f') goto yy578;
if (yych <= 'm') goto yy559;
goto yy580;
}
} else {
if (yych <= 't') {
if (yych == 'r') goto yy582;
if (yych <= 's') goto yy559;
goto yy584;
} else {
if (yych <= 'v') {
if (yych <= 'u') goto yy569;
goto yy586;
} else {
if (yych == 'x') goto yy588;
goto yy559;
}
}
}
}
yy558:
#line 697 "../src/parse/lex.re"
{ msg.error(loc, "syntax error in escape sequence"); exit(1); }
#line 3816 "src/parse/lex.cc"
yy559:
++YYCURSOR;
yy560:
#line 715 "../src/parse/lex.re"
{
msg.warn.useless_escape(loc, tok, cur);
return decode(tok + 1);
}
#line 3825 "src/parse/lex.cc"
yy561:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy554;
goto yy560;
yy562:
++YYCURSOR;
#line 713 "../src/parse/lex.re"
{ return static_cast<uint8_t>('-'); }
#line 3834 "src/parse/lex.cc"
yy564:
yyaccept = 0;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy565;
if (yych <= '7') goto yy589;
yy565:
#line 696 "../src/parse/lex.re"
{ msg.error(loc, "syntax error in octal escape sequence"); exit(1); }
#line 3843 "src/parse/lex.cc"
yy566:
++YYCURSOR;
goto yy565;
yy567:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy568;
if (yych <= '9') goto yy591;
} else {
if (yych <= 'F') goto yy591;
if (yych <= '`') goto yy568;
if (yych <= 'f') goto yy591;
}
yy568:
#line 695 "../src/parse/lex.re"
{ msg.error(loc, "syntax error in hexadecimal escape sequence"); exit(1); }
#line 3861 "src/parse/lex.cc"
yy569:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy568;
if (yych <= '9') goto yy592;
goto yy568;
} else {
if (yych <= 'F') goto yy592;
if (yych <= '`') goto yy568;
if (yych <= 'f') goto yy592;
goto yy568;
}
yy570:
++YYCURSOR;
#line 712 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\\'); }
#line 3879 "src/parse/lex.cc"
yy572:
++YYCURSOR;
#line 714 "../src/parse/lex.re"
{ return static_cast<uint8_t>(']'); }
#line 3884 "src/parse/lex.cc"
yy574:
++YYCURSOR;
#line 705 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\a'); }
#line 3889 "src/parse/lex.cc"
yy576:
++YYCURSOR;
#line 706 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\b'); }
#line 3894 "src/parse/lex.cc"
yy578:
++YYCURSOR;
#line 707 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\f'); }
#line 3899 "src/parse/lex.cc"
yy580:
++YYCURSOR;
#line 708 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\n'); }
#line 3904 "src/parse/lex.cc"
yy582:
++YYCURSOR;
#line 709 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\r'); }
#line 3909 "src/parse/lex.cc"
yy584:
++YYCURSOR;
#line 710 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\t'); }
#line 3914 "src/parse/lex.cc"
yy586:
++YYCURSOR;
#line 711 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\v'); }
#line 3919 "src/parse/lex.cc"
yy588:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy568;
if (yych <= '9') goto yy593;
goto yy568;
} else {
if (yych <= 'F') goto yy593;
if (yych <= '`') goto yy568;
if (yych <= 'f') goto yy593;
goto yy568;
}
yy589:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '/') goto yy590;
if (yych <= '7') goto yy594;
yy590:
YYCURSOR = YYMARKER;
if (yyaccept == 0) {
goto yy565;
} else {
goto yy568;
}
yy591:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy590;
if (yych <= '9') goto yy596;
goto yy590;
} else {
if (yych <= 'F') goto yy596;
if (yych <= '`') goto yy590;
if (yych <= 'f') goto yy596;
goto yy590;
}
yy592:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy590;
if (yych <= '9') goto yy597;
goto yy590;
} else {
if (yych <= 'F') goto yy597;
if (yych <= '`') goto yy590;
if (yych <= 'f') goto yy597;
goto yy590;
}
yy593:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy590;
if (yych <= '9') goto yy598;
goto yy590;
} else {
if (yych <= 'F') goto yy598;
if (yych <= '`') goto yy590;
if (yych <= 'f') goto yy598;
goto yy590;
}
yy594:
++YYCURSOR;
#line 704 "../src/parse/lex.re"
{ return unesc_oct(tok, cur); }
#line 3984 "src/parse/lex.cc"
yy596:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy590;
if (yych <= '9') goto yy600;
goto yy590;
} else {
if (yych <= 'F') goto yy600;
if (yych <= '`') goto yy590;
if (yych <= 'f') goto yy600;
goto yy590;
}
yy597:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy590;
if (yych <= '9') goto yy593;
goto yy590;
} else {
if (yych <= 'F') goto yy593;
if (yych <= '`') goto yy590;
if (yych <= 'f') goto yy593;
goto yy590;
}
yy598:
++YYCURSOR;
#line 703 "../src/parse/lex.re"
{ return unesc_hex(tok, cur); }
#line 4013 "src/parse/lex.cc"
yy600:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy590;
if (yych >= ':') goto yy590;
} else {
if (yych <= 'F') goto yy601;
if (yych <= '`') goto yy590;
if (yych >= 'g') goto yy590;
}
yy601:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy590;
if (yych <= '9') goto yy592;
goto yy590;
} else {
if (yych <= 'F') goto yy592;
if (yych <= '`') goto yy590;
if (yych <= 'f') goto yy592;
goto yy590;
}
}
#line 721 "../src/parse/lex.re"
}
else {
#line 4042 "src/parse/lex.cc"
{
YYCTYPE yych;
unsigned int yyaccept = 0;
if ((YYLIMIT - YYCURSOR) < 10) YYFILL(10);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x7F) {
if (yych <= '\f') {
if (yych <= 0x00) goto yy604;
if (yych == '\n') goto yy608;
goto yy606;
} else {
if (yych <= '\r') goto yy610;
if (yych == '\\') goto yy611;
goto yy606;
}
} else {
if (yych <= 0xEF) {
if (yych <= 0xC1) goto yy613;
if (yych <= 0xDF) goto yy615;
if (yych <= 0xE0) goto yy616;
goto yy617;
} else {
if (yych <= 0xF0) goto yy618;
if (yych <= 0xF3) goto yy619;
if (yych <= 0xF4) goto yy620;
goto yy613;
}
}
yy604:
++YYCURSOR;
#line 700 "../src/parse/lex.re"
{ fail_if_eof(); return 0; }
#line 4075 "src/parse/lex.cc"
yy606:
++YYCURSOR;
yy607:
#line 702 "../src/parse/lex.re"
{ return decode(tok); }
#line 4081 "src/parse/lex.cc"
yy608:
++YYCURSOR;
#line 694 "../src/parse/lex.re"
{ msg.error(loc, "newline in character class"); exit(1); }
#line 4086 "src/parse/lex.cc"
yy610:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy608;
goto yy607;
yy611:
yyaccept = 0;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 'b') {
if (yych <= '7') {
if (yych <= '\r') {
if (yych <= '\t') {
if (yych >= 0x01) goto yy621;
} else {
if (yych <= '\n') goto yy608;
if (yych <= '\f') goto yy621;
goto yy623;
}
} else {
if (yych <= '-') {
if (yych <= ',') goto yy621;
goto yy624;
} else {
if (yych <= '/') goto yy621;
if (yych <= '3') goto yy626;
goto yy628;
}
}
} else {
if (yych <= '[') {
if (yych <= 'U') {
if (yych <= 'T') goto yy621;
goto yy629;
} else {
if (yych == 'X') goto yy631;
goto yy621;
}
} else {
if (yych <= ']') {
if (yych <= '\\') goto yy632;
goto yy634;
} else {
if (yych <= '`') goto yy621;
if (yych <= 'a') goto yy636;
goto yy638;
}
}
}
} else {
if (yych <= 'v') {
if (yych <= 'q') {
if (yych <= 'f') {
if (yych <= 'e') goto yy621;
goto yy640;
} else {
if (yych == 'n') goto yy642;
goto yy621;
}
} else {
if (yych <= 's') {
if (yych <= 'r') goto yy644;
goto yy621;
} else {
if (yych <= 't') goto yy646;
if (yych <= 'u') goto yy631;
goto yy648;
}
}
} else {
if (yych <= 0xDF) {
if (yych <= 'x') {
if (yych <= 'w') goto yy621;
goto yy650;
} else {
if (yych <= 0x7F) goto yy621;
if (yych >= 0xC2) goto yy651;
}
} else {
if (yych <= 0xF0) {
if (yych <= 0xE0) goto yy653;
if (yych <= 0xEF) goto yy654;
goto yy655;
} else {
if (yych <= 0xF3) goto yy656;
if (yych <= 0xF4) goto yy657;
}
}
}
}
yy612:
#line 697 "../src/parse/lex.re"
{ msg.error(loc, "syntax error in escape sequence"); exit(1); }
#line 4178 "src/parse/lex.cc"
yy613:
++YYCURSOR;
yy614:
#line 698 "../src/parse/lex.re"
{ msg.error(loc, "syntax error"); exit(1); }
#line 4184 "src/parse/lex.cc"
yy615:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy614;
if (yych <= 0xBF) goto yy606;
goto yy614;
yy616:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x9F) goto yy614;
if (yych <= 0xBF) goto yy658;
goto yy614;
yy617:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x7F) goto yy614;
if (yych <= 0xBF) goto yy658;
goto yy614;
yy618:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x8F) goto yy614;
if (yych <= 0xBF) goto yy659;
goto yy614;
yy619:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x7F) goto yy614;
if (yych <= 0xBF) goto yy659;
goto yy614;
yy620:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x7F) goto yy614;
if (yych <= 0x8F) goto yy659;
goto yy614;
yy621:
++YYCURSOR;
yy622:
#line 715 "../src/parse/lex.re"
{
msg.warn.useless_escape(loc, tok, cur);
return decode(tok + 1);
}
#line 4228 "src/parse/lex.cc"
yy623:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy608;
goto yy622;
yy624:
++YYCURSOR;
#line 713 "../src/parse/lex.re"
{ return static_cast<uint8_t>('-'); }
#line 4237 "src/parse/lex.cc"
yy626:
yyaccept = 2;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy627;
if (yych <= '7') goto yy660;
yy627:
#line 696 "../src/parse/lex.re"
{ msg.error(loc, "syntax error in octal escape sequence"); exit(1); }
#line 4246 "src/parse/lex.cc"
yy628:
++YYCURSOR;
goto yy627;
yy629:
yyaccept = 3;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy630;
if (yych <= '9') goto yy661;
} else {
if (yych <= 'F') goto yy661;
if (yych <= '`') goto yy630;
if (yych <= 'f') goto yy661;
}
yy630:
#line 695 "../src/parse/lex.re"
{ msg.error(loc, "syntax error in hexadecimal escape sequence"); exit(1); }
#line 4264 "src/parse/lex.cc"
yy631:
yyaccept = 3;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy630;
if (yych <= '9') goto yy662;
goto yy630;
} else {
if (yych <= 'F') goto yy662;
if (yych <= '`') goto yy630;
if (yych <= 'f') goto yy662;
goto yy630;
}
yy632:
++YYCURSOR;
#line 712 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\\'); }
#line 4282 "src/parse/lex.cc"
yy634:
++YYCURSOR;
#line 714 "../src/parse/lex.re"
{ return static_cast<uint8_t>(']'); }
#line 4287 "src/parse/lex.cc"
yy636:
++YYCURSOR;
#line 705 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\a'); }
#line 4292 "src/parse/lex.cc"
yy638:
++YYCURSOR;
#line 706 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\b'); }
#line 4297 "src/parse/lex.cc"
yy640:
++YYCURSOR;
#line 707 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\f'); }
#line 4302 "src/parse/lex.cc"
yy642:
++YYCURSOR;
#line 708 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\n'); }
#line 4307 "src/parse/lex.cc"
yy644:
++YYCURSOR;
#line 709 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\r'); }
#line 4312 "src/parse/lex.cc"
yy646:
++YYCURSOR;
#line 710 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\t'); }
#line 4317 "src/parse/lex.cc"
yy648:
++YYCURSOR;
#line 711 "../src/parse/lex.re"
{ return static_cast<uint8_t>('\v'); }
#line 4322 "src/parse/lex.cc"
yy650:
yyaccept = 3;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy630;
if (yych <= '9') goto yy663;
goto yy630;
} else {
if (yych <= 'F') goto yy663;
if (yych <= '`') goto yy630;
if (yych <= 'f') goto yy663;
goto yy630;
}
yy651:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy652;
if (yych <= 0xBF) goto yy621;
yy652:
YYCURSOR = YYMARKER;
if (yyaccept <= 1) {
if (yyaccept == 0) {
goto yy612;
} else {
goto yy614;
}
} else {
if (yyaccept == 2) {
goto yy627;
} else {
goto yy630;
}
}
yy653:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x9F) goto yy652;
if (yych <= 0xBF) goto yy651;
goto yy652;
yy654:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy652;
if (yych <= 0xBF) goto yy651;
goto yy652;
yy655:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x8F) goto yy652;
if (yych <= 0xBF) goto yy654;
goto yy652;
yy656:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy652;
if (yych <= 0xBF) goto yy654;
goto yy652;
yy657:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy652;
if (yych <= 0x8F) goto yy654;
goto yy652;
yy658:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy652;
if (yych <= 0xBF) goto yy606;
goto yy652;
yy659:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy652;
if (yych <= 0xBF) goto yy658;
goto yy652;
yy660:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '/') goto yy652;
if (yych <= '7') goto yy664;
goto yy652;
yy661:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy652;
if (yych <= '9') goto yy666;
goto yy652;
} else {
if (yych <= 'F') goto yy666;
if (yych <= '`') goto yy652;
if (yych <= 'f') goto yy666;
goto yy652;
}
yy662:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy652;
if (yych <= '9') goto yy667;
goto yy652;
} else {
if (yych <= 'F') goto yy667;
if (yych <= '`') goto yy652;
if (yych <= 'f') goto yy667;
goto yy652;
}
yy663:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy652;
if (yych <= '9') goto yy668;
goto yy652;
} else {
if (yych <= 'F') goto yy668;
if (yych <= '`') goto yy652;
if (yych <= 'f') goto yy668;
goto yy652;
}
yy664:
++YYCURSOR;
#line 704 "../src/parse/lex.re"
{ return unesc_oct(tok, cur); }
#line 4435 "src/parse/lex.cc"
yy666:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy652;
if (yych <= '9') goto yy670;
goto yy652;
} else {
if (yych <= 'F') goto yy670;
if (yych <= '`') goto yy652;
if (yych <= 'f') goto yy670;
goto yy652;
}
yy667:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy652;
if (yych <= '9') goto yy663;
goto yy652;
} else {
if (yych <= 'F') goto yy663;
if (yych <= '`') goto yy652;
if (yych <= 'f') goto yy663;
goto yy652;
}
yy668:
++YYCURSOR;
#line 703 "../src/parse/lex.re"
{ return unesc_hex(tok, cur); }
#line 4464 "src/parse/lex.cc"
yy670:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy652;
if (yych >= ':') goto yy652;
} else {
if (yych <= 'F') goto yy671;
if (yych <= '`') goto yy652;
if (yych >= 'g') goto yy652;
}
yy671:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy652;
if (yych <= '9') goto yy662;
goto yy652;
} else {
if (yych <= 'F') goto yy662;
if (yych <= '`') goto yy652;
if (yych <= 'f') goto yy662;
goto yy652;
}
}
#line 724 "../src/parse/lex.re"
#line 724 "../src/parse/lex.re"
}
}
bool Scanner::lex_str_chr(char quote, ASTChar &ast)
{
tok = cur;
ast.loc = cur_loc();
#line 758 "../src/parse/lex.re"
if (globopts->input_encoding == Enc::ASCII) {
#line 4503 "src/parse/lex.cc"
{
YYCTYPE yych;
unsigned int yyaccept = 0;
if ((YYLIMIT - YYCURSOR) < 10) YYFILL(10);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '\f') {
if (yych <= 0x00) goto yy674;
if (yych == '\n') goto yy678;
goto yy676;
} else {
if (yych <= '\r') goto yy680;
if (yych == '\\') goto yy681;
goto yy676;
}
yy674:
++YYCURSOR;
#line 740 "../src/parse/lex.re"
{ fail_if_eof(); ast.chr = 0; return true; }
#line 4522 "src/parse/lex.cc"
yy676:
++YYCURSOR;
yy677:
#line 742 "../src/parse/lex.re"
{ ast.chr = decode(tok); return tok[0] != quote; }
#line 4528 "src/parse/lex.cc"
yy678:
++YYCURSOR;
#line 734 "../src/parse/lex.re"
{ msg.error(ast.loc, "newline in character string"); exit(1); }
#line 4533 "src/parse/lex.cc"
yy680:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy678;
goto yy677;
yy681:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '`') {
if (yych <= '3') {
if (yych <= '\n') {
if (yych <= 0x00) goto yy682;
if (yych <= '\t') goto yy683;
goto yy678;
} else {
if (yych == '\r') goto yy685;
if (yych <= '/') goto yy683;
goto yy686;
}
} else {
if (yych <= 'W') {
if (yych <= '7') goto yy688;
if (yych == 'U') goto yy689;
goto yy683;
} else {
if (yych <= 'X') goto yy691;
if (yych == '\\') goto yy692;
goto yy683;
}
}
} else {
if (yych <= 'q') {
if (yych <= 'e') {
if (yych <= 'a') goto yy694;
if (yych <= 'b') goto yy696;
goto yy683;
} else {
if (yych <= 'f') goto yy698;
if (yych == 'n') goto yy700;
goto yy683;
}
} else {
if (yych <= 'u') {
if (yych <= 'r') goto yy702;
if (yych <= 's') goto yy683;
if (yych <= 't') goto yy704;
goto yy691;
} else {
if (yych <= 'v') goto yy706;
if (yych == 'x') goto yy708;
goto yy683;
}
}
}
yy682:
#line 737 "../src/parse/lex.re"
{ msg.error(ast.loc, "syntax error in escape sequence"); exit(1); }
#line 4589 "src/parse/lex.cc"
yy683:
++YYCURSOR;
yy684:
#line 753 "../src/parse/lex.re"
{
ast.chr = decode(tok + 1);
if (tok[1] != quote) msg.warn.useless_escape(ast.loc, tok, cur);
return true;
}
#line 4599 "src/parse/lex.cc"
yy685:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy678;
goto yy684;
yy686:
yyaccept = 0;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy687;
if (yych <= '7') goto yy709;
yy687:
#line 736 "../src/parse/lex.re"
{ msg.error(ast.loc, "syntax error in octal escape sequence"); exit(1); }
#line 4612 "src/parse/lex.cc"
yy688:
++YYCURSOR;
goto yy687;
yy689:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy690;
if (yych <= '9') goto yy711;
} else {
if (yych <= 'F') goto yy711;
if (yych <= '`') goto yy690;
if (yych <= 'f') goto yy711;
}
yy690:
#line 735 "../src/parse/lex.re"
{ msg.error(ast.loc, "syntax error in hexadecimal escape sequence"); exit(1); }
#line 4630 "src/parse/lex.cc"
yy691:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy690;
if (yych <= '9') goto yy712;
goto yy690;
} else {
if (yych <= 'F') goto yy712;
if (yych <= '`') goto yy690;
if (yych <= 'f') goto yy712;
goto yy690;
}
yy692:
++YYCURSOR;
#line 752 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\\'); return true; }
#line 4648 "src/parse/lex.cc"
yy694:
++YYCURSOR;
#line 745 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\a'); return true; }
#line 4653 "src/parse/lex.cc"
yy696:
++YYCURSOR;
#line 746 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\b'); return true; }
#line 4658 "src/parse/lex.cc"
yy698:
++YYCURSOR;
#line 747 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\f'); return true; }
#line 4663 "src/parse/lex.cc"
yy700:
++YYCURSOR;
#line 748 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\n'); return true; }
#line 4668 "src/parse/lex.cc"
yy702:
++YYCURSOR;
#line 749 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\r'); return true; }
#line 4673 "src/parse/lex.cc"
yy704:
++YYCURSOR;
#line 750 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\t'); return true; }
#line 4678 "src/parse/lex.cc"
yy706:
++YYCURSOR;
#line 751 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\v'); return true; }
#line 4683 "src/parse/lex.cc"
yy708:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy690;
if (yych <= '9') goto yy713;
goto yy690;
} else {
if (yych <= 'F') goto yy713;
if (yych <= '`') goto yy690;
if (yych <= 'f') goto yy713;
goto yy690;
}
yy709:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '/') goto yy710;
if (yych <= '7') goto yy714;
yy710:
YYCURSOR = YYMARKER;
if (yyaccept == 0) {
goto yy687;
} else {
goto yy690;
}
yy711:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy710;
if (yych <= '9') goto yy716;
goto yy710;
} else {
if (yych <= 'F') goto yy716;
if (yych <= '`') goto yy710;
if (yych <= 'f') goto yy716;
goto yy710;
}
yy712:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy710;
if (yych <= '9') goto yy717;
goto yy710;
} else {
if (yych <= 'F') goto yy717;
if (yych <= '`') goto yy710;
if (yych <= 'f') goto yy717;
goto yy710;
}
yy713:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy710;
if (yych <= '9') goto yy718;
goto yy710;
} else {
if (yych <= 'F') goto yy718;
if (yych <= '`') goto yy710;
if (yych <= 'f') goto yy718;
goto yy710;
}
yy714:
++YYCURSOR;
#line 744 "../src/parse/lex.re"
{ ast.chr = unesc_oct(tok, cur); return true; }
#line 4748 "src/parse/lex.cc"
yy716:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy710;
if (yych <= '9') goto yy720;
goto yy710;
} else {
if (yych <= 'F') goto yy720;
if (yych <= '`') goto yy710;
if (yych <= 'f') goto yy720;
goto yy710;
}
yy717:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy710;
if (yych <= '9') goto yy713;
goto yy710;
} else {
if (yych <= 'F') goto yy713;
if (yych <= '`') goto yy710;
if (yych <= 'f') goto yy713;
goto yy710;
}
yy718:
++YYCURSOR;
#line 743 "../src/parse/lex.re"
{ ast.chr = unesc_hex(tok, cur); return true; }
#line 4777 "src/parse/lex.cc"
yy720:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy710;
if (yych >= ':') goto yy710;
} else {
if (yych <= 'F') goto yy721;
if (yych <= '`') goto yy710;
if (yych >= 'g') goto yy710;
}
yy721:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy710;
if (yych <= '9') goto yy712;
goto yy710;
} else {
if (yych <= 'F') goto yy712;
if (yych <= '`') goto yy710;
if (yych <= 'f') goto yy712;
goto yy710;
}
}
#line 760 "../src/parse/lex.re"
}
else {
#line 4806 "src/parse/lex.cc"
{
YYCTYPE yych;
unsigned int yyaccept = 0;
if ((YYLIMIT - YYCURSOR) < 10) YYFILL(10);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x7F) {
if (yych <= '\f') {
if (yych <= 0x00) goto yy724;
if (yych == '\n') goto yy728;
goto yy726;
} else {
if (yych <= '\r') goto yy730;
if (yych == '\\') goto yy731;
goto yy726;
}
} else {
if (yych <= 0xEF) {
if (yych <= 0xC1) goto yy733;
if (yych <= 0xDF) goto yy735;
if (yych <= 0xE0) goto yy736;
goto yy737;
} else {
if (yych <= 0xF0) goto yy738;
if (yych <= 0xF3) goto yy739;
if (yych <= 0xF4) goto yy740;
goto yy733;
}
}
yy724:
++YYCURSOR;
#line 740 "../src/parse/lex.re"
{ fail_if_eof(); ast.chr = 0; return true; }
#line 4839 "src/parse/lex.cc"
yy726:
++YYCURSOR;
yy727:
#line 742 "../src/parse/lex.re"
{ ast.chr = decode(tok); return tok[0] != quote; }
#line 4845 "src/parse/lex.cc"
yy728:
++YYCURSOR;
#line 734 "../src/parse/lex.re"
{ msg.error(ast.loc, "newline in character string"); exit(1); }
#line 4850 "src/parse/lex.cc"
yy730:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy728;
goto yy727;
yy731:
yyaccept = 0;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 'f') {
if (yych <= 'T') {
if (yych <= '\f') {
if (yych <= 0x00) goto yy732;
if (yych == '\n') goto yy728;
goto yy741;
} else {
if (yych <= '/') {
if (yych <= '\r') goto yy743;
goto yy741;
} else {
if (yych <= '3') goto yy744;
if (yych <= '7') goto yy746;
goto yy741;
}
}
} else {
if (yych <= '\\') {
if (yych <= 'W') {
if (yych <= 'U') goto yy747;
goto yy741;
} else {
if (yych <= 'X') goto yy749;
if (yych <= '[') goto yy741;
goto yy750;
}
} else {
if (yych <= 'a') {
if (yych <= '`') goto yy741;
goto yy752;
} else {
if (yych <= 'b') goto yy754;
if (yych <= 'e') goto yy741;
goto yy756;
}
}
}
} else {
if (yych <= 'w') {
if (yych <= 'r') {
if (yych == 'n') goto yy758;
if (yych <= 'q') goto yy741;
goto yy760;
} else {
if (yych <= 't') {
if (yych <= 's') goto yy741;
goto yy762;
} else {
if (yych <= 'u') goto yy749;
if (yych <= 'v') goto yy764;
goto yy741;
}
}
} else {
if (yych <= 0xE0) {
if (yych <= 0x7F) {
if (yych <= 'x') goto yy766;
goto yy741;
} else {
if (yych <= 0xC1) goto yy732;
if (yych <= 0xDF) goto yy767;
goto yy769;
}
} else {
if (yych <= 0xF0) {
if (yych <= 0xEF) goto yy770;
goto yy771;
} else {
if (yych <= 0xF3) goto yy772;
if (yych <= 0xF4) goto yy773;
}
}
}
}
yy732:
#line 737 "../src/parse/lex.re"
{ msg.error(ast.loc, "syntax error in escape sequence"); exit(1); }
#line 4935 "src/parse/lex.cc"
yy733:
++YYCURSOR;
yy734:
#line 738 "../src/parse/lex.re"
{ msg.error(ast.loc, "syntax error"); exit(1); }
#line 4941 "src/parse/lex.cc"
yy735:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy734;
if (yych <= 0xBF) goto yy726;
goto yy734;
yy736:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x9F) goto yy734;
if (yych <= 0xBF) goto yy774;
goto yy734;
yy737:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x7F) goto yy734;
if (yych <= 0xBF) goto yy774;
goto yy734;
yy738:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x8F) goto yy734;
if (yych <= 0xBF) goto yy775;
goto yy734;
yy739:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x7F) goto yy734;
if (yych <= 0xBF) goto yy775;
goto yy734;
yy740:
yyaccept = 1;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x7F) goto yy734;
if (yych <= 0x8F) goto yy775;
goto yy734;
yy741:
++YYCURSOR;
yy742:
#line 753 "../src/parse/lex.re"
{
ast.chr = decode(tok + 1);
if (tok[1] != quote) msg.warn.useless_escape(ast.loc, tok, cur);
return true;
}
#line 4986 "src/parse/lex.cc"
yy743:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy728;
goto yy742;
yy744:
yyaccept = 2;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '/') goto yy745;
if (yych <= '7') goto yy776;
yy745:
#line 736 "../src/parse/lex.re"
{ msg.error(ast.loc, "syntax error in octal escape sequence"); exit(1); }
#line 4999 "src/parse/lex.cc"
yy746:
++YYCURSOR;
goto yy745;
yy747:
yyaccept = 3;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy748;
if (yych <= '9') goto yy777;
} else {
if (yych <= 'F') goto yy777;
if (yych <= '`') goto yy748;
if (yych <= 'f') goto yy777;
}
yy748:
#line 735 "../src/parse/lex.re"
{ msg.error(ast.loc, "syntax error in hexadecimal escape sequence"); exit(1); }
#line 5017 "src/parse/lex.cc"
yy749:
yyaccept = 3;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy748;
if (yych <= '9') goto yy778;
goto yy748;
} else {
if (yych <= 'F') goto yy778;
if (yych <= '`') goto yy748;
if (yych <= 'f') goto yy778;
goto yy748;
}
yy750:
++YYCURSOR;
#line 752 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\\'); return true; }
#line 5035 "src/parse/lex.cc"
yy752:
++YYCURSOR;
#line 745 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\a'); return true; }
#line 5040 "src/parse/lex.cc"
yy754:
++YYCURSOR;
#line 746 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\b'); return true; }
#line 5045 "src/parse/lex.cc"
yy756:
++YYCURSOR;
#line 747 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\f'); return true; }
#line 5050 "src/parse/lex.cc"
yy758:
++YYCURSOR;
#line 748 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\n'); return true; }
#line 5055 "src/parse/lex.cc"
yy760:
++YYCURSOR;
#line 749 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\r'); return true; }
#line 5060 "src/parse/lex.cc"
yy762:
++YYCURSOR;
#line 750 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\t'); return true; }
#line 5065 "src/parse/lex.cc"
yy764:
++YYCURSOR;
#line 751 "../src/parse/lex.re"
{ ast.chr = static_cast<uint8_t>('\v'); return true; }
#line 5070 "src/parse/lex.cc"
yy766:
yyaccept = 3;
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= '@') {
if (yych <= '/') goto yy748;
if (yych <= '9') goto yy779;
goto yy748;
} else {
if (yych <= 'F') goto yy779;
if (yych <= '`') goto yy748;
if (yych <= 'f') goto yy779;
goto yy748;
}
yy767:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy768;
if (yych <= 0xBF) goto yy741;
yy768:
YYCURSOR = YYMARKER;
if (yyaccept <= 1) {
if (yyaccept == 0) {
goto yy732;
} else {
goto yy734;
}
} else {
if (yyaccept == 2) {
goto yy745;
} else {
goto yy748;
}
}
yy769:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x9F) goto yy768;
if (yych <= 0xBF) goto yy767;
goto yy768;
yy770:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy768;
if (yych <= 0xBF) goto yy767;
goto yy768;
yy771:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x8F) goto yy768;
if (yych <= 0xBF) goto yy770;
goto yy768;
yy772:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy768;
if (yych <= 0xBF) goto yy770;
goto yy768;
yy773:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy768;
if (yych <= 0x8F) goto yy770;
goto yy768;
yy774:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy768;
if (yych <= 0xBF) goto yy726;
goto yy768;
yy775:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= 0x7F) goto yy768;
if (yych <= 0xBF) goto yy774;
goto yy768;
yy776:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '/') goto yy768;
if (yych <= '7') goto yy780;
goto yy768;
yy777:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy768;
if (yych <= '9') goto yy782;
goto yy768;
} else {
if (yych <= 'F') goto yy782;
if (yych <= '`') goto yy768;
if (yych <= 'f') goto yy782;
goto yy768;
}
yy778:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy768;
if (yych <= '9') goto yy783;
goto yy768;
} else {
if (yych <= 'F') goto yy783;
if (yych <= '`') goto yy768;
if (yych <= 'f') goto yy783;
goto yy768;
}
yy779:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy768;
if (yych <= '9') goto yy784;
goto yy768;
} else {
if (yych <= 'F') goto yy784;
if (yych <= '`') goto yy768;
if (yych <= 'f') goto yy784;
goto yy768;
}
yy780:
++YYCURSOR;
#line 744 "../src/parse/lex.re"
{ ast.chr = unesc_oct(tok, cur); return true; }
#line 5183 "src/parse/lex.cc"
yy782:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy768;
if (yych <= '9') goto yy786;
goto yy768;
} else {
if (yych <= 'F') goto yy786;
if (yych <= '`') goto yy768;
if (yych <= 'f') goto yy786;
goto yy768;
}
yy783:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy768;
if (yych <= '9') goto yy779;
goto yy768;
} else {
if (yych <= 'F') goto yy779;
if (yych <= '`') goto yy768;
if (yych <= 'f') goto yy779;
goto yy768;
}
yy784:
++YYCURSOR;
#line 743 "../src/parse/lex.re"
{ ast.chr = unesc_hex(tok, cur); return true; }
#line 5212 "src/parse/lex.cc"
yy786:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy768;
if (yych >= ':') goto yy768;
} else {
if (yych <= 'F') goto yy787;
if (yych <= '`') goto yy768;
if (yych >= 'g') goto yy768;
}
yy787:
yych = (YYCTYPE)*++YYCURSOR;
if (yych <= '@') {
if (yych <= '/') goto yy768;
if (yych <= '9') goto yy778;
goto yy768;
} else {
if (yych <= 'F') goto yy778;
if (yych <= '`') goto yy768;
if (yych <= 'f') goto yy778;
goto yy768;
}
}
#line 763 "../src/parse/lex.re"
#line 763 "../src/parse/lex.re"
}
}
const AST *Scanner::lex_str(char quote)
{
const loc_t &loc = tok_loc();
std::vector<ASTChar> *str = new std::vector<ASTChar>;
ASTChar c;
for (;;) {
if (!lex_str_chr(quote, c)) {
return ast_str(loc, str, quote == '\'');
}
str->push_back(c);
}
}
void Scanner::set_sourceline ()
{
sourceline:
tok = cur;
#line 5260 "src/parse/lex.cc"
{
YYCTYPE yych;
static const unsigned char yybm[] = {
0, 128, 128, 128, 128, 128, 128, 128,
128, 128, 0, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 0, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
192, 192, 192, 192, 192, 192, 192, 192,
192, 192, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 0, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128,
};
if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= '\r') {
if (yych <= '\t') {
if (yych >= 0x01) goto yy792;
} else {
if (yych <= '\n') goto yy794;
if (yych <= '\f') goto yy792;
goto yy796;
}
} else {
if (yych <= '"') {
if (yych <= '!') goto yy792;
goto yy797;
} else {
if (yych <= '0') goto yy792;
if (yych <= '9') goto yy798;
goto yy792;
}
}
++YYCURSOR;
#line 806 "../src/parse/lex.re"
{ --cur; return; }
#line 5320 "src/parse/lex.cc"
yy792:
++YYCURSOR;
yy793:
#line 807 "../src/parse/lex.re"
{ goto sourceline; }
#line 5326 "src/parse/lex.cc"
yy794:
++YYCURSOR;
#line 805 "../src/parse/lex.re"
{ pos = tok = cur; return; }
#line 5331 "src/parse/lex.cc"
yy796:
yych = (YYCTYPE)*++YYCURSOR;
if (yych == '\n') goto yy794;
goto yy793;
yy797:
yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR);
if (yych <= 0x00) goto yy793;
if (yych == '\n') goto yy793;
goto yy802;
yy798:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yybm[0+yych] & 64) {
goto yy798;
}
#line 785 "../src/parse/lex.re"
{
uint32_t l;
if (!s_to_u32_unsafe(tok, cur, l)) {
msg.error(tok_loc(), "line number overflow");
exit(1);
}
set_line(l);
goto sourceline;
}
#line 5358 "src/parse/lex.cc"
yy801:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
yy802:
if (yybm[0+yych] & 128) {
goto yy801;
}
if (yych <= '\n') goto yy803;
if (yych <= '"') goto yy804;
goto yy806;
yy803:
YYCURSOR = YYMARKER;
goto yy793;
yy804:
++YYCURSOR;
#line 795 "../src/parse/lex.re"
{
Input &in = get_input();
std::string &name = in.escaped_name;
name = getstr(tok + 1, cur - 1);
strrreplace(name, "\\", "\\\\");
in.fidx = static_cast<uint32_t>(msg.filenames.size());
msg.filenames.push_back(name);
goto sourceline;
}
#line 5385 "src/parse/lex.cc"
yy806:
++YYCURSOR;
if (YYLIMIT <= YYCURSOR) YYFILL(1);
yych = (YYCTYPE)*YYCURSOR;
if (yych <= 0x00) goto yy803;
if (yych == '\n') goto yy803;
goto yy801;
}
#line 808 "../src/parse/lex.re"
}
void Scanner::fail_if_eof() const
{
if (is_eof()) {
msg.error(cur_loc(), "unexpected end of input");
exit(1);
}
}
#undef YYCTYPE
#undef YYCURSOR
#undef YYLIMIT
#undef YYMARKER
#undef YYFILL
} // end namespace re2c
| 22.062269 | 93 | 0.533706 | [
"vector"
] |
82a3aa63f0afa3c8c5971d66ac548e4f2be0bc3a | 1,438 | cpp | C++ | 0188-best-time-to-buy-and-sell-stock-iv.cpp | Jamesweng/leetcode | 1711a2a0e31d831e40137203c9abcba0bf56fcad | [
"Apache-2.0"
] | 106 | 2019-06-08T15:23:45.000Z | 2020-04-04T17:56:54.000Z | 0188-best-time-to-buy-and-sell-stock-iv.cpp | Jamesweng/leetcode | 1711a2a0e31d831e40137203c9abcba0bf56fcad | [
"Apache-2.0"
] | null | null | null | 0188-best-time-to-buy-and-sell-stock-iv.cpp | Jamesweng/leetcode | 1711a2a0e31d831e40137203c9abcba0bf56fcad | [
"Apache-2.0"
] | 3 | 2019-07-13T05:51:29.000Z | 2020-04-04T17:56:57.000Z | class Solution {
public:
int maxProfit(int k, vector<int>& prices) {
int n = prices.size();
if (n <= 1 || k <= 0) return 0;
if (k > n / 2) k = n / 2;
int f[2][n], ans = 0;
//printf("n=%d\n", n);
// 前i个,k次交易最多的profit
// f[k][i] = max(f[k - 1][j] + max{j..i})
for (int kv = 0; kv <= k; ++kv) {
int maxDiff = INT_MIN;
for (int i = 0; i < n; ++i) {
int x = kv % 2;
if (kv == 0) f[x][i] = 0;
else {
f[x][i] = 0;
if (i == 0) continue;
maxDiff = max(maxDiff, f[1 - x][i - 1] - prices[i - 1]);
f[x][i] = max(f[x][i - 1], maxDiff + prices[i]);
// int maxPrice = prices[i], maxProfit = 0;
// for (int j = i - 1; j >= 0; --j) {
// maxProfit = max(maxProfit, maxPrice - prices[j]);
// maxPrice = max(maxPrice, prices[j]);
// f[x][i] = max(f[x][i], j > 0 ?
// f[1 - x][j - 1] + maxProfit :
// maxProfit);
// }
}
ans = max(ans, f[x][i]);
}
}
return ans;
}
};
| 32.681818 | 76 | 0.295549 | [
"vector"
] |
82a89553f499c190d88ccd6884d23082c0399049 | 17,012 | cpp | C++ | src/demos/synchrono/demo_SCM/demo_SYN_scm_tracked.cpp | zzhou292/chrono-collision | c2a20e171bb0eb8819636d370887aa32d68547c6 | [
"BSD-3-Clause"
] | 1 | 2020-01-18T02:39:17.000Z | 2020-01-18T02:39:17.000Z | src/demos/synchrono/demo_SCM/demo_SYN_scm_tracked.cpp | zzhou292/chrono-collision | c2a20e171bb0eb8819636d370887aa32d68547c6 | [
"BSD-3-Clause"
] | null | null | null | src/demos/synchrono/demo_SCM/demo_SYN_scm_tracked.cpp | zzhou292/chrono-collision | c2a20e171bb0eb8819636d370887aa32d68547c6 | [
"BSD-3-Clause"
] | 1 | 2019-07-16T00:23:00.000Z | 2019-07-16T00:23:00.000Z | // =============================================================================
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2020 projectchrono.org
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file at the top level of the distribution and at
// http://projectchrono.org/license-chrono.txt.
//
// =============================================================================
// Authors: Jay Taves, Aaron Young
// =============================================================================
//
// Demo code illustrating synchronization of the SCM semi-empirical model for
// deformable soil
//
// See also in chrono_vehicle:
// - demo_VEH_DeformableSoil
// - demo_VEH_DeformableSoilAndTire
// - demo_VEH_HMMWV_DefSoil
//
// =============================================================================
#include <chrono>
#include "chrono_vehicle/driver/ChPathFollowerDriver.h"
#include "chrono_synchrono/communication/mpi/SynMPIManager.h"
#include "chrono_thirdparty/cxxopts/ChCLI.h"
#include "chrono_synchrono/agent/SynTrackedVehicleAgent.h"
#include "chrono_synchrono/vehicle/SynTrackedVehicle.h"
#include "chrono_synchrono/terrain/SynSCMTerrain.h"
#include "chrono_synchrono/terrain/SynRigidTerrain.h"
#include "chrono_synchrono/visualization/SynVisualizationManager.h"
#ifdef CHRONO_IRRLICHT
#include "chrono_synchrono/visualization/SynIrrVehicleVisualization.h"
#endif
#ifdef CHRONO_SENSOR
#include "chrono_sensor/ChCameraSensor.h"
#include "chrono_sensor/filters/ChFilterAccess.h"
#include "chrono_sensor/filters/ChFilterSave.h"
#include "chrono_sensor/filters/ChFilterVisualize.h"
#include "chrono_synchrono/visualization/SynSensorVisualization.h"
using namespace chrono::sensor;
#endif
#include "chrono_models/vehicle/m113/M113.h"
using namespace chrono;
using namespace chrono::synchrono;
using namespace chrono::vehicle;
using namespace chrono::vehicle::m113;
// =============================================================================
// Better conserve mass by displacing soil to the sides of a rut
bool bulldozing = true;
ChContactMethod contact_method = ChContactMethod::SMC;
double end_time = 1000;
double step_size = 1e-3;
// Time interval between two render frames
double render_step_size = 1.0 / 50; // FPS = 50
int render_rank = 0;
// SynChrono synchronization heartbeat
float heartbeat = 1e-2; // 100[Hz]
ChContactMethod ContactMethodFromString(std::string str);
std::string StringFromContactMethod(ChContactMethod contact);
void AddCommandLineOptions(ChCLI& cli);
// =============================================================================
int main(int argc, char* argv[]) {
SynMPIConfig config = MPI_CONFIG_DEFAULT;
// Need dynamic reserve as we don't know how many nodes the vehicles will hit
config.memory_mode = SynMPIMemoryMode::DYNAMIC_RESERVE;
SynMPIManager mpi_manager(argc, argv, config);
int rank = mpi_manager.GetRank();
int num_ranks = mpi_manager.GetNumRanks();
// -----------------------------------------------------
// CLI SETUP - Get most parameters from the command line
// -----------------------------------------------------
ChCLI cli(argv[0]);
AddCommandLineOptions(cli);
if (!cli.Parse(argc, argv, rank == 0))
mpi_manager.Exit();
// Normal simulation options
step_size = cli.GetAsType<double>("step_size");
end_time = cli.GetAsType<double>("end_time");
heartbeat = cli.GetAsType<double>("heartbeat");
contact_method = ContactMethodFromString(cli.GetAsType<std::string>("contact_method"));
const double size_x = cli.GetAsType<double>("sizeX");
const double size_y = cli.GetAsType<double>("sizeY");
const double cam_x = cli.GetAsType<std::vector<double>>("c_pos")[0];
const double cam_y = cli.GetAsType<std::vector<double>>("c_pos")[1];
const double dpu = cli.GetAsType<double>("dpu");
const int cam_res_width = cli.GetAsType<std::vector<int>>("res")[0];
const int cam_res_height = cli.GetAsType<std::vector<int>>("res")[1];
const bool using_scm_terrain = cli.GetAsType<std::string>("terrain_type") == "SCM";
const bool use_sensor_vis = cli.HasValueInVector<int>("sens", rank);
const bool use_irrlicht_vis = !use_sensor_vis && cli.HasValueInVector<int>("irr", rank);
mpi_manager.SetHeartbeat(heartbeat);
mpi_manager.SetEndTime(end_time);
// --------------------
// Agent Initialization
// --------------------
auto agent = chrono_types::make_shared<SynTrackedVehicleAgent>(rank);
mpi_manager.AddAgent(agent, rank);
// Use up more of the mesh by not placing vehicles in the middle
ChVector<> offset(-size_x / 2 + 5, 0, 0);
ChVector<> init_loc;
ChQuaternion<> init_rot;
std::vector<ChVector<>> curve_pts;
if (rank % 2 == 0) {
// Start even vehicles in a row on the south side, driving north
init_loc = offset + ChVector<>(0, 2.0 * (rank + 1), 0.75);
init_rot = Q_from_AngZ(0);
curve_pts = {init_loc, init_loc + ChVector<>(100, 0, 0)};
} else {
// Start odd vehicles staggered going up the west edge, driving east
init_loc = offset + ChVector<>(2.0 * (rank - 1), -5.0 - 2.0 * (rank - 1), 0.75);
init_rot = Q_from_AngZ(CH_C_PI / 2);
curve_pts = {init_loc, init_loc + ChVector<>(0, 100, 0)};
}
// -------------------------
// Chrono::Vehicle specifics
// -------------------------
auto m113 = chrono_types::make_shared<M113>();
m113->SetContactMethod(contact_method);
m113->SetChassisCollisionType(CollisionType::NONE);
m113->SetChassisFixed(false);
m113->SetInitPosition(ChCoordsys<>(init_loc, init_rot));
m113->SetTrackShoeType(TrackShoeType::SINGLE_PIN);
m113->SetBrakeType(BrakeType::SIMPLE);
m113->Initialize();
m113->SetChassisVisualizationType(VisualizationType::MESH);
m113->SetSprocketVisualizationType(VisualizationType::MESH);
m113->SetIdlerVisualizationType(VisualizationType::MESH);
m113->SetRoadWheelAssemblyVisualizationType(VisualizationType::NONE);
m113->SetRoadWheelVisualizationType(VisualizationType::MESH);
m113->SetTrackShoeVisualizationType(VisualizationType::MESH);
auto vehicle = chrono_types::make_shared<SynCustomTrackedVehicle<M113>>(m113);
agent->SetVehicle(vehicle);
// Set the zombie visualization assets of the vehicle
// This is done only with custom vehicles because this information is required in the JSON format
vehicle->SetZombieVisualizationFiles("M113/Chassis.obj", //
"M113/TrackShoe.obj", //
"M113/Sprocket_L.obj", //
"M113/Sprocket_R.obj", //
"M113/Idler_L.obj", //
"M113/Idler_R.obj", //
"M113/Roller_L.obj", //
"M113/Roller_R.obj"); //
vehicle->SetNumAssemblyComponents(127, 2, 2, 10);
// ----------------------
// Terrain specific setup
// ----------------------
if (using_scm_terrain) {
auto scm = chrono_types::make_shared<SCMDeformableTerrain>(agent->GetSystem());
// Configure the SCM terrain
if (bulldozing) {
scm->EnableBulldozing(bulldozing);
scm->SetBulldozingParameters(
55, // angle of friction for erosion of displaced material at the border of the rut
1, // displaced material vs downward pressed material.
5, // number of erosion refinements per timestep
10); // number of concentric vertex selections subject to erosion
}
// Only relevant for Irrlicht visualization, gives some nice colors
scm->SetPlotType(SCMDeformableTerrain::PLOT_SINKAGE, 0, 0.1);
scm->GetMesh()->SetWireframe(true);
// The physics do not change when you add a moving patch, you just make it much easier for the SCM
// implementation to do its job by restricting where it has to look for contacts
// We need a larger contact patch here than for the humvee
scm->AddMovingPatch(vehicle->GetVehicle().GetChassisBody(), ChVector<>(0, 0, 0), ChVector<>(10, 10, 1));
scm->Initialize(size_x, size_y, 1. / dpu);
// Wrap the ChTerrain in a SynChrono object
auto terrain = chrono_types::make_shared<SynSCMTerrain>(scm, agent->GetSystem());
agent->SetTerrain(terrain);
// Choice of soft parameters is arbitrary
SCMParameters params;
params.InitializeParametersAsSoft();
terrain->SetSoilParametersFromStruct(¶ms);
// Add texture for the terrain
auto vis_mat = chrono_types::make_shared<ChVisualMaterial>();
vis_mat->SetSpecularColor({.1f, .1f, .1f});
vis_mat->SetKdTexture(GetChronoDataFile("sensor/textures/grass_texture.jpg"));
scm->GetMesh()->material_list.push_back(vis_mat);
} else {
// Rigid Terrain setup here
MaterialInfo minfo;
minfo.mu = 0.9f;
minfo.cr = 0.01f;
minfo.Y = 2e7f;
auto patch_mat = minfo.CreateMaterial(contact_method);
auto rigid = chrono_types::make_shared<RigidTerrain>(agent->GetSystem());
auto patch = rigid->AddPatch(patch_mat, ChVector<>(0, 0, 0), ChVector<>(0, 0, 1), size_x, size_y);
rigid->Initialize();
// Terrain visualization
// For irrlicht
patch->SetTexture(vehicle::GetDataFile("terrain/textures/tile4.jpg"), 200, 200);
// For sensor
auto patch_asset = patch->GetGroundBody()->GetAssets()[0];
if (auto visual_asset = std::dynamic_pointer_cast<ChVisualization>(patch_asset)) {
auto box_texture = chrono_types::make_shared<ChVisualMaterial>();
box_texture->SetKdTexture(vehicle::GetDataFile("terrain/textures/tile4.jpg"));
// FresnelMax and SpecularColor should make it less shiny
box_texture->SetFresnelMax(0.2);
box_texture->SetSpecularColor({0.2, 0.2, 0.2});
visual_asset->material_list.push_back(box_texture);
}
agent->SetTerrain(chrono_types::make_shared<SynRigidTerrain>(rigid));
}
// ---------------------------
// Controller for the vehicles
// ---------------------------
// What we defined earlier, a straight line
auto path = chrono_types::make_shared<ChBezierCurve>(curve_pts);
auto driver = chrono_types::make_shared<ChPathFollowerDriver>(vehicle->GetVehicle(), path, "Box path", 10);
// Reasonable defaults for the underlying PID
driver->GetSpeedController().SetGains(0.4, 0, 0);
driver->GetSteeringController().SetGains(0.4, 0.1, 0.2);
driver->GetSteeringController().SetLookAheadDistance(5);
// Wrap the ChDriver in a SynVehicleBrain and add it to our agent
auto brain = chrono_types::make_shared<SynVehicleBrain>(rank, driver, agent->GetChVehicle());
agent->SetBrain(brain);
// ---------------------------
// Visualization
// ---------------------------
// Visualization manager is a convenient way to bring Sensor and Irrlicht under one roof
auto vis_manager = chrono_types::make_shared<SynVisualizationManager>();
agent->SetVisualizationManager(vis_manager);
#ifdef CHRONO_IRRLICHT
if (use_irrlicht_vis) {
auto irr_vis = chrono_types::make_shared<SynIrrVehicleVisualization>(driver, step_size, render_step_size);
irr_vis->InitializeAsDefaultTrackedChaseCamera(agent->GetTrackedVehicle(), 10);
vis_manager->AddVisualization(irr_vis);
}
#endif
#ifdef CHRONO_SENSOR
if (use_sensor_vis) {
auto sen_vis = chrono_types::make_shared<SynSensorVisualization>();
sen_vis->InitializeDefaultSensorManager(agent->GetSystem());
// Give the camera a fixed place to live
auto origin = chrono_types::make_shared<ChBody>();
origin->SetBodyFixed(true);
agent->GetSystem()->AddBody(origin);
// Happens to be a reasonable-looking height
ChVector<> camera_loc(cam_x, cam_y, 25);
// Rotations to get a nice angle
ChQuaternion<> rotation = QUNIT;
const bool USE_ISO_VIEW = true;
if (USE_ISO_VIEW) {
ChQuaternion<> qA = Q_from_AngAxis(35 * CH_C_DEG_TO_RAD, VECT_Y);
ChQuaternion<> qB = Q_from_AngAxis(135 * CH_C_DEG_TO_RAD, VECT_Z);
rotation = rotation >> qA >> qB;
} else {
// Top down view
ChQuaternion<> qA = Q_from_AngAxis(90 * CH_C_DEG_TO_RAD, VECT_Y);
ChQuaternion<> qB = Q_from_AngAxis(180 * CH_C_DEG_TO_RAD, VECT_Z);
rotation = rotation >> qA >> qB;
}
auto overhead_camera = chrono_types::make_shared<chrono::sensor::ChCameraSensor>(
origin, // body camera is attached to
30, // update rate in Hz
chrono::ChFrame<double>(camera_loc, rotation), // offset pose
cam_res_width, // image width
cam_res_height, // image height
CH_C_PI / 3);
overhead_camera->SetName("Overhead Cam");
overhead_camera->PushFilter(chrono_types::make_shared<ChFilterRGBA8Access>());
// Do we draw a window on the screen?
if (cli.GetAsType<bool>("sens_vis"))
overhead_camera->PushFilter(chrono_types::make_shared<ChFilterVisualize>(cam_res_width, cam_res_height));
// Do we save images to disc?
std::string file_path = std::string("SENSOR_OUTPUT/scm_tracked") + std::to_string(rank) + std::string("/");
if (cli.GetAsType<bool>("sens_save"))
overhead_camera->PushFilter(chrono_types::make_shared<ChFilterSave>(file_path));
sen_vis->SetSensor(overhead_camera);
vis_manager->AddVisualization(sen_vis);
}
#endif
mpi_manager.Barrier();
mpi_manager.Initialize();
std::cout << "Rank " << rank << " entering simulation loop." << std::endl;
int step_number = 0;
// Simulation Loop
while (mpi_manager.IsOk()) {
mpi_manager.Advance(heartbeat * step_number++);
mpi_manager.Synchronize();
mpi_manager.Update();
}
std::cout << "Rank " << rank << " completed successfully." << std::endl;
return 0;
}
ChContactMethod ContactMethodFromString(std::string str) {
if (str == "SMC")
return ChContactMethod::SMC;
if (str == "NSC")
return ChContactMethod::NSC;
throw ChException(str + " is not a valid ChContactMethod (SMC or NSC)");
}
std::string StringFromContactMethod(ChContactMethod contact) {
switch (contact) {
case ChContactMethod::NSC:
return "NSC";
case ChContactMethod::SMC:
return "SMC";
default:
throw ChException("ChContactMethod improperly enumerated in StringFromContactMethod");
}
}
void AddCommandLineOptions(ChCLI& cli) {
// Standard demo options
cli.AddOption<double>("Simulation", "step_size", "Step size", std::to_string(step_size));
cli.AddOption<double>("Simulation", "end_time", "End time", std::to_string(end_time));
cli.AddOption<double>("Simulation", "heartbeat", "Heartbeat", std::to_string(heartbeat));
cli.AddOption<std::string>("Simulation", "contact_method", "Contact Method",
StringFromContactMethod(contact_method), "NSC/SMC");
// SCM specific options
cli.AddOption<double>("Demo", "d,dpu", "Divisions per unit", "20");
cli.AddOption<std::string>("Demo", "t,terrain_type", "Terrain Type", "Rigid", "Rigid,SCM");
// Visualization is the only reason you should be shy about terrain size. The implementation can easily handle a
// practically infinite terrain (provided you don't need to visualize it)
cli.AddOption<double>("Demo", "x,sizeX", "Size in the X", "100");
cli.AddOption<double>("Demo", "y,sizeY", "Size in the Y", "50");
// Irrlicht options
cli.AddOption<std::vector<int>>("Irrlicht", "irr", "Ranks for irrlicht usage", "-1");
cli.AddOption<bool>("Irrlicht", "irr_save", "Toggle irrlicht saving ON", "false");
cli.AddOption<bool>("Irrlicht", "irr_vis", "Toggle irrlicht visualization ON", "false");
// Sensor options
cli.AddOption<std::vector<int>>("Sensor", "sens", "Ranks for sensor usage", "-1");
cli.AddOption<bool>("Sensor", "sens_save", "Toggle sensor saving ON", "false");
cli.AddOption<bool>("Sensor", "sens_vis", "Toggle sensor visualization ON", "false");
cli.AddOption<std::vector<int>>("Demo", "r,res", "Camera resolution", "1280,720", "width,height");
cli.AddOption<std::vector<double>>("Demo", "c_pos", "Camera Position", "-15,-25", "X,Y");
} | 41.798526 | 117 | 0.627322 | [
"mesh",
"render",
"object",
"vector",
"model"
] |
82acba6eb7c5a4597465d6211b7c980e63fe87c0 | 53,887 | cpp | C++ | test/1.3/QLstm.cpp | ARM-software/android-nn-driver | 249c1253c6019a380ee2e283b7d3f412d5ecbfd1 | [
"MIT"
] | 130 | 2018-03-09T20:44:20.000Z | 2022-03-06T16:34:51.000Z | test/1.3/QLstm.cpp | ARM-software/android-nn-driver | 249c1253c6019a380ee2e283b7d3f412d5ecbfd1 | [
"MIT"
] | 18 | 2018-05-02T09:43:59.000Z | 2021-11-08T10:41:55.000Z | test/1.3/QLstm.cpp | ARM-software/android-nn-driver | 249c1253c6019a380ee2e283b7d3f412d5ecbfd1 | [
"MIT"
] | 53 | 2018-03-12T18:25:48.000Z | 2022-02-01T13:52:52.000Z | //
// Copyright © 2020 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#include "../DriverTestHelpers.hpp"
#include "../TestTensor.hpp"
#include "../1.3/HalPolicy.hpp"
#include <armnn/utility/IgnoreUnused.hpp>
#include <doctest/doctest.h>
#include <array>
using ArmnnDriver = armnn_driver::ArmnnDriver;
using DriverOptions = armnn_driver::DriverOptions;
using namespace driverTestHelpers;
using namespace android::hardware;
using HalPolicy = hal_1_3::HalPolicy;
static const float TOLERANCE = 1.0f;
namespace
{
template<typename T>
RequestArgument CreateRequestArgument(const std::vector<T>& value, unsigned int poolIndex)
{
V1_0::DataLocation inputInloc = {};
inputInloc.poolIndex = poolIndex;
inputInloc.offset = 0;
inputInloc.length = value.size() * sizeof(T);
RequestArgument inputRequestArgument = {};
inputRequestArgument.location = inputInloc;
inputRequestArgument.dimensions = hidl_vec<uint32_t>{};
return inputRequestArgument;
}
// Helper function to create an OperandLifeTime::NO_VALUE for testing.
// To be used on optional input operands that have no values - these are valid and should be tested.
HalPolicy::OperandLifeTime CreateNoValueLifeTime(const hidl_vec<uint32_t>& dimensions)
{
// Only create a NO_VALUE for optional operands that have no elements
if (dimensions.size() == 0 || dimensions[0] == 0)
{
return HalPolicy::OperandLifeTime::NO_VALUE;
}
return HalPolicy::OperandLifeTime::CONSTANT_COPY;
}
void ExecuteModel(const armnn_driver::hal_1_3::HalPolicy::Model& model,
armnn_driver::ArmnnDriver& driver,
const V1_0::Request& request)
{
android::sp<V1_3::IPreparedModel> preparedModel = PrepareModel_1_3(model, driver);
if (preparedModel.get() != nullptr)
{
Execute(preparedModel, request);
}
}
// Add our own tests here since we skip the qlstm tests which Google supplies (because of non-const weights)
void QLstmTestImpl(const hidl_vec<uint32_t>& inputDimensions,
const std::vector<int8_t>& inputValue,
const hidl_vec<uint32_t>& inputToInputWeightsDimensions,
const std::vector<int8_t>& inputToInputWeightsValue,
const hidl_vec<uint32_t>& inputToForgetWeightsDimensions,
const std::vector<int8_t>& inputToForgetWeightsValue,
const hidl_vec<uint32_t>& inputToCellWeightsDimensions,
const std::vector<int8_t>& inputToCellWeightsValue,
const hidl_vec<uint32_t>& inputToOutputWeightsDimensions,
const std::vector<int8_t>& inputToOutputWeightsValue,
const hidl_vec<uint32_t>& recurrentToInputWeightsDimensions,
const std::vector<int8_t>& recurrentToInputWeightsValue,
const hidl_vec<uint32_t>& recurrentToForgetWeightsDimensions,
const std::vector<int8_t>& recurrentToForgetWeightsValue,
const hidl_vec<uint32_t>& recurrentToCellWeightsDimensions,
const std::vector<int8_t>& recurrentToCellWeightsValue,
const hidl_vec<uint32_t>& recurrentToOutputWeightsDimensions,
const std::vector<int8_t>& recurrentToOutputWeightsValue,
const hidl_vec<uint32_t>& cellToInputWeightsDimensions,
const std::vector<int16_t>& cellToInputWeightsValue,
const hidl_vec<uint32_t>& cellToForgetWeightsDimensions,
const std::vector<int16_t>& cellToForgetWeightsValue,
const hidl_vec<uint32_t>& cellToOutputWeightsDimensions,
const std::vector<int16_t>& cellToOutputWeightsValue,
const hidl_vec<uint32_t>& inputGateBiasDimensions,
const std::vector<int32_t>& inputGateBiasValue,
const hidl_vec<uint32_t>& forgetGateBiasDimensions,
const std::vector<int32_t>& forgetGateBiasValue,
const hidl_vec<uint32_t>& cellBiasDimensions,
const std::vector<int32_t>& cellBiasValue,
const hidl_vec<uint32_t>& outputGateBiasDimensions,
const std::vector<int32_t>& outputGateBiasValue,
const hidl_vec<uint32_t>& projectionWeightsDimensions,
const std::vector<int8_t>& projectionWeightsValue,
const hidl_vec<uint32_t>& projectionBiasDimensions,
const std::vector<int32_t>& projectionBiasValue,
const hidl_vec<uint32_t>& outputPreviousTimeStepInDimensions,
const std::vector<int8_t>& outputPreviousTimeStepInValue,
const hidl_vec<uint32_t>& cellStatePreviousTimeStepInDimensions,
const std::vector<int16_t>& cellStatePreviousTimeStepInValue,
const hidl_vec<uint32_t>& inputLayerNormWeightsDimensions,
const std::vector<int16_t>& inputLayerNormWeightsValue,
const hidl_vec<uint32_t>& forgetLayerNormWeightsDimensions,
const std::vector<int16_t>& forgetLayerNormWeightsValue,
const hidl_vec<uint32_t>& cellLayerNormWeightsDimensions,
const std::vector<int16_t>& cellLayerNormWeightsValue,
const hidl_vec<uint32_t>& outputLayerNormWeightsDimensions,
const std::vector<int16_t>& outputLayerNormWeightsValue,
const float& cellClipValue,
const float& projectionClipValue,
const float& matMulInputGateValue,
const float& matMulForgetGateValue,
const float& matMulCellGateValue,
const float& matMulOutputGateValue,
const int32_t& projInputZeroPointValue,
const float& projInputScaleValue,
const hidl_vec<uint32_t>& outputStateOutDimensions,
const std::vector<int8_t>& outputStateOutValue,
const hidl_vec<uint32_t>& cellStateOutDimensions,
const std::vector<int16_t>& cellStateOutValue,
const hidl_vec<uint32_t>& outputDimensions,
const std::vector<int8_t>& outputValue,
armnn::Compute compute)
{
auto driver = std::make_unique<ArmnnDriver>(DriverOptions(compute));
HalPolicy::Model model = {};
// Scale/Offset quantization info
float inputScale = 0.0078125f;
int32_t inputOffset = 0;
int32_t hiddenStateZeroPoint = 0;
float hiddenStateScale = 0.007f;
float outputScale = hiddenStateScale;
int32_t outputOffset = hiddenStateZeroPoint;
float cellStateScale = 3.05176e-05f;
float cellWeightsScale = 1.0f;
int32_t cellStateOffset = 0;
float weightsScale = 0.00784314f;
int32_t weightsOffset = 0;
float layerNormScale = 3.05182e-05f;
int32_t layerNormOffset = 0;
float biasScale = layerNormScale / 1024;
int32_t biasOffset = 0;
// Inputs:
// 00: The input to the LSTM cell. Type: ANEURALNETWORKS_TENSOR_QUANT8_ASYMM_SIGNED Shape: [batchSize, inputSize]
AddInputOperand<HalPolicy>(model,
inputDimensions,
HalPolicy::OperandType::TENSOR_QUANT8_ASYMM_SIGNED,
inputScale,
inputOffset);
// 01: The input-to-input weights. Optional. Type: ANEURALNETWORKS_TENSOR_QUANT8_SYMM Shape: [numUnits, inputSize]
AddTensorOperand<HalPolicy>(model,
inputToInputWeightsDimensions,
inputToInputWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT8_SYMM,
CreateNoValueLifeTime(inputToInputWeightsDimensions),
weightsScale,
weightsOffset);
// 02: The input-to-forget weights. Type: ANEURALNETWORKS_TENSOR_QUANT8_SYMM Shape: [numUnits, inputSize]
AddTensorOperand<HalPolicy>(model,
inputToForgetWeightsDimensions,
inputToForgetWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT8_SYMM,
CreateNoValueLifeTime(inputToForgetWeightsDimensions),
weightsScale,
weightsOffset);
// 03: The input-to-cell weights. Type: ANEURALNETWORKS_TENSOR_QUANT8_SYMM Shape: [numUnits, inputSize]
AddTensorOperand<HalPolicy>(model,
inputToCellWeightsDimensions,
inputToCellWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT8_SYMM,
CreateNoValueLifeTime(inputToCellWeightsDimensions),
weightsScale,
weightsOffset);
// 04: The input-to-output weights. Type: ANEURALNETWORKS_TENSOR_QUANT8_SYMM Shape: [numUnits, inputSize]
AddTensorOperand<HalPolicy>(model,
inputToOutputWeightsDimensions,
inputToOutputWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT8_SYMM,
CreateNoValueLifeTime(inputToOutputWeightsDimensions),
weightsScale,
weightsOffset);
// 05: The recurrent-to-input weights. Optional. Type: ANEURALNETWORKS_TENSOR_QUANT8_SYMM
// Shape: [numUnits, outputSize]
AddTensorOperand<HalPolicy>(model,
recurrentToInputWeightsDimensions,
recurrentToInputWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT8_SYMM,
CreateNoValueLifeTime(recurrentToInputWeightsDimensions),
weightsScale,
weightsOffset);
// 06: The recurrent-to-forget weights. Type: ANEURALNETWORKS_TENSOR_QUANT8_SYMM Shape: [numUnits, outputSize]
AddTensorOperand<HalPolicy>(model,
recurrentToForgetWeightsDimensions,
recurrentToForgetWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT8_SYMM,
CreateNoValueLifeTime(recurrentToForgetWeightsDimensions),
weightsScale,
weightsOffset);
// 07: The recurrent-to-cell weights. Type: ANEURALNETWORKS_TENSOR_QUANT8_SYMM Shape: [numUnits, outputSize]
AddTensorOperand<HalPolicy>(model,
recurrentToCellWeightsDimensions,
recurrentToCellWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT8_SYMM,
CreateNoValueLifeTime(recurrentToCellWeightsDimensions),
weightsScale,
weightsOffset);
// 08: The recurrent-to-output weights. Type: ANEURALNETWORKS_TENSOR_QUANT8_SYMM Shape: [numUnits, outputSize]
AddTensorOperand<HalPolicy>(model,
recurrentToOutputWeightsDimensions,
recurrentToOutputWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT8_SYMM,
CreateNoValueLifeTime(recurrentToOutputWeightsDimensions),
weightsScale,
weightsOffset);
// 09: The cell-to-input weights (for peephole). Optional. Type: ANEURALNETWORKS_TENSOR_QUANT16_SYMM
// Shape: [numUnits]
AddTensorOperand<HalPolicy>(model,
cellToInputWeightsDimensions,
cellToInputWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT16_SYMM ,
CreateNoValueLifeTime(cellToInputWeightsDimensions),
cellWeightsScale,
weightsOffset);
// 10: The cell-to-forget weights (for peephole). Optional. Type: ANEURALNETWORKS_TENSOR_QUANT16_SYMM
// Shape: [numUnits].
AddTensorOperand<HalPolicy>(model,
cellToForgetWeightsDimensions,
cellToForgetWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT16_SYMM,
CreateNoValueLifeTime(cellToForgetWeightsDimensions),
cellWeightsScale,
weightsOffset);
// 11: The cell-to-output weights (for peephole). Optional. Type: ANEURALNETWORKS_TENSOR_QUANT16_SYMM
// Shape: [numUnits]
AddTensorOperand<HalPolicy>(model,
cellToOutputWeightsDimensions,
cellToOutputWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT16_SYMM,
CreateNoValueLifeTime(cellToOutputWeightsDimensions),
cellWeightsScale,
weightsOffset);
// 12: The input gate bias. Quantized with scale being the product of input and weights scales
// and zeroPoint equal to 0. Optional. Type: ANEURALNETWORKS_TENSOR_INT32 Shape: [numUnits]
AddTensorOperand<HalPolicy>(model,
inputGateBiasDimensions,
inputGateBiasValue,
HalPolicy::OperandType::TENSOR_INT32,
CreateNoValueLifeTime(inputGateBiasDimensions),
biasScale,
biasOffset);
// 13: The forget gate bias. Quantized with scale being the product of input and weights scales
// and zeroPoint equal to 0. Type: ANEURALNETWORKS_TENSOR_INT32 Shape: [numUnits]
AddTensorOperand<HalPolicy>(model,
forgetGateBiasDimensions,
forgetGateBiasValue,
HalPolicy::OperandType::TENSOR_INT32,
CreateNoValueLifeTime(forgetGateBiasDimensions),
biasScale,
biasOffset);
// 14: The cell bias. Quantized with scale being the product of input and weights scales and zeroPoint equal to 0.
// Type: ANEURALNETWORKS_TENSOR_INT32 Shape: [numUnits]
AddTensorOperand<HalPolicy>(model,
cellBiasDimensions,
cellBiasValue,
HalPolicy::OperandType::TENSOR_INT32,
CreateNoValueLifeTime(cellBiasDimensions),
biasScale,
biasOffset);
// 15: The output gate bias. Quantized with scale being the product of input and weights scales
// and zeroPoint equal to 0. Type: ANEURALNETWORKS_TENSOR_INT32 Shape: [numUnits]
AddTensorOperand<HalPolicy>(model,
outputGateBiasDimensions,
outputGateBiasValue,
HalPolicy::OperandType::TENSOR_INT32,
CreateNoValueLifeTime(outputGateBiasDimensions),
biasScale,
biasOffset);
// 16: The projection weights. Optional. Type: ANEURALNETWORKS_TENSOR_QUANT8_SYMM Shape: [outputSize, numUnits]
AddTensorOperand<HalPolicy>(model,
projectionWeightsDimensions,
projectionWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT8_SYMM,
CreateNoValueLifeTime(projectionWeightsDimensions),
0.00392157f,
weightsOffset);
// 17: The projection bias. Quantized with scale being the product of input and weights scales
// and zeroPoint equal to 0. Optional. Type: ANEURALNETWORKS_TENSOR_INT32 Shape: [outputSize]
AddTensorOperand<HalPolicy>(model,
projectionBiasDimensions,
projectionBiasValue,
HalPolicy::OperandType::TENSOR_INT32,
CreateNoValueLifeTime(projectionBiasDimensions),
0.0f,
biasOffset);
// 18: The output from the previous time step. Type: ANEURALNETWORKS_TENSOR_QUANT8_ASYMM_SIGNED
// Shape: [batchSize, outputSize]
AddInputOperand<HalPolicy>(model,
outputPreviousTimeStepInDimensions,
HalPolicy::OperandType::TENSOR_QUANT8_ASYMM_SIGNED,
cellStateScale,
inputOffset);
// 19: The cell state from the previous time step. Type: ANEURALNETWORKS_TENSOR_QUANT16_SYMM
// Shape: [batchSize, numUnits]
AddInputOperand<HalPolicy>(model,
cellStatePreviousTimeStepInDimensions,
HalPolicy::OperandType::TENSOR_QUANT16_SYMM,
cellStateScale,
cellStateOffset);
// If any of the tensors have a value all normalization tensors are set
if (!inputLayerNormWeightsValue.empty() ||
!forgetLayerNormWeightsValue.empty() ||
!cellLayerNormWeightsValue.empty() ||
!outputLayerNormWeightsValue.empty())
{
// Normalization:
// 20: The input layer normalization weights. Used to rescale normalized inputs to activation at input gate.
// Optional. Type: ANEURALNETWORKS_TENSOR_QUANT16_SYMM Shape: [numUnits]
AddTensorOperand<HalPolicy>(model,
inputLayerNormWeightsDimensions,
inputLayerNormWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT16_SYMM,
CreateNoValueLifeTime(inputLayerNormWeightsDimensions),
layerNormScale,
layerNormOffset);
// 21: The forget layer normalization weights. Used to rescale normalized inputs to activation at forget gate.
// Optional. Type: ANEURALNETWORKS_TENSOR_QUANT16_SYMM Shape: [numUnits]
AddTensorOperand<HalPolicy>(model,
forgetLayerNormWeightsDimensions,
forgetLayerNormWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT16_SYMM,
CreateNoValueLifeTime(forgetLayerNormWeightsDimensions),
layerNormScale,
layerNormOffset);
// 22: The cell layer normalization weights. Used to rescale normalized inputs to activation at cell gate.
// Optional. Type: ANEURALNETWORKS_TENSOR_QUANT16_SYMM Shape: [numUnits]
AddTensorOperand<HalPolicy>(model,
cellLayerNormWeightsDimensions,
cellLayerNormWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT16_SYMM,
CreateNoValueLifeTime(cellLayerNormWeightsDimensions),
layerNormScale,
layerNormOffset);
// 23: The output layer normalization weights. Used to rescale normalized inputs to activation at output gate.
// Optional. Type: ANEURALNETWORKS_TENSOR_QUANT16_SYMM Shape: [numUnits]
AddTensorOperand<HalPolicy>(model,
outputLayerNormWeightsDimensions,
outputLayerNormWeightsValue,
HalPolicy::OperandType::TENSOR_QUANT16_SYMM,
CreateNoValueLifeTime(outputLayerNormWeightsDimensions),
layerNormScale,
layerNormOffset);
}
// Constant scalar values
// 24: The cell clip. If provided the cell state is clipped by this value prior to the cell output activation.
// Optional. Type: ANEURALNETWORKS_FLOAT32.
AddFloatOperand<HalPolicy>(model, cellClipValue);
// Constant scalar values
// 25: The projection clip. If provided and projection is enabled, this is used for clipping the projected values.
// Optional. Type: ANEURALNETWORKS_FLOAT32.
AddFloatOperand<HalPolicy>(model, projectionClipValue);
// Constant scalar values
// 26: The scale of the intermediate result of matmul, i.e. input to layer normalization, at input gate.
// Type: ANEURALNETWORKS_FLOAT32.
AddFloatOperand<HalPolicy>(model, matMulInputGateValue);
// Constant scalar values
// 27: The scale of the intermediate result of matmul, i.e. input to layer normalization, at forget gate.
// Type: ANEURALNETWORKS_FLOAT32.
AddFloatOperand<HalPolicy>(model, matMulForgetGateValue);
// Constant scalar values
// 28: The scale of the intermediate result of matmul, i.e. input to layer normalization, at cell gate.
// Type: ANEURALNETWORKS_FLOAT32.
AddFloatOperand<HalPolicy>(model, matMulCellGateValue);
// Constant scalar values
// 29: The scale of the intermediate result of matmul, i.e. input to layer normalization, at output gate.
// Type: ANEURALNETWORKS_FLOAT32.
AddFloatOperand<HalPolicy>(model, matMulOutputGateValue);
// Constant scalar values
// 30: The zero point of the hidden state, i.e. input to projection. Type: ANEURALNETWORKS_INT32.
AddIntOperand<HalPolicy>(model, projInputZeroPointValue);
// Constant scalar values
// 31: The scale of the hidden state, i.e. input to projection. Type: ANEURALNETWORKS_FLOAT32.
AddFloatOperand<HalPolicy>(model, projInputScaleValue);
// Outputs:
// 0: The output state (out). Type: ANEURALNETWORKS_TENSOR_QUANT8_ASYMM_SIGNED Shape: [batchSize, outputSize]
AddOutputOperand<HalPolicy>(model,
outputStateOutDimensions,
HalPolicy::OperandType::TENSOR_QUANT8_ASYMM_SIGNED,
cellStateScale,
cellStateScale);
// 1: The cell state (out). Type: ANEURALNETWORKS_TENSOR_QUANT16_SYMM Shape: [batchSize, numUnits].
AddOutputOperand<HalPolicy>(model,
cellStateOutDimensions,
HalPolicy::OperandType::TENSOR_QUANT16_SYMM,
cellStateScale,
cellStateOffset);
// 2: The output. This is effectively the same as the current "output state (out)" value.
// Type: ANEURALNETWORKS_TENSOR_QUANT8_ASYMM_SIGNED Shape: [batchSize, outputSize]
AddOutputOperand<HalPolicy>(model,
outputDimensions,
HalPolicy::OperandType::TENSOR_QUANT8_ASYMM_SIGNED,
cellStateScale,
cellStateScale);
// make the QUANTIZED_LSTM operation
model.main.operations.resize(1);
model.main.operations[0].type = HalPolicy::OperationType::QUANTIZED_LSTM;
model.main.operations[0].inputs = hidl_vec<uint32_t> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31};
model.main.operations[0].outputs = hidl_vec<uint32_t> {32, 33, 34};
// define the input values
hidl_vec<RequestArgument> inputArguments;
inputArguments.resize(3);
inputArguments[0] = CreateRequestArgument<int8_t>(inputValue, 0);
inputArguments[1] = CreateRequestArgument<int8_t>(outputPreviousTimeStepInValue, 1);
inputArguments[2] = CreateRequestArgument<int16_t>(cellStatePreviousTimeStepInValue, 2);
// define the expected output values
hidl_vec<RequestArgument> outputArguments;
outputArguments.resize(3);
outputArguments[0] = CreateRequestArgument<int8_t>(outputStateOutValue, 3);
outputArguments[1] = CreateRequestArgument<int16_t>(cellStateOutValue, 4);
outputArguments[2] = CreateRequestArgument<int8_t>(outputValue, 5);
android::hardware::neuralnetworks::V1_0::Request request = {};
request.inputs = inputArguments;
request.outputs = outputArguments;
// set the input data
AddPoolAndSetData(inputValue.size(), request, inputValue.data());
AddPoolAndSetData(outputPreviousTimeStepInValue.size(), request, outputPreviousTimeStepInValue.data());
AddPoolAndSetData(cellStatePreviousTimeStepInValue.size(), request, cellStatePreviousTimeStepInValue.data());
// add memory for the outputs
android::sp<IMemory> outputStateOutMemory = AddPoolAndGetData<int8_t>(outputStateOutValue.size(), request);
int8_t* outputStateOutData = static_cast<int8_t*>(static_cast<void*>(outputStateOutMemory->getPointer()));
android::sp<IMemory> cellStateOutMemory = AddPoolAndGetData<int16_t>(cellStateOutValue.size(), request);
int16_t* cellStateOutData = static_cast<int16_t*>(static_cast<void*>(cellStateOutMemory->getPointer()));
android::sp<IMemory> outputMemory = AddPoolAndGetData<int8_t>(outputValue.size(), request);
int8_t* outputData = static_cast<int8_t*>(static_cast<void*>(outputMemory->getPointer()));
// make the prepared model and run the execution
ExecuteModel(model, *driver, request);
// check the results
for (size_t i = 0; i < outputStateOutValue.size(); ++i)
{
CHECK_MESSAGE(outputStateOutValue[i] == doctest::Approx( outputStateOutData[i] ).epsilon(TOLERANCE),
"outputStateOut[" << i << "]: " << outputStateOutValue[i] << " != " << outputStateOutData[i]);
}
// CELL STATE OUTPUT Does not match currently: IVGCVSW-4860 Verify remaining VTS tests (2) for QLSTM
// Comment out for now
// for (size_t i = 0; i < cellStateOutValue.size(); ++i)
// {
// BOOST_TEST(TolerantCompareEqual(cellStateOutValue[i], cellStateOutData[i]),
// "cellStateOut[" << i << "]: " << cellStateOutValue[i] << " != " << cellStateOutData[i]);
//}
for (size_t i = 0; i < outputValue.size(); ++i)
{
CHECK_MESSAGE(outputValue[i] == doctest::Approx( outputData[i] ).epsilon(TOLERANCE),
"output[" << i << "]: " << outputValue[i] << " != " << outputData[i]);
}
}
void QLstmWithProjection(armnn::Compute compute)
{
// This replicates android/frameworks/ml/nn/runtime/test/specs/V1_3/qlstm_projection.mod.py
// with values from android/frameworks/ml/nn/runtime/test/generated/spec_V1_3/qlstm_projection.example.cpp
// and weights, biases and scalars passed as CONSTANT_COPY tensors (instead of SUBGRAPH_INPUT tensors).
uint32_t batchSize = 2;
uint32_t inputSize = 5;
uint32_t outputSize = 3;
uint32_t numUnits = 4;
// Inputs:
hidl_vec<uint32_t> inputDimensions{batchSize, inputSize};
std::vector<int8_t> inputValue{ 90, 102, 13, 26, 38, 102, 13, 26, 51, 64};
hidl_vec<uint32_t> inputToInputWeightsDimensions{numUnits, inputSize};
std::vector<int8_t> inputToInputWeightsValue{ 64, 77, 89, -102,
-115, 13, 25, 38,
-51, 64, -102, 89,
-77, 64, -51, -64,
-51, -38, -25, -13 };
hidl_vec<uint32_t> inputToForgetWeightsDimensions{numUnits, inputSize};
std::vector<int8_t> inputToForgetWeightsValue{ -77, -13, 38, 25,
115, -64, -25, -51,
38, -102, -51, 38,
-64, -51, -77, 38,
-51, -77, -64, -64 };
hidl_vec<uint32_t> inputToCellWeightsDimensions{numUnits, inputSize};
std::vector<int8_t> inputToCellWeightsValue{ -51, -38, -25, -13,
-64, 64, -25, -38,
-25, -77, 77, -13,
-51, -38, -89, 89,
-115, -64, 102, 77 };
hidl_vec<uint32_t> inputToOutputWeightsDimensions{numUnits, inputSize};
std::vector<int8_t> inputToOutputWeightsValue{ -102, -51, -25, -115,
-13, -89, 38, -38,
-102, -25, 77, -25,
51, -89, -38, -64,
13, 64, -77, -51 };
hidl_vec<uint32_t> recurrentToInputWeightsDimensions{numUnits, outputSize};
std::vector<int8_t> recurrentToInputWeightsValue{ -25, -38, 51, 13, -64, 115, -25, -38, -89, 6, -25, -77 };
hidl_vec<uint32_t> recurrentToForgetWeightsDimensions{numUnits, outputSize};
std::vector<int8_t> recurrentToForgetWeightsValue{ -64, -38, -64, -25, 77, 51, 115, 38, -13, 25, 64, 25 };
hidl_vec<uint32_t> recurrentToCellWeightsDimensions{numUnits, outputSize};
std::vector<int8_t> recurrentToCellWeightsValue{ -38, 25, 13, -38, 102, -10, -25, 38, 102, -77, -13, 25 };
hidl_vec<uint32_t> recurrentToOutputWeightsDimensions{numUnits, outputSize};
std::vector<int8_t> recurrentToOutputWeightsValue{ 38, -13, 13, -25, -64, -89, -25, -77, -13, -51, -89, -25 };
hidl_vec<uint32_t> cellToInputWeightsDimensions{0};
std::vector<int16_t> cellToInputWeightsValue;
hidl_vec<uint32_t> cellToForgetWeightsDimensions{0};
std::vector<int16_t> cellToForgetWeightsValue;
hidl_vec<uint32_t> cellToOutputWeightsDimensions{0};
std::vector<int16_t> cellToOutputWeightsValue;
hidl_vec<uint32_t> inputGateBiasDimensions{numUnits};
std::vector<int32_t> inputGateBiasValue{ 644245, 3221226, 4724464, 8160438 };
hidl_vec<uint32_t> forgetGateBiasDimensions{numUnits};
std::vector<int32_t> forgetGateBiasValue{ 2147484, -6442451, -4294968, 2147484 };
hidl_vec<uint32_t> cellBiasDimensions{numUnits};
std::vector<int32_t> cellBiasValue{-1073742, 15461883, 5368709, 1717987 };
hidl_vec<uint32_t> outputGateBiasDimensions{numUnits};
std::vector<int32_t> outputGateBiasValue{ 1073742, -214748, 4294968, 2147484 };
hidl_vec<uint32_t> projectionWeightsDimensions{outputSize, numUnits};
std::vector<int8_t> projectionWeightsValue{ -25, 51, 3, -51, 25, 127, 77, 20, 18, 51, -102, 51 };
hidl_vec<uint32_t> projectionBiasDimensions{outputSize};
std::vector<int32_t> projectionBiasValue{ 0, 0, 0 };
hidl_vec<uint32_t> outputStateInDimensions{batchSize, outputSize};
std::vector<int8_t> outputStateInValue{ 0, 0, 0, 0, 0, 0 };
hidl_vec<uint32_t> cellStateInDimensions{batchSize, numUnits};
std::vector<int16_t> cellStateInValue{ 0, 0, 0, 0, 0, 0, 0, 0 };
// Normalization:
hidl_vec<uint32_t> inputLayerNormWeightsDimensions{numUnits};
std::vector<int16_t> inputLayerNormWeightsValue{ 3277, 6553, 9830, 16384 };
hidl_vec<uint32_t> forgetLayerNormWeightsDimensions{numUnits};
std::vector<int16_t> forgetLayerNormWeightsValue{ 6553, 6553, 13107, 9830 };
hidl_vec<uint32_t> cellLayerNormWeightsDimensions{numUnits};
std::vector<int16_t> cellLayerNormWeightsValue{ 22937, 6553, 9830, 26214 };
hidl_vec<uint32_t> outputLayerNormWeightsDimensions{numUnits};
std::vector<int16_t> outputLayerNormWeightsValue{ 19660, 6553, 6553, 16384 };
float cellClipValue = 0.0f;
float projectionClipValue = 0.0f;
float inputIntermediateScale = 0.007059f;
float forgetIntermediateScale = 0.007812f;
float cellIntermediateScale = 0.007059f;
float outputIntermediateScale = 0.007812f;
int32_t hiddenStateZeroPoint = 0;
float hiddenStateScale = 0.007f;
// Outputs:
hidl_vec<uint32_t> outputStateOutDimensions{batchSize, outputSize};
std::vector<int8_t> outputStateOutValue{ 127, 127, -108, -67, 127, 127 };
hidl_vec<uint32_t> cellStateOutDimensions{batchSize, numUnits};
std::vector<int16_t> cellStateOutValue { -14650, 8939, 5771, 6715, -11843, 7847, 1508, 12939 };
hidl_vec<uint32_t> outputDimensions{batchSize, outputSize};
std::vector<int8_t> outputValue { 127, 127, -108, -67, 127, 127 };
QLstmTestImpl(inputDimensions, inputValue,
inputToInputWeightsDimensions, inputToInputWeightsValue,
inputToForgetWeightsDimensions, inputToForgetWeightsValue,
inputToCellWeightsDimensions, inputToCellWeightsValue,
inputToOutputWeightsDimensions, inputToOutputWeightsValue,
recurrentToInputWeightsDimensions, recurrentToInputWeightsValue,
recurrentToForgetWeightsDimensions, recurrentToForgetWeightsValue,
recurrentToCellWeightsDimensions, recurrentToCellWeightsValue,
recurrentToOutputWeightsDimensions, recurrentToOutputWeightsValue,
cellToInputWeightsDimensions, cellToInputWeightsValue,
cellToForgetWeightsDimensions, cellToForgetWeightsValue,
cellToOutputWeightsDimensions, cellToOutputWeightsValue,
inputGateBiasDimensions, inputGateBiasValue,
forgetGateBiasDimensions, forgetGateBiasValue,
cellBiasDimensions, cellBiasValue,
outputGateBiasDimensions, outputGateBiasValue,
projectionWeightsDimensions, projectionWeightsValue,
projectionBiasDimensions, projectionBiasValue,
outputStateInDimensions, outputStateInValue,
cellStateInDimensions, cellStateInValue,
inputLayerNormWeightsDimensions, inputLayerNormWeightsValue,
forgetLayerNormWeightsDimensions, forgetLayerNormWeightsValue,
cellLayerNormWeightsDimensions, cellLayerNormWeightsValue,
outputLayerNormWeightsDimensions, outputLayerNormWeightsValue,
cellClipValue,
projectionClipValue,
inputIntermediateScale,
forgetIntermediateScale,
cellIntermediateScale,
outputIntermediateScale,
hiddenStateZeroPoint,
hiddenStateScale,
outputStateOutDimensions, outputStateOutValue,
cellStateOutDimensions, cellStateOutValue,
outputDimensions, outputValue,
compute);
}
void QLstmWithNoProjection(armnn::Compute compute)
{
// This replicates android/frameworks/ml/nn/runtime/test/specs/V1_3/qlstm_noprojection.mod.py
// with values from android/frameworks/ml/nn/runtime/test/generated/spec_V1_3/qlstm_noprojection.example.cpp
// and weights, biases and scalars passed as CONSTANT_COPY tensors (instead of SUBGRAPH_INPUT tensors).
uint32_t batchSize = 2;
uint32_t inputSize = 5;
uint32_t outputSize = 4;
uint32_t numUnits = 4;
// Inputs:
hidl_vec<uint32_t> inputDimensions{batchSize, inputSize};
std::vector<int8_t> inputValue { 90, 102, 13, 26, 38, 102, 13, 26, 51, 64 };
hidl_vec<uint32_t> inputToInputWeightsDimensions{0, 0};
std::vector<int8_t> inputToInputWeightsValue;
hidl_vec<uint32_t> inputToForgetWeightsDimensions{numUnits, inputSize};
std::vector<int8_t> inputToForgetWeightsValue { -77, -13, 38, 25, 115,
-64, -25, -51, 38, -102,
-51, 38, -64, -51, -77,
38, -51, -77, -64, -64 };
hidl_vec<uint32_t> inputToCellWeightsDimensions{numUnits, inputSize};
std::vector<int8_t> inputToCellWeightsValue { -51, -38, -25, -13, -64,
64, -25, -38, -25, -77,
77, -13, -51, -38, -89,
89, -115, -64, 102, 77 };
hidl_vec<uint32_t> inputToOutputWeightsDimensions{numUnits, inputSize};
std::vector<int8_t> inputToOutputWeightsValue { -102, -51, -25, -115, -13,
-89, 38, -38, -102, -25,
77, -25, 51, -89, -38,
-64, 13, 64, -77, -51 };
hidl_vec<uint32_t> recurrentToInputWeightsDimensions{0, 0};
std::vector<int8_t> recurrentToInputWeightsValue;
hidl_vec<uint32_t> recurrentToForgetWeightsDimensions{numUnits, outputSize};
std::vector<int8_t> recurrentToForgetWeightsValue { -64, -38, -64, -25,
77, 51, 115, 38,
-13, 25, 64, 25,
25, 38, -13, 51 };
hidl_vec<uint32_t> recurrentToCellWeightsDimensions{numUnits, outputSize};
std::vector<int8_t> recurrentToCellWeightsValue { -38, 25, 13, -38,
102, -10, -25, 38,
102, -77, -13, 25,
38, -13, 25, 64 };
hidl_vec<uint32_t> recurrentToOutputWeightsDimensions{numUnits, outputSize};
std::vector<int8_t> recurrentToOutputWeightsValue { 38, -13, 13, -25,
-64, -89, -25, -77,
-13, -51, -89, -25,
13, 64, 25, -38 };
hidl_vec<uint32_t> cellToInputWeightsDimensions{0};
std::vector<int16_t> cellToInputWeightsValue;
hidl_vec<uint32_t> cellToForgetWeightsDimensions{0};
std::vector<int16_t> cellToForgetWeightsValue;
hidl_vec<uint32_t> cellToOutputWeightsDimensions{0};
std::vector<int16_t> cellToOutputWeightsValue;
hidl_vec<uint32_t> inputGateBiasDimensions{0};
std::vector<int32_t> inputGateBiasValue;
hidl_vec<uint32_t> forgetGateBiasDimensions{numUnits};
std::vector<int32_t> forgetGateBiasValue { 2147484, -6442451, -4294968, 2147484 };
hidl_vec<uint32_t> cellBiasDimensions{numUnits};
std::vector<int32_t> cellBiasValue { -1073742, 15461883, 5368709, 1717987 };
hidl_vec<uint32_t> outputGateBiasDimensions{numUnits};
std::vector<int32_t> outputGateBiasValue { 1073742, -214748, 4294968, 2147484 };
hidl_vec<uint32_t> projectionWeightsDimensions{0, 0};
std::vector<int8_t> projectionWeightsValue;
hidl_vec<uint32_t> projectionBiasDimensions{0};
std::vector<int32_t> projectionBiasValue;
hidl_vec<uint32_t> outputStateInDimensions{batchSize, outputSize};
std::vector<int8_t> outputStateInValue { 0, 0, 0, 0, 0, 0, 0, 0 };
hidl_vec<uint32_t> cellStateInDimensions{batchSize, numUnits};
std::vector<int16_t> cellStateInValue { 0, 0, 0, 0, 0, 0, 0, 0 };
// Normalization:
hidl_vec<uint32_t> inputLayerNormWeightsDimensions{0};
std::vector<int16_t> inputLayerNormWeightsValue;
hidl_vec<uint32_t> forgetLayerNormWeightsDimensions{numUnits};
std::vector<int16_t> forgetLayerNormWeightsValue { 6553, 6553, 13107, 9830 };
hidl_vec<uint32_t> cellLayerNormWeightsDimensions{numUnits};
std::vector<int16_t> cellLayerNormWeightsValue { 22937, 6553, 9830, 26214 };
hidl_vec<uint32_t> outputLayerNormWeightsDimensions{numUnits};
std::vector<int16_t> outputLayerNormWeightsValue { 19660, 6553, 6553, 16384 };
float cellClipValue = 0.0f;
float projectionClipValue = 0.0f;
float inputIntermediateScale = 0.007059f;
float forgetIntermediateScale = 0.007812f;
float cellIntermediateScale = 0.007059f;
float outputIntermediateScale = 0.007812f;
int32_t hiddenStateZeroPoint = 0;
float hiddenStateScale = 0.007f;
// Outputs:
hidl_vec<uint32_t> outputStateOutDimensions{batchSize, outputSize};
std::vector<int8_t> outputStateOutValue { -15, 21, 14, 20, -15, 15, 5, 27 };
hidl_vec<uint32_t> cellStateOutDimensions{batchSize, numUnits};
std::vector<int16_t> cellStateOutValue { -11692, 9960, 5491, 8861, -9422, 7726, 2056, 13149 };
hidl_vec<uint32_t> outputDimensions{batchSize, outputSize};
std::vector<int8_t> outputValue { -15, 21, 14, 20, -15, 15, 5, 27 };
QLstmTestImpl(inputDimensions, inputValue,
inputToInputWeightsDimensions, inputToInputWeightsValue,
inputToForgetWeightsDimensions, inputToForgetWeightsValue,
inputToCellWeightsDimensions, inputToCellWeightsValue,
inputToOutputWeightsDimensions, inputToOutputWeightsValue,
recurrentToInputWeightsDimensions, recurrentToInputWeightsValue,
recurrentToForgetWeightsDimensions, recurrentToForgetWeightsValue,
recurrentToCellWeightsDimensions, recurrentToCellWeightsValue,
recurrentToOutputWeightsDimensions, recurrentToOutputWeightsValue,
cellToInputWeightsDimensions, cellToInputWeightsValue,
cellToForgetWeightsDimensions, cellToForgetWeightsValue,
cellToOutputWeightsDimensions, cellToOutputWeightsValue,
inputGateBiasDimensions, inputGateBiasValue,
forgetGateBiasDimensions, forgetGateBiasValue,
cellBiasDimensions, cellBiasValue,
outputGateBiasDimensions, outputGateBiasValue,
projectionWeightsDimensions, projectionWeightsValue,
projectionBiasDimensions, projectionBiasValue,
outputStateInDimensions, outputStateInValue,
cellStateInDimensions, cellStateInValue,
inputLayerNormWeightsDimensions, inputLayerNormWeightsValue,
forgetLayerNormWeightsDimensions, forgetLayerNormWeightsValue,
cellLayerNormWeightsDimensions, cellLayerNormWeightsValue,
outputLayerNormWeightsDimensions, outputLayerNormWeightsValue,
cellClipValue,
projectionClipValue,
inputIntermediateScale,
forgetIntermediateScale,
cellIntermediateScale,
outputIntermediateScale,
hiddenStateZeroPoint,
hiddenStateScale,
outputStateOutDimensions, outputStateOutValue,
cellStateOutDimensions, cellStateOutValue,
outputDimensions, outputValue,
compute);
}
void DynamicOutputQLstmWithNoProjection(armnn::Compute compute)
{
// This replicates android/frameworks/ml/nn/runtime/test/specs/V1_3/qlstm_noprojection.mod.py
// with values from android/frameworks/ml/nn/runtime/test/generated/spec_V1_3/qlstm_noprojection.example.cpp
// and weights, biases and scalars passed as CONSTANT_COPY tensors (instead of SUBGRAPH_INPUT tensors)
// and made cellStateOutput dynamic.
uint32_t batchSize = 2;
uint32_t inputSize = 5;
uint32_t outputSize = 4;
uint32_t numUnits = 4;
// Inputs:
hidl_vec<uint32_t> inputDimensions{batchSize, inputSize};
std::vector<int8_t> inputValue { 90, 102, 13, 26, 38, 102, 13, 26, 51, 64 };
hidl_vec<uint32_t> inputToInputWeightsDimensions{0, 0};
std::vector<int8_t> inputToInputWeightsValue;
hidl_vec<uint32_t> inputToForgetWeightsDimensions{numUnits, inputSize};
std::vector<int8_t> inputToForgetWeightsValue { -77, -13, 38, 25, 115,
-64, -25, -51, 38, -102,
-51, 38, -64, -51, -77,
38, -51, -77, -64, -64 };
hidl_vec<uint32_t> inputToCellWeightsDimensions{numUnits, inputSize};
std::vector<int8_t> inputToCellWeightsValue { -51, -38, -25, -13, -64,
64, -25, -38, -25, -77,
77, -13, -51, -38, -89,
89, -115, -64, 102, 77 };
hidl_vec<uint32_t> inputToOutputWeightsDimensions{numUnits, inputSize};
std::vector<int8_t> inputToOutputWeightsValue { -102, -51, -25, -115, -13,
-89, 38, -38, -102, -25,
77, -25, 51, -89, -38,
-64, 13, 64, -77, -51 };
hidl_vec<uint32_t> recurrentToInputWeightsDimensions{0, 0};
std::vector<int8_t> recurrentToInputWeightsValue;
hidl_vec<uint32_t> recurrentToForgetWeightsDimensions{numUnits, outputSize};
std::vector<int8_t> recurrentToForgetWeightsValue { -64, -38, -64, -25,
77, 51, 115, 38,
-13, 25, 64, 25,
25, 38, -13, 51 };
hidl_vec<uint32_t> recurrentToCellWeightsDimensions{numUnits, outputSize};
std::vector<int8_t> recurrentToCellWeightsValue { -38, 25, 13, -38,
102, -10, -25, 38,
102, -77, -13, 25,
38, -13, 25, 64 };
hidl_vec<uint32_t> recurrentToOutputWeightsDimensions{numUnits, outputSize};
std::vector<int8_t> recurrentToOutputWeightsValue { 38, -13, 13, -25,
-64, -89, -25, -77,
-13, -51, -89, -25,
13, 64, 25, -38 };
hidl_vec<uint32_t> cellToInputWeightsDimensions{0};
std::vector<int16_t> cellToInputWeightsValue;
hidl_vec<uint32_t> cellToForgetWeightsDimensions{0};
std::vector<int16_t> cellToForgetWeightsValue;
hidl_vec<uint32_t> cellToOutputWeightsDimensions{0};
std::vector<int16_t> cellToOutputWeightsValue;
hidl_vec<uint32_t> inputGateBiasDimensions{0};
std::vector<int32_t> inputGateBiasValue;
hidl_vec<uint32_t> forgetGateBiasDimensions{numUnits};
std::vector<int32_t> forgetGateBiasValue { 2147484, -6442451, -4294968, 2147484 };
hidl_vec<uint32_t> cellBiasDimensions{numUnits};
std::vector<int32_t> cellBiasValue { -1073742, 15461883, 5368709, 1717987 };
hidl_vec<uint32_t> outputGateBiasDimensions{numUnits};
std::vector<int32_t> outputGateBiasValue { 1073742, -214748, 4294968, 2147484 };
hidl_vec<uint32_t> projectionWeightsDimensions{0, 0};
std::vector<int8_t> projectionWeightsValue;
hidl_vec<uint32_t> projectionBiasDimensions{0};
std::vector<int32_t> projectionBiasValue;
hidl_vec<uint32_t> outputStateInDimensions{batchSize, outputSize};
std::vector<int8_t> outputStateInValue { 0, 0, 0, 0, 0, 0, 0, 0 };
hidl_vec<uint32_t> cellStateInDimensions{batchSize, numUnits};
std::vector<int16_t> cellStateInValue { 0, 0, 0, 0, 0, 0, 0, 0 };
// Normalization:
hidl_vec<uint32_t> inputLayerNormWeightsDimensions{0};
std::vector<int16_t> inputLayerNormWeightsValue;
hidl_vec<uint32_t> forgetLayerNormWeightsDimensions{numUnits};
std::vector<int16_t> forgetLayerNormWeightsValue { 6553, 6553, 13107, 9830 };
hidl_vec<uint32_t> cellLayerNormWeightsDimensions{numUnits};
std::vector<int16_t> cellLayerNormWeightsValue { 22937, 6553, 9830, 26214 };
hidl_vec<uint32_t> outputLayerNormWeightsDimensions{numUnits};
std::vector<int16_t> outputLayerNormWeightsValue { 19660, 6553, 6553, 16384 };
float cellClipValue = 0.0f;
float projectionClipValue = 0.0f;
float inputIntermediateScale = 0.007059f;
float forgetIntermediateScale = 0.007812f;
float cellIntermediateScale = 0.007059f;
float outputIntermediateScale = 0.007812f;
int32_t hiddenStateZeroPoint = 0;
float hiddenStateScale = 0.007f;
// Outputs:
hidl_vec<uint32_t> outputStateOutDimensions{batchSize, outputSize};
std::vector<int8_t> outputStateOutValue { -15, 21, 14, 20, -15, 15, 5, 27 };
hidl_vec<uint32_t> cellStateOutDimensions{};
std::vector<int16_t> cellStateOutValue { -11692, 9960, 5491, 8861, -9422, 7726, 2056, 13149 };
hidl_vec<uint32_t> outputDimensions{batchSize, outputSize};
std::vector<int8_t> outputValue { -15, 21, 14, 20, -15, 15, 5, 27 };
QLstmTestImpl(inputDimensions, inputValue,
inputToInputWeightsDimensions, inputToInputWeightsValue,
inputToForgetWeightsDimensions, inputToForgetWeightsValue,
inputToCellWeightsDimensions, inputToCellWeightsValue,
inputToOutputWeightsDimensions, inputToOutputWeightsValue,
recurrentToInputWeightsDimensions, recurrentToInputWeightsValue,
recurrentToForgetWeightsDimensions, recurrentToForgetWeightsValue,
recurrentToCellWeightsDimensions, recurrentToCellWeightsValue,
recurrentToOutputWeightsDimensions, recurrentToOutputWeightsValue,
cellToInputWeightsDimensions, cellToInputWeightsValue,
cellToForgetWeightsDimensions, cellToForgetWeightsValue,
cellToOutputWeightsDimensions, cellToOutputWeightsValue,
inputGateBiasDimensions, inputGateBiasValue,
forgetGateBiasDimensions, forgetGateBiasValue,
cellBiasDimensions, cellBiasValue,
outputGateBiasDimensions, outputGateBiasValue,
projectionWeightsDimensions, projectionWeightsValue,
projectionBiasDimensions, projectionBiasValue,
outputStateInDimensions, outputStateInValue,
cellStateInDimensions, cellStateInValue,
inputLayerNormWeightsDimensions, inputLayerNormWeightsValue,
forgetLayerNormWeightsDimensions, forgetLayerNormWeightsValue,
cellLayerNormWeightsDimensions, cellLayerNormWeightsValue,
outputLayerNormWeightsDimensions, outputLayerNormWeightsValue,
cellClipValue,
projectionClipValue,
inputIntermediateScale,
forgetIntermediateScale,
cellIntermediateScale,
outputIntermediateScale,
hiddenStateZeroPoint,
hiddenStateScale,
outputStateOutDimensions, outputStateOutValue,
cellStateOutDimensions, cellStateOutValue,
outputDimensions, outputValue,
compute);
}
} // anonymous namespace
// Support is not added yet
//TEST_CASE(QLSTMWithProjectionTest, COMPUTE_DEVICES)
//{
// QLstmWithProjection(sample);
//}
TEST_SUITE("QLSTMTests_CpuRef")
{
TEST_CASE("QLSTMWithNoProjectionTest_CpuRef")
{
QLstmWithNoProjection(armnn::Compute::CpuRef);
}
TEST_CASE("DynamicOutputQLstmWithNoProjection_CpuRef")
{
DynamicOutputQLstmWithNoProjection(armnn::Compute::CpuRef);
}
}
#ifdef ARMCOMPUTECL_ENABLED
TEST_SUITE("QLSTMTests_CpuAcc")
{
TEST_CASE("QLSTMWithNoProjectionTest_CpuAcc")
{
QLstmWithNoProjection(armnn::Compute::CpuAcc);
}
TEST_CASE("DynamicOutputQLstmWithNoProjection_CpuAcc")
{
DynamicOutputQLstmWithNoProjection(armnn::Compute::CpuAcc);
}
}
#endif
| 52.115087 | 118 | 0.597101 | [
"shape",
"vector",
"model"
] |
82afb288deca74b47e9cdd8665242e2f369eaf54 | 5,956 | cpp | C++ | enduser/speech/sapi/sapi/dsaudiobuffer.cpp | npocmaka/Windows-Server-2003 | 5c6fe3db626b63a384230a1aa6b92ac416b0765f | [
"Unlicense"
] | 17 | 2020-11-13T13:42:52.000Z | 2021-09-16T09:13:13.000Z | enduser/speech/sapi/sapi/dsaudiobuffer.cpp | sancho1952007/Windows-Server-2003 | 5c6fe3db626b63a384230a1aa6b92ac416b0765f | [
"Unlicense"
] | 2 | 2020-10-19T08:02:06.000Z | 2020-10-19T08:23:18.000Z | enduser/speech/sapi/sapi/dsaudiobuffer.cpp | sancho1952007/Windows-Server-2003 | 5c6fe3db626b63a384230a1aa6b92ac416b0765f | [
"Unlicense"
] | 14 | 2020-11-14T09:43:20.000Z | 2021-08-28T08:59:57.000Z | /****************************************************************************
* dsaudiobuffer.cpp
* Implementation of the CDSoundAudioBuffer class and it's derivatives.
*
* Owner: YUNUSM
* Copyright (c) 1999 Microsoft Corporation All Rights Reserved.
*****************************************************************************/
//--- Includes --------------------------------------------------------------
#include "stdafx.h"
#ifdef _WIN32_WCE
#include "dsaudiobuffer.h"
#include <dsound.h>
/****************************************************************************
* CDSoundAudioBuffer::CDSoundAudioBuffer *
*----------------------------------------*
* Description:
* Ctor
*
* Return:
* n/a
******************************************************************* YUNUSM */
CDSoundAudioBuffer::CDSoundAudioBuffer()
{
ZeroMemory(&m_Header, sizeof(m_Header));
}
/****************************************************************************
* CDSoundAudioBuffer::AllocInternalBuffer *
*-----------------------------------------*
* Description:
* Allocate internal buffer store for this object.
*
* Return:
* TRUE if successful
* FALSE if not
******************************************************************* YUNUSM */
BOOL CDSoundAudioBuffer::AllocInternalBuffer(ULONG cb)
{
SPDBG_ASSERT(NULL == m_Header.lpData);
m_Header.lpData = new char[cb];
if (m_Header.lpData)
{
m_Header.dwUser = 0;
return TRUE;
}
return FALSE;
}
/****************************************************************************
* CDSoundAudioBuffer::~CDSoundAudioBuffer *
*-----------------------------------------*
* Description:
* Dtor
*
* Return:
* n/a
******************************************************************* YUNUSM */
CDSoundAudioBuffer::~CDSoundAudioBuffer()
{
delete[] m_Header.lpData;
}
/****************************************************************************
* CDSoundAudioBuffer::AsyncRead *
*-------------------------------*
* Description:
* Overriden because this is a virtual function in base class.
* This function is only called for input object buffers.
*
* Return:
* S_OK
******************************************************************* YUNUSM */
HRESULT CDSoundAudioBuffer::AsyncRead()
{
SetReadOffset(0);
SetWriteOffset(0);
m_Header.dwFlags &= ~(WHDR_PREPARED | WHDR_DONE);
return S_OK;
}
/****************************************************************************
* CDSoundAudioBuffer::AsyncWrite *
*----------------------------------*
* Description:
* Overriden because this is a virtual function in base class.
* This function is only called for output object buffers.
*
* Return:
* S_OK
******************************************************************* YUNUSM */
HRESULT CDSoundAudioBuffer::AsyncWrite()
{
return S_OK;
}
/****************************************************************************
* CDSoundAudioInBuffer::ReadFromInternalBuffer *
*----------------------------------------------*
* Description:
* Read from the internal buffer into the memory pointed to by pvData
*
* Return:
* S_OK if successful
* FAILED(hr) otherwise
******************************************************************* YUNUSM */
HRESULT CDSoundAudioInBuffer::ReadFromInternalBuffer(void *pvData, ULONG cb)
{
SPDBG_ASSERT(IsAsyncDone());
memcpy(pvData, m_Header.lpData + GetReadOffset(), cb);
return S_OK;
}
/****************************************************************************
* CDSoundAudioInBuffer::WriteToInternalBuffer *
*---------------------------------------------*
* Description:
* Write to the internal buffer from the memory pointed to by pvData
*
* Return:
* S_OK if successful
* FAILED(hr) otherwise
******************************************************************* YUNUSM */
HRESULT CDSoundAudioInBuffer::WriteToInternalBuffer(const void *pvData, ULONG cb)
{
memcpy(m_Header.lpData + GetWriteOffset(), pvData, cb);
m_Header.dwBytesRecorded = cb;
m_Header.dwFlags = WHDR_PREPARED | WHDR_DONE;
return S_OK;
}
/****************************************************************************
* CDSoundAudioOutBuffer::ReadFromInternalBuffer *
*-----------------------------------------------*
* Description:
* Read from the internal buffer into the memory pointed to by pvData
*
* Return:
* S_OK if successful
* FAILED(hr) otherwise
******************************************************************* YUNUSM */
HRESULT CDSoundAudioOutBuffer::ReadFromInternalBuffer(void *pvData, ULONG cb)
{
if (cb > m_Header.dwBytesRecorded - GetReadOffset())
cb = m_Header.dwBytesRecorded - GetReadOffset();
memcpy(pvData, m_Header.lpData + GetReadOffset(), cb);
if (cb + GetReadOffset() == m_Header.dwBytesRecorded)
m_Header.dwFlags = WHDR_PREPARED | WHDR_DONE;
SetReadOffset(GetReadOffset() + cb);
return S_OK;
}
/****************************************************************************
* CDSoundAudioOutBuffer::WriteToInternalBuffer *
*----------------------------------------------*
* Description:
* Write to the internal buffer from the memory pointed to by pvData
*
* Return:
* S_OK if successful
* FAILED(hr) otherwise
******************************************************************* YUNUSM */
HRESULT CDSoundAudioOutBuffer::WriteToInternalBuffer(const void *pvData, ULONG cb)
{
m_Header.dwFlags &= ~(WHDR_PREPARED | WHDR_DONE);
memcpy(m_Header.lpData + GetWriteOffset(), pvData, cb);
if (!GetWriteOffset())
m_Header.dwBytesRecorded = cb;
else
m_Header.dwBytesRecorded += cb;
return S_OK;
}
#endif // WIN32_WCE | 32.906077 | 83 | 0.448959 | [
"object"
] |
a11609dd97d2b4ef99fe878ececeebecd6d0d8d8 | 12,861 | cpp | C++ | Firmware/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp | M1dn1ghtN1nj4/UnifiedFirmware | 510ef8f4145dcbae1caced5e391c3888e6022b00 | [
"Info-ZIP"
] | 6 | 2020-12-04T21:55:04.000Z | 2022-02-02T20:49:45.000Z | Firmware/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp | M1dn1ghtN1nj4/UnifiedFirmware | 510ef8f4145dcbae1caced5e391c3888e6022b00 | [
"Info-ZIP"
] | 24 | 2020-12-25T05:00:51.000Z | 2021-04-20T00:56:50.000Z | Firmware/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp | M1dn1ghtN1nj4/UnifiedFirmware | 510ef8f4145dcbae1caced5e391c3888e6022b00 | [
"Info-ZIP"
] | 3 | 2021-05-01T15:13:41.000Z | 2022-02-11T01:15:30.000Z | /***********************
* bed_mesh_screen.cpp *
***********************/
/****************************************************************************
* Written By Marcio Teixeira 2020 *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (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. *
* *
* To view a copy of the GNU General Public License, go to the following *
* location: <https://www.gnu.org/licenses/>. *
****************************************************************************/
#include "../config.h"
#if BOTH(TOUCH_UI_FTDI_EVE, HAS_MESH)
#include "screens.h"
#include "screen_data.h"
using namespace FTDI;
using namespace Theme;
using namespace ExtUI;
#ifdef TOUCH_UI_PORTRAIT
#define GRID_COLS 2
#define GRID_ROWS 10
#define MESH_POS BTN_POS(1, 2), BTN_SIZE(2,5)
#define MESSAGE_POS BTN_POS(1, 7), BTN_SIZE(2,1)
#define Z_LABEL_POS BTN_POS(1, 8), BTN_SIZE(1,1)
#define Z_VALUE_POS BTN_POS(2, 8), BTN_SIZE(1,1)
#define OKAY_POS BTN_POS(1,10), BTN_SIZE(2,1)
#else
#define GRID_COLS 5
#define GRID_ROWS 5
#define MESH_POS BTN_POS(1,1), BTN_SIZE(3,5)
#define MESSAGE_POS BTN_POS(4,1), BTN_SIZE(2,1)
#define Z_LABEL_POS BTN_POS(4,2), BTN_SIZE(2,1)
#define Z_VALUE_POS BTN_POS(4,3), BTN_SIZE(2,1)
#define OKAY_POS BTN_POS(4,5), BTN_SIZE(2,1)
#endif
void BedMeshScreen::drawMesh(int16_t x, int16_t y, int16_t w, int16_t h, ExtUI::bed_mesh_t data, uint8_t opts, float autoscale_max) {
constexpr uint8_t rows = GRID_MAX_POINTS_Y;
constexpr uint8_t cols = GRID_MAX_POINTS_X;
#define VALUE(X,Y) (data ? data[X][Y] : 0)
#define ISVAL(X,Y) (data ? !isnan(VALUE(X,Y)) : true)
#define HEIGHT(X,Y) (ISVAL(X,Y) ? (VALUE(X,Y) - val_min) * scale_z : 0)
// Compute the mean, min and max for the points
float val_mean = 0;
float val_max = -INFINITY;
float val_min = INFINITY;
uint8_t val_cnt = 0;
if (data && (opts & USE_AUTOSCALE)) {
for (uint8_t y = 0; y < rows; y++) {
for (uint8_t x = 0; x < cols; x++) {
if (ISVAL(x,y)) {
const float val = VALUE(x,y);
val_mean += val;
val_max = max(val_max, val);
val_min = min(val_min, val);
val_cnt++;
}
}
}
}
if (val_cnt) {
val_mean /= val_cnt;
} else {
val_mean = 0;
val_min = 0;
val_max = 0;
}
const float scale_z = ((val_max == val_min) ? 1 : 1/(val_max - val_min)) * autoscale_max;
/**
* The 3D points go through a 3D graphics pipeline to determine the final 2D point on the screen.
* This is written out as a stack of macros that each apply an affine transformation to the point.
* At compile time, the compiler should be able to reduce these expressions.
*
* The last transformation in the chain (TRANSFORM_5) is initially set to a no-op so we can measure
* the dimensions of the grid, but is later replaced with a scaling transform that scales the grid
* to fit.
*/
#define TRANSFORM_5(X,Y,Z) (X), (Y) // No transform
#define TRANSFORM_4(X,Y,Z) TRANSFORM_5((X)/(Z),(Y)/-(Z), 0) // Perspective
#define TRANSFORM_3(X,Y,Z) TRANSFORM_4((X), (Z), (Y)) // Swap Z and Y
#define TRANSFORM_2(X,Y,Z) TRANSFORM_3((X), (Y) + 2.5, (Z) - 1) // Translate
#define TRANSFORM(X,Y,Z) TRANSFORM_2(float(X)/(cols-1) - 0.5, float(Y)/(rows-1) - 0.5, (Z)) // Normalize
// Compute the bounding box for the grid prior to scaling. Do this at compile-time by
// transforming the four corner points via the transformation equations and finding
// the min and max for each axis.
constexpr float bounds[][3] = {{TRANSFORM(0 , 0 , 0)},
{TRANSFORM(cols-1, 0 , 0)},
{TRANSFORM(0 , rows-1, 0)},
{TRANSFORM(cols-1, rows-1, 0)}};
#define APPLY(FUNC, AXIS) FUNC(FUNC(bounds[0][AXIS], bounds[1][AXIS]), FUNC(bounds[2][AXIS], bounds[3][AXIS]))
constexpr float grid_x = APPLY(min,0);
constexpr float grid_y = APPLY(min,1);
constexpr float grid_w = APPLY(max,0) - grid_x;
constexpr float grid_h = APPLY(max,1) - grid_y;
constexpr float grid_cx = grid_x + grid_w/2;
constexpr float grid_cy = grid_y + grid_h/2;
// Figure out scale and offset such that the grid fits within the rectangle given by (x,y,w,h)
const float scale_x = float(w)/grid_w;
const float scale_y = float(h)/grid_h;
const float center_x = x + w/2;
const float center_y = y + h/2;
// Now replace the last transformation in the chain with a scaling operation.
#undef TRANSFORM_5
#define TRANSFORM_6(X,Y,Z) (X)*16, (Y)*16 // Scale to 1/16 pixel units
#define TRANSFORM_5(X,Y,Z) TRANSFORM_6( center_x + ((X) - grid_cx) * scale_x, \
center_y + ((Y) - grid_cy) * scale_y, 0) // Scale to bounds
// Draw the grid
const uint16_t basePointSize = min(w,h) / max(cols,rows);
CommandProcessor cmd;
cmd.cmd(SAVE_CONTEXT())
.cmd(TAG_MASK(false))
.cmd(SAVE_CONTEXT());
for (uint8_t y = 0; y < rows; y++) {
for (uint8_t x = 0; x < cols; x++) {
if (ISVAL(x,y)) {
const bool hasLeftSegment = x < cols - 1 && ISVAL(x+1,y);
const bool hasRightSegment = y < rows - 1 && ISVAL(x,y+1);
if (hasLeftSegment || hasRightSegment) {
cmd.cmd(BEGIN(LINE_STRIP));
if (hasLeftSegment) cmd.cmd(VERTEX2F(TRANSFORM(x + 1, y , HEIGHT(x + 1, y ))));
cmd.cmd( VERTEX2F(TRANSFORM(x , y , HEIGHT(x , y ))));
if (hasRightSegment) cmd.cmd(VERTEX2F(TRANSFORM(x , y + 1, HEIGHT(x , y + 1))));
}
}
}
if (opts & USE_POINTS) {
const float sq_min = sq(val_min - val_mean);
const float sq_max = sq(val_max - val_mean);
cmd.cmd(POINT_SIZE(basePointSize * 2));
cmd.cmd(BEGIN(POINTS));
for (uint8_t x = 0; x < cols; x++) {
if (ISVAL(x,y)) {
if (opts & USE_COLORS) {
const float val_dev = VALUE(x, y) - val_mean;
const uint8_t neg_byte = sq(val_dev) / (val_dev < 0 ? sq_min : sq_max) * 0xFF;
const uint8_t pos_byte = 255 - neg_byte;
cmd.cmd(COLOR_RGB(pos_byte, pos_byte, 0xFF));
}
cmd.cmd(VERTEX2F(TRANSFORM(x, y, HEIGHT(x, y))));
}
}
if (opts & USE_COLORS) {
cmd.cmd(RESTORE_CONTEXT())
.cmd(SAVE_CONTEXT());
}
}
}
cmd.cmd(RESTORE_CONTEXT())
.cmd(TAG_MASK(true));
if (opts & USE_TAGS) {
cmd.cmd(COLOR_MASK(false, false, false, false))
.cmd(POINT_SIZE(basePointSize * 10))
.cmd(BEGIN(POINTS));
for (uint8_t y = 0; y < rows; y++) {
for (uint8_t x = 0; x < cols; x++) {
const uint8_t tag = pointToTag(x, y);
cmd.tag(tag).cmd(VERTEX2F(TRANSFORM(x, y, HEIGHT(x, y))));
}
}
cmd.cmd(COLOR_MASK(true, true, true, true));
}
if (opts & USE_HIGHLIGHT) {
const uint8_t tag = screen_data.BedMeshScreen.highlightedTag;
uint8_t x, y;
if (tagToPoint(tag, x, y)) {
cmd.cmd(COLOR_A(128))
.cmd(POINT_SIZE(basePointSize * 6))
.cmd(BEGIN(POINTS))
.tag(tag).cmd(VERTEX2F(TRANSFORM(x, y, HEIGHT(x, y))));
}
}
cmd.cmd(END());
cmd.cmd(RESTORE_CONTEXT());
}
uint8_t BedMeshScreen::pointToTag(uint8_t x, uint8_t y) {
return y * (GRID_MAX_POINTS_X) + x + 10;
}
bool BedMeshScreen::tagToPoint(uint8_t tag, uint8_t &x, uint8_t &y) {
if (tag < 10) return false;
x = (tag - 10) % (GRID_MAX_POINTS_X);
y = (tag - 10) / (GRID_MAX_POINTS_X);
return true;
}
void BedMeshScreen::onEntry() {
screen_data.BedMeshScreen.highlightedTag = 0;
screen_data.BedMeshScreen.count = GRID_MAX_POINTS;
screen_data.BedMeshScreen.message = screen_data.BedMeshScreen.MSG_NONE;
BaseScreen::onEntry();
}
float BedMeshScreen::getHightlightedValue() {
if (screen_data.BedMeshScreen.highlightedTag) {
xy_uint8_t pt;
tagToPoint(screen_data.BedMeshScreen.highlightedTag, pt.x, pt.y);
return ExtUI::getMeshPoint(pt);
}
return NAN;
}
void BedMeshScreen::drawHighlightedPointValue() {
char str[16];
const float val = getHightlightedValue();
const bool isGood = !isnan(val);
if (isGood)
dtostrf(val, 5, 3, str);
else
strcpy_P(str, PSTR("-"));
CommandProcessor cmd;
cmd.font(Theme::font_medium)
.text(Z_LABEL_POS, GET_TEXT_F(MSG_MESH_EDIT_Z))
.text(Z_VALUE_POS, str)
.colors(action_btn)
.tag(1).button( OKAY_POS, GET_TEXT_F(MSG_BUTTON_OKAY))
.tag(0);
switch (screen_data.BedMeshScreen.message) {
case screen_data.BedMeshScreen.MSG_MESH_COMPLETE: cmd.text(MESSAGE_POS, GET_TEXT_F(MSG_BED_MAPPING_DONE)); break;
case screen_data.BedMeshScreen.MSG_MESH_INCOMPLETE: cmd.text(MESSAGE_POS, GET_TEXT_F(MSG_BED_MAPPING_INCOMPLETE)); break;
default: break;
}
}
void BedMeshScreen::onRedraw(draw_mode_t what) {
#define _INSET_POS(x,y,w,h) x + min(w,h)/10, y + min(w,h)/10, w - min(w,h)/5, h - min(w,h)/5
#define INSET_POS(pos) _INSET_POS(pos)
if (what & BACKGROUND) {
CommandProcessor cmd;
cmd.cmd(CLEAR_COLOR_RGB(bg_color))
.cmd(CLEAR(true,true,true));
// Draw the shadow and tags
cmd.cmd(COLOR_RGB(0x444444));
BedMeshScreen::drawMesh(INSET_POS(MESH_POS), nullptr, USE_POINTS | USE_TAGS);
cmd.cmd(COLOR_RGB(bg_text_enabled));
}
if (what & FOREGROUND) {
constexpr float autoscale_max_amplitude = 0.03;
const bool gotAllPoints = screen_data.BedMeshScreen.count >= GRID_MAX_POINTS;
if (gotAllPoints) {
drawHighlightedPointValue();
}
const float levelingProgress = sq(float(screen_data.BedMeshScreen.count) / GRID_MAX_POINTS);
BedMeshScreen::drawMesh(INSET_POS(MESH_POS), ExtUI::getMeshArray(),
USE_POINTS | USE_HIGHLIGHT | USE_AUTOSCALE | (gotAllPoints ? USE_COLORS : 0),
autoscale_max_amplitude * levelingProgress
);
}
}
bool BedMeshScreen::onTouchStart(uint8_t tag) {
screen_data.BedMeshScreen.highlightedTag = tag;
return true;
}
bool BedMeshScreen::onTouchEnd(uint8_t tag) {
switch (tag) {
case 1:
GOTO_PREVIOUS();
return true;
default:
return false;
}
}
void BedMeshScreen::onMeshUpdate(const int8_t, const int8_t, const float) {
if (AT_SCREEN(BedMeshScreen))
onRefresh();
}
bool BedMeshScreen::isMeshComplete(ExtUI::bed_mesh_t data) {
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) {
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) {
if (isnan(data[x][y])) {
return false;
}
}
}
return true;
}
void BedMeshScreen::onMeshUpdate(const int8_t x, const int8_t y, const ExtUI::probe_state_t state) {
switch (state) {
case ExtUI::MESH_START:
screen_data.BedMeshScreen.count = 0;
screen_data.BedMeshScreen.message = screen_data.BedMeshScreen.MSG_NONE;
break;
case ExtUI::MESH_FINISH:
if (screen_data.BedMeshScreen.count == GRID_MAX_POINTS && isMeshComplete(ExtUI::getMeshArray())) {
screen_data.BedMeshScreen.message = screen_data.BedMeshScreen.MSG_MESH_COMPLETE;
} else {
screen_data.BedMeshScreen.message = screen_data.BedMeshScreen.MSG_MESH_INCOMPLETE;
}
screen_data.BedMeshScreen.count = GRID_MAX_POINTS;
break;
case ExtUI::PROBE_START:
screen_data.BedMeshScreen.highlightedTag = pointToTag(x, y);
break;
case ExtUI::PROBE_FINISH:
screen_data.BedMeshScreen.count++;
break;
}
BedMeshScreen::onMeshUpdate(x, y, 0);
}
void BedMeshScreen::startMeshProbe() {
GOTO_SCREEN(BedMeshScreen);
screen_data.BedMeshScreen.count = 0;
injectCommands_P(PSTR(BED_LEVELING_COMMANDS));
}
#endif // TOUCH_UI_FTDI_EVE && HAS_MESH
| 36.330508 | 133 | 0.595988 | [
"transform",
"3d"
] |
a1167fdf1ca2d8cd8aaf700d4d3106eea4b81952 | 2,905 | cpp | C++ | Graph/Tree/BST/BST Iterator.cpp | Edith-3000/Algorithmic-Implementations | 7ff8cd615fd453a346b4e851606d47c26f05a084 | [
"MIT"
] | 8 | 2021-02-13T17:07:27.000Z | 2021-08-20T08:20:40.000Z | Graph/Tree/BST/BST Iterator.cpp | Edith-3000/Algorithmic-Implementations | 7ff8cd615fd453a346b4e851606d47c26f05a084 | [
"MIT"
] | null | null | null | Graph/Tree/BST/BST Iterator.cpp | Edith-3000/Algorithmic-Implementations | 7ff8cd615fd453a346b4e851606d47c26f05a084 | [
"MIT"
] | 5 | 2021-02-17T18:12:20.000Z | 2021-10-10T17:49:34.000Z | // Problem: https://www.interviewbit.com/problems/bst-iterator/
// REf: https://www.youtube.com/watch?v=4L5seG1d2dA&list=PL7JyMDSI2BfZugpAjdWc8ES_mYMz2F9Qo&index=6
/****************************************************************************************************/
// In this problem there is just iterative implementation of inorder traversal of the BST.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.1415926535897932384626
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vull> vvull;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0,lim-1);
return uid(rang);
}
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
class TreeNode {
public:
int val;
TreeNode *left;
TreeNode *right;
TreeNode(): val(0), left(NULL), right(NULL) {}
TreeNode(int data): val(data), left(NULL), right(NULL) {}
TreeNode(int data, TreeNode *left, TreeNode *right): val(data), left(left), right(right) {}
};
class BSTIterator {
private:
stack<TreeNode*> stk;
public:
BSTIterator(TreeNode*);
void push_all(TreeNode*);
bool hasNext();
int next();
};
BSTIterator::BSTIterator(TreeNode *root) {
while(!stk.empty()) stk.pop();
push_all(root);
}
void BSTIterator::push_all(TreeNode *root) {
while(root != NULL) {
stk.push(root);
root = root->left;
}
}
bool BSTIterator::hasNext() {
return !stk.empty();
}
int BSTIterator::next() {
TreeNode *tmp = stk.top();
stk.pop();
push_all(tmp->right);
return tmp->val;
}
void solve()
{
TreeNode* root = new TreeNode(2);
root->left = new TreeNode(1);
root->right = new TreeNode(15);
root->right->left = new TreeNode(7);
root->right->right = new TreeNode(26);
root->right->left->left = new TreeNode(5);
root->right->left->right = new TreeNode(10);
root->right->left->right->left = new TreeNode(8);
root->right->left->right->right = new TreeNode(9);
BSTIterator i(root);
while(i.hasNext()) {
cout << i.next() << "\n";
}
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t = 1;
// int test = 1;
// cin >> t;
while(t--) {
// cout << "Case #" << test++ << ": ";
solve();
}
return 0;
} | 24.208333 | 102 | 0.626506 | [
"vector"
] |
a118ba0ba75225b1b49a122ea8b833ffb119c135 | 8,339 | hpp | C++ | src/FGraph/mrob/factor_graph_solve.hpp | miloserdova-l/mrob | 48bef772ba3158d2122991069196d6efd4a39f8c | [
"Apache-2.0"
] | 12 | 2020-09-22T15:33:48.000Z | 2022-03-02T17:27:39.000Z | src/FGraph/mrob/factor_graph_solve.hpp | MobileRoboticsSkoltech/mrob | 7668a3ee35345c4878aa86fff082cc017992d205 | [
"Apache-2.0"
] | 46 | 2020-09-22T15:47:08.000Z | 2022-01-22T10:56:44.000Z | src/FGraph/mrob/factor_graph_solve.hpp | MobileRoboticsSkoltech/mrob | 7668a3ee35345c4878aa86fff082cc017992d205 | [
"Apache-2.0"
] | 9 | 2020-09-22T15:59:33.000Z | 2021-12-20T20:15:16.000Z | /* Copyright (c) 2018, Skolkovo Institute of Science and Technology (Skoltech)
*
* 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.
*
*
* factor_graph_solve.hpp
*
* Created on: Mar 23, 2018
* Author: Gonzalo Ferrer
* g.ferrer@skoltech.ru
* Mobile Robotics Lab, Skoltech
*/
#ifndef SRC_FACTOR_GRAPH_SOLVE_HPP_
#define SRC_FACTOR_GRAPH_SOLVE_HPP_
#include "mrob/factor_graph.hpp"
#include "mrob/time_profiling.hpp"
namespace mrob {
/**
* Class FGraphSolve creates all the required matrices for solving the LSQ problem.
* The problem takes the following form:
*
* x* = argmin {C(x)} = argmin {1/2 sum ||r_i(x,z)||2_W} = argmin 1/2||r||2_W.
*
* last term in vectorized form.
*
* By convention, the residuals r_i are ALWAYS formulated as follows:
* -------------------------------------------
* | r(x) = h(x) - z |
* -------------------------------------------
*
* With this arrangement, the linearized factor substracts the residual (r)
* to the first order term of the nonlinear observation function:
* ||h(x)-z||2_W = ||h(x0) + J dx - z ||2_W = ||J dx + r||2_W
*
* When optimizing the linearized LSQ:
* dC 1 d
* -- = - ---(sum r' W r) = J' W (J dx + r) = 0
* dx 2 dx
*
* => dx = -(J'WJ)^(-1) J'W r
*
* This convention will be followed by all factors in this library, otherwise the optimization
* will not work properly.
*
* Different options are provided:
* - Adjacency matrix (plus indirect construction of Information)
* - TODO Information matrix (direct)
* - TODO Diagonal and information for Schur complement
*
* Routines provide different optimization methods:
* - Gauss-Newton (GN) using Cholesky LDLT with minimum degree ordering
* - Levenberg–Marquardt (LM) (Nocedal Ch.10) using spherical
* trust region alg. (Nocedal 4.1) to estimate a "good" lambda.
* Bertsekas p.105 proposes a similar heuristic approach for the trust
* region, which we convert to lambda estimation (we follow Bertsekas' notation in code).
* - TODO Gradient 1st order based with preconditioning
* - TODO Dogleg (DL) (Nocedal 4.3)
* - TODO Conjugate gradient method (Nocedal 7.2)
*/
class FGraphSolve: public FGraph
{
public:
/**
* This enums all matrix building methods available
*/
enum matrixMethod{ADJ=0, SCHUR};
/**
* This enums optimization methods available:
* - Gauss Newton
* - Levenberg Marquardt (trust-region-like for lambda adjustment) TODO LM elliptical?
*/
enum optimMethod{GN=0, LM};
FGraphSolve(matrixMethod method = ADJ);
virtual ~FGraphSolve();
/**
* Solve call the corresponding routine on the class parameters or
* ultimately on the function input,
* by default optim method is Gauss Newton
*/
void solve(optimMethod method = GN, uint_t maxIters = 20, matData_t lambda = 1e-6, matData_t solutionTolerance = 1e-2);
/**
* Evaluates the current solution chi2.
*
* Variable relinearizeProblemFlag:
* - (default) true: Recalculates residuals.
* - false: Uses the previous calculated residuals
*/
matData_t chi2(bool evaluateResidualsFlag = true);
/**
* Returns a Reference to the solution vector
* of all variables, vectors, matrices, etc.
*/
std::vector<MatX> get_estimated_state();
/**
* Functions to set the matrix method building
*/
void set_build_matrix_method(matrixMethod method) {matrixMethod_ = method;};
matrixMethod get_build_matrix_method() { return matrixMethod_;};
/**
* Returns a copy to the information matrix.
* TODO If true, it re-evaluates the problem
*/
SMatCol get_information_matrix() { return L_;}
/**
* Returns a copy to the information matrix.
* TODO If true, it re-evaluates the problem
*/
SMatCol get_adjacency_matrix() { return A_;}
/**
* Returns a copy to the W matrix.
* TODO If true, it re-evaluates the problem
*/
SMatCol get_W_matrix() { return W_;}
/**
* Returns a copy to the processed residuals in state space b = A'Wr.
* TODO If true, it re-evaluates the problem
*/
MatX1 get_vector_b() { return b_;}
/**
* Returns a vector of chi2 values for each of the factors.
*/
MatX1 get_chi2_array();
protected:
/**
* build problem creates an information matrix L, W and a vector b
*
* It chooses from building the information from the adjacency matrix,
* directly building info or schur (TODO)
*
* If bool useLambda is true, it also stores a vector D2 containing the diagonal
* of the information matrix L
*/
void build_problem(bool useLambda = false);
/**
* This protected method creates an Adjacency matrix, iterating over
* all factors in the FG and creates a block diagonal matrix W with each factors information.
* As a result, residuals, Jacobians and chi2 values are up to date
*
*/
void build_adjacency();
/**
* From the adjacency matrix it creates the information matrix as
* L = A^T * W * A
* The residuals are also calculated as b = A^T * W *r
*/
void build_info_adjacency();
void build_schur(); // TODO
/**
* Once the matrix L is generated, it solves the linearized LSQ
* by using the Gauss-Newton algorithm
*
* Input useLambda (default false) builds the GN problem with lambda factor on the diagonal
* L = A'*A + lambda * I
*/
void optimize_gauss_newton(bool useLambda = false);
/**
* It generates the information matrix as
* L' = L + lambda * I
*
* TODO, the preconditioning could be adapted to expected values, such as w < pi and v < avg
* L' = L + lambda * D2
*
* Iteratively updates the solution given the right estimation of lambda
* Parameters are necessary to be specified in advance, o.w. it would use default values.
*
* input maxIters, before returning a result
*
* output: number of iterations it took to converge.
* 0 when incorrect solution
*/
uint_t optimize_levenberg_marquardt(uint_t maxIters);
/**
* Function that updates all nodes with the current solution,
* this must be called after solving the problem
*/
void update_nodes();
/**
* Synchronize state variable in all nodes
* exactly value the current state.
*
* Usually this function un-does an incorrect update of the state.
*/
void synchronize_nodes_state();
/**
* Synchronize auxiliary state variables in all nodes
* exactly value the current state.
* This function is used when we will update a solution
* but it needs verification, so we book-keep at auxiliary.
*/
void synchronize_nodes_auxiliary_state();
// Variables for solving the FGraph
matrixMethod matrixMethod_;
uint_t N_; // total number of state variables
uint_t M_; // total number of observation variables
SMatRow A_; //Adjacency matrix, as a Row sparse matrix
SMatRow W_; //A block diagonal information matrix. For types Adjacency it calculates its block transposed squared root
MatX1 r_; // Residuals as given by the factors
SMatCol L_; //Information matrix
MatX1 b_; // Post-processed residuals, A'*W*r
// Correction deltas
MatX1 dx_;
// Particular parameters for Levenberg-Marquard
matData_t lambda_; // current value of lambda
matData_t solutionTolerance_;
MatX1 diagL_; //diagonal matrix (vector) of L to update it efficiently
// time profiling
TimeProfiling time_profiles_;
};
}
#endif /* SRC_FACTOR_GRAPH_SOLVE_HPP_ */
| 33.625 | 123 | 0.651637 | [
"vector"
] |
a11b78bb1c22e549a563df67e564a4ff0ec97316 | 3,635 | cpp | C++ | src/crypter.cpp | 2a5A1Ghu1/DigitalNote-2 | f129cdab4b19dcd98945cfe199c49e5f72f91b8c | [
"MIT"
] | 10 | 2019-06-06T04:08:38.000Z | 2022-01-07T13:02:17.000Z | src/crypter.cpp | 2a5A1Ghu1/DigitalNote-2 | f129cdab4b19dcd98945cfe199c49e5f72f91b8c | [
"MIT"
] | 21 | 2019-07-19T18:36:34.000Z | 2022-03-06T09:59:51.000Z | src/crypter.cpp | 2a5A1Ghu1/DigitalNote-2 | f129cdab4b19dcd98945cfe199c49e5f72f91b8c | [
"MIT"
] | 24 | 2019-04-19T12:24:16.000Z | 2022-01-07T13:02:20.000Z | // Copyright (c) 2009-2012 The Bitcoin Developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "compat.h"
#include <openssl/aes.h>
#include <openssl/evp.h>
#include "util.h"
#include "ccrypter.h"
#include "crypter.h"
bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256& nIV, std::vector<unsigned char> &vchCiphertext)
{
CCrypter cKeyCrypter;
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE);
memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE);
if(!cKeyCrypter.SetKey(vMasterKey, chIV))
return false;
return cKeyCrypter.Encrypt(*((const CKeyingMaterial*)&vchPlaintext), vchCiphertext);
}
bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCiphertext, const uint256& nIV, CKeyingMaterial& vchPlaintext)
{
CCrypter cKeyCrypter;
std::vector<unsigned char> chIV(WALLET_CRYPTO_KEY_SIZE);
memcpy(&chIV[0], &nIV, WALLET_CRYPTO_KEY_SIZE);
if(!cKeyCrypter.SetKey(vMasterKey, chIV))
return false;
return cKeyCrypter.Decrypt(vchCiphertext, *((CKeyingMaterial*)&vchPlaintext));
}
// General secure AES 256 CBC encryption routine
bool EncryptAES256(const SecureString& sKey, const SecureString& sPlaintext, const std::string& sIV, std::string& sCiphertext)
{
// max ciphertext len for a n bytes of plaintext is
// n + AES_BLOCK_SIZE - 1 bytes
int nLen = sPlaintext.size();
int nCLen = nLen + AES_BLOCK_SIZE;
int nFLen = 0;
// Verify key sizes
if(sKey.size() != 32 || sIV.size() != AES_BLOCK_SIZE) {
LogPrintf("crypter EncryptAES256 - Invalid key or block size: Key: %d sIV:%d\n", sKey.size(), sIV.size());
return false;
}
// Prepare output buffer
sCiphertext.resize(nCLen);
// Perform the encryption
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
bool fOk = true;
EVP_CIPHER_CTX_init(ctx);
if (fOk) fOk = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, (const unsigned char*) &sKey[0], (const unsigned char*) &sIV[0]);
if (fOk) fOk = EVP_EncryptUpdate(ctx, (unsigned char*) &sCiphertext[0], &nCLen, (const unsigned char*) &sPlaintext[0], nLen);
if (fOk) fOk = EVP_EncryptFinal_ex(ctx, (unsigned char*) (&sCiphertext[0])+nCLen, &nFLen);
EVP_CIPHER_CTX_cleanup(ctx);
EVP_CIPHER_CTX_free(ctx);
if (!fOk) return false;
sCiphertext.resize(nCLen + nFLen);
return true;
}
bool DecryptAES256(const SecureString& sKey, const std::string& sCiphertext, const std::string& sIV, SecureString& sPlaintext)
{
// plaintext will always be equal to or lesser than length of ciphertext
int nLen = sCiphertext.size();
int nPLen = nLen, nFLen = 0;
// Verify key sizes
if(sKey.size() != 32 || sIV.size() != AES_BLOCK_SIZE) {
LogPrintf("crypter DecryptAES256 - Invalid key or block size\n");
return false;
}
sPlaintext.resize(nPLen);
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
bool fOk = true;
EVP_CIPHER_CTX_init(ctx);
if (fOk) fOk = EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, (const unsigned char*) &sKey[0], (const unsigned char*) &sIV[0]);
if (fOk) fOk = EVP_DecryptUpdate(ctx, (unsigned char *) &sPlaintext[0], &nPLen, (const unsigned char *) &sCiphertext[0], nLen);
if (fOk) fOk = EVP_DecryptFinal_ex(ctx, (unsigned char *) (&sPlaintext[0])+nPLen, &nFLen);
EVP_CIPHER_CTX_cleanup(ctx);
EVP_CIPHER_CTX_free(ctx);
if (!fOk) return false;
sPlaintext.resize(nPLen + nFLen);
return true;
}
| 34.951923 | 153 | 0.694911 | [
"vector"
] |
a125d1642037b0c7a6374d7cabf42248dfe56e07 | 4,989 | hh | C++ | surfaces/ConeAligned.t.hh | celeritas-project/orange-port | 9aa2d36984a24a02ed6d14688a889d4266f7b1af | [
"Apache-2.0",
"MIT"
] | null | null | null | surfaces/ConeAligned.t.hh | celeritas-project/orange-port | 9aa2d36984a24a02ed6d14688a889d4266f7b1af | [
"Apache-2.0",
"MIT"
] | null | null | null | surfaces/ConeAligned.t.hh | celeritas-project/orange-port | 9aa2d36984a24a02ed6d14688a889d4266f7b1af | [
"Apache-2.0",
"MIT"
] | null | null | null | //---------------------------------*-C++-*-----------------------------------//
/*!
* \file surfaces/ConeAligned.t.hh
* \brief ConeAligned template method definitions
* \note Copyright (c) 2020 Oak Ridge National Laboratory, UT-Battelle, LLC.
*/
//---------------------------------------------------------------------------//
#pragma once
#include "ConeAligned.hh"
#include <iostream>
#include <cmath>
#include "base/FixedViewArray.hh"
#include "orange/Transform.hh"
#include "orange/BoundingBox.hh"
#include "orange/Fuzziness.hh"
#include "GeneralQuadric.hh"
#include "SimpleQuadric.hh"
namespace celeritas
{
//---------------------------------------------------------------------------//
// STATIC METHODS
//---------------------------------------------------------------------------//
/*!
* Whether the given quadric can be simplified to this shape
*
* A cone has a negative second-moment along this axis, no cross terms, and
* equal non-axis second moments.
*
* This implementation requires that the second-order terms be scaled to 1.
*/
template<Axis T>
bool ConeAligned<T>::can_simplify(const SimpleQuadric& gq)
{
const real_type tol = fuzziness().surface_simplification_abs();
auto second = gq.second();
return second[t_index()] < 0 && std::fabs(second[u_index()] - 1.0) < tol
&& std::fabs(second[v_index()] - 1.0) < tol;
}
//---------------------------------------------------------------------------//
// METHODS
//---------------------------------------------------------------------------//
/*!
* User-accessible construction
*/
template<Axis T>
ConeAligned<T>::ConeAligned(const Real3& origin, real_type tangent)
: origin_(make_vector(origin)), tsq_ipow<2>(tangent)
{
CELER_VALIDATE(tangent >= 0,
<< "Cone tangent must be nonnegative, but it is "
<< tangent);
}
//---------------------------------------------------------------------------//
/*!
* \brief Construct from a degenerate SQ
*/
template<Axis T>
ConeAligned<T>::ConeAligned(const SimpleQuadric& sq)
{
CELER_EXPECT(can_simplify(sq));
// Calculate t^2 from the second-order term
tsq_ = -sq.second()[t_index()];
// Calc origin from first-order coefficients
origin_[t_index()] = sq.first()[t_index()] / (2 * tsq_);
origin_[u_index()] = sq.first()[u_index()] * (-half);
origin_[v_index()] = sq.first()[v_index()] * (-half);
CELER_ENSURE(soft_equiv(-tsq_ * origin_[t_index()] * origin_[t_index()]
+ (origin_[u_index()] * origin_[u_index()])
+ (origin_[v_index()] * origin_[v_index()]),
sq.zeroth(),
1.e-6));
}
//---------------------------------------------------------------------------//
/*!
* Return a new cone translated by some vector
*/
template<Axis T>
ConeAligned<T> ConeAligned<T>::translated(const Transform& t) const
{
CELER_EXPECT(!t.has_rotation());
// Create a copy
ConeAligned<T> result(*this);
// Update origin
result.origin_ += t.translation();
return result;
}
//---------------------------------------------------------------------------//
/*!
* Return a cone transformed by a rotate/translate
*
* A cone parallel to the X axis is represented as a general quadric:
* \f[
(-t^2) x^2 + y^2 + z^2 + (2t^2 x_0) x + (-2y_0) y + (-2z_0) z
+ (-t^2 x_0^2 + y_0^2 + z_0^2) = 0
\f]
*/
template<Axis T>
GeneralQuadric ConeAligned<T>::transformed(const Transform& t) const
{
CELER_EXPECT(t.has_rotation());
// First, second, and zeroth coefficients
Real3 second;
Real3 first;
real_type zeroth;
second[t_index()] = -tsq_;
second[u_index()] = 1;
second[v_index()] = 1;
first[t_index()] = 2 * tsq_ * origin_[t_index()];
first[u_index()] = -2 * origin_[u_index()];
first[v_index()] = -2 * origin_[v_index()];
zeroth = -tsq_ * origin_[t_index()] * origin_[t_index()]
+ (origin_[u_index()] * origin_[u_index()])
+ (origin_[v_index()] * origin_[v_index()]);
return GeneralQuadric(make_fixed_view(second),
{0, 0, 0},
make_fixed_view(first),
zeroth)
.transformed(t);
}
//---------------------------------------------------------------------------//
/*!
* Clip a bounding box to this surface
*/
template<Axis T>
void ConeAligned<T>::clip(Sense, BoundingBox&) const
{
}
//---------------------------------------------------------------------------//
/*!
* \brief Output a very short description of this sufrace
*/
template<Axis T>
std::ostream& operator<<(std::ostream& os, const ConeAligned<T>& s)
{
os << "Cone " << to_cstring(T) << ": tangent=" << std::sqrt(s.tangent_sq())
<< " at " << s.origin();
return os;
}
//---------------------------------------------------------------------------//
} // namespace celeritas
| 30.607362 | 79 | 0.491882 | [
"shape",
"vector",
"transform"
] |
a1288a8c85c5578827886773865e963d862edf69 | 1,508 | cpp | C++ | samples/cpp/tutorial_code/features2D/SURF_detector.cpp | sagarjoglekar/opencv | de4ee084b1958e859e5a2c74b6867310bb2e4940 | [
"BSD-3-Clause"
] | 3 | 2018-10-15T07:31:30.000Z | 2020-10-16T08:59:46.000Z | samples/cpp/tutorial_code/features2D/SURF_detector.cpp | ehren/opencv | abe37659ccfc2b399e7543eee1a43900c9a7099e | [
"BSD-3-Clause"
] | null | null | null | samples/cpp/tutorial_code/features2D/SURF_detector.cpp | ehren/opencv | abe37659ccfc2b399e7543eee1a43900c9a7099e | [
"BSD-3-Clause"
] | 2 | 2016-12-02T02:57:34.000Z | 2020-01-09T11:03:24.000Z | /**
* @file SURF_detector
* @brief SURF keypoint detection + keypoint drawing with OpenCV functions
* @author A. Huaman
*/
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/features2d.hpp"
using namespace cv;
void readme();
/**
* @function main
* @brief Main function
*/
int main( int argc, char** argv )
{
if( argc != 3 )
{ readme(); return -1; }
Mat img_1 = imread( argv[1], IMREAD_GRAYSCALE );
Mat img_2 = imread( argv[2], IMREAD_GRAYSCALE );
if( !img_1.data || !img_2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );
//-- Draw keypoints
Mat img_keypoints_1; Mat img_keypoints_2;
drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
//-- Show detected (drawn) keypoints
imshow("Keypoints 1", img_keypoints_1 );
imshow("Keypoints 2", img_keypoints_2 );
waitKey(0);
return 0;
}
/**
* @function readme
*/
void readme()
{ std::cout << " Usage: ./SURF_detector <img1> <img2>" << std::endl; }
| 23.936508 | 99 | 0.685013 | [
"vector"
] |
a12a95ef24bc63d7f1e1d1eedb88ad61f025d3c4 | 4,170 | cpp | C++ | examples_oldgl_glfw/124_4RotSymField/main.cpp | mmer547/delfem2 | 4f4b28931c96467ac30948e6b3f83150ea530c92 | [
"MIT"
] | 1 | 2020-07-18T17:03:36.000Z | 2020-07-18T17:03:36.000Z | examples_oldgl_glfw/124_4RotSymField/main.cpp | mmer547/delfem2 | 4f4b28931c96467ac30948e6b3f83150ea530c92 | [
"MIT"
] | null | null | null | examples_oldgl_glfw/124_4RotSymField/main.cpp | mmer547/delfem2 | 4f4b28931c96467ac30948e6b3f83150ea530c92 | [
"MIT"
] | null | null | null | /*
* Copyright (c) 2019 Nobuyuki Umetani
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @brief implementation of 4 rotatoinal symetry field
* @details implementation is based on "Wenzel Jakob, Marco Tarini, Daniele Panozzo, and Olga Sorkine-Hornung. Instant field-aligned meshes. Siggraph Asia 2015"
*/
#include <cstdlib>
#include <filesystem>
#if defined(_WIN32) // windows
# define NOMINMAX // to remove min,max macro
# include <windows.h> // this should come before glfw3.h
#endif
#define GL_SILENCE_DEPRECATION
#include <GLFW/glfw3.h>
#include "delfem2/msh_io_ply.h"
#include "delfem2/mshmisc.h"
#include "delfem2/points.h"
#include "delfem2/mshuni.h"
#include "delfem2/vec3.h"
#include "delfem2/4rotsym.h"
#include "delfem2/glfw/viewer3.h"
#include "delfem2/glfw/util.h"
#include "delfem2/opengl/old/funcs.h"
#include "delfem2/opengl/old/mshuni.h"
#include "delfem2/opengl/old/v3q.h"
namespace dfm2 = delfem2;
// ------------------------------------------------
// TODO: Add random permutation version in the demo
int main() {
std::vector<double> vtx_xyz;
std::vector<unsigned int> tri_vtx;
delfem2::Read_Ply(
vtx_xyz, tri_vtx,
std::filesystem::path(PATH_INPUT_DIR) / "bunny_1k.ply");
delfem2::Normalize_Points3(vtx_xyz);
std::vector<double> vtx_normal(vtx_xyz.size());
dfm2::Normal_MeshTri3D(
vtx_normal.data(),
vtx_xyz.data(), vtx_xyz.size() / 3,
tri_vtx.data(), tri_vtx.size() / 3);
std::vector<double> aOdir;
{
const double minCoords[3] = {-1., -1., -1.};
const double maxCoords[3] = {+1., +1., +1.};
aOdir.resize(vtx_xyz.size());
dfm2::Points_RandomUniform(aOdir.data(),
vtx_xyz.size() / 3, 3,
minCoords, maxCoords);
dfm2::TangentVector_Points3(aOdir,
vtx_normal);
}
std::vector<unsigned int> psup_ind, psup;
dfm2::JArray_PSuP_MeshElem(
psup_ind, psup,
tri_vtx.data(), tri_vtx.size() / 3, 3,
vtx_xyz.size() / 3);
// ------------------
delfem2::glfw::CViewer3 viewer;
delfem2::glfw::InitGLOld();
viewer.OpenWindow();
dfm2::opengl::setSomeLighting();
unsigned int iframe = 0;
while (true) {
if (iframe == 0) {
const double minCoords[3] = {-1., -1., -1.};
const double maxCoords[3] = {+1., +1., +1.};
aOdir.resize(vtx_xyz.size());
dfm2::Points_RandomUniform(
aOdir.data(),
vtx_xyz.size() / 3, 3,
minCoords, maxCoords);
dfm2::TangentVector_Points3(aOdir, vtx_normal);
}
if (iframe > 30) {
dfm2::Smooth4RotSym(aOdir,
vtx_normal, psup_ind, psup);
}
// --------------------
viewer.DrawBegin_oldGL();
::glEnable(GL_LIGHTING);
dfm2::opengl::DrawMeshTri3D_FaceNorm(
vtx_xyz.data(),
tri_vtx.data(), tri_vtx.size() / 3);
{
::glDisable(GL_LIGHTING);
double len = 0.03;
::glLineWidth(3);
const size_t np = vtx_xyz.size() / 3;
for (unsigned int ip = 0; ip < np; ++ip) {
const dfm2::CVec3d p = dfm2::CVec3d(vtx_xyz.data() + ip * 3);
const dfm2::CVec3d n = dfm2::CVec3d(vtx_normal.data() + ip * 3).normalized();
const dfm2::CVec3d o = dfm2::CVec3d(aOdir.data() + ip * 3).normalized();
const dfm2::CVec3d q = dfm2::Cross(n, o);
::glBegin(GL_LINES);
::glColor3d(0, 0, 0);
dfm2::opengl::myGlVertex(p);
dfm2::opengl::myGlVertex(p + len * n);
::glColor3d(0, 0, 1);
dfm2::opengl::myGlVertex(p - len * o);
dfm2::opengl::myGlVertex(p);
::glColor3d(1, 0, 0);
dfm2::opengl::myGlVertex(p);
dfm2::opengl::myGlVertex(p + len * o);
dfm2::opengl::myGlVertex(p - len * q);
dfm2::opengl::myGlVertex(p + len * q);
::glEnd();
}
}
iframe = (iframe + 1) % 100;
glfwSwapBuffers(viewer.window);
glfwPollEvents();
if (glfwWindowShouldClose(viewer.window)) { goto EXIT; }
}
EXIT:
glfwDestroyWindow(viewer.window);
glfwTerminate();
exit(EXIT_SUCCESS);
}
| 31.590909 | 160 | 0.598082 | [
"vector"
] |
a12cf9f923894e53d61d9f113d568a144a4c7d7d | 2,748 | hpp | C++ | src/Rendering/OpenGL/libraries/gl/include/gl/state.hpp | Megaxela/HGEngineReloaded | 62d319308c2d8a62f6854721c31afc4981aa13df | [
"MIT"
] | 2 | 2021-02-26T05:25:48.000Z | 2021-09-16T22:30:41.000Z | src/Rendering/OpenGL/libraries/gl/include/gl/state.hpp | Megaxela/HGEngineReloaded | 62d319308c2d8a62f6854721c31afc4981aa13df | [
"MIT"
] | 1 | 2019-10-19T10:36:43.000Z | 2019-10-19T10:36:43.000Z | src/Rendering/OpenGL/libraries/gl/include/gl/state.hpp | Megaxela/HGEngineReloaded | 62d319308c2d8a62f6854721c31afc4981aa13df | [
"MIT"
] | 2 | 2019-10-22T18:56:59.000Z | 2020-03-12T04:38:31.000Z | // Copyright Ali Can Demiralp 2016 - 2017.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef GL_STATE_HPP_
#define GL_STATE_HPP_
#include <string>
#include <vector>
#include <gl/export.hpp>
#include <gl/opengl.hpp>
namespace gl
{
// 8.4.1 Pixel storage modes.
GL_EXPORT void set_pack_swap_bytes (bool value = false);
GL_EXPORT void set_pack_lsb_first (bool value = false);
GL_EXPORT void set_pack_row_length (GLint value = 0);
GL_EXPORT void set_pack_image_height (GLint value = 0);
GL_EXPORT void set_pack_skip_images (GLint value = 0);
GL_EXPORT void set_pack_skip_pixels (GLint value = 0);
GL_EXPORT void set_pack_skip_rows (GLint value = 0);
GL_EXPORT void set_pack_alignment (GLint value = 4);
GL_EXPORT void set_pack_compressed_block_width (GLint value = 0);
GL_EXPORT void set_pack_compressed_block_height (GLint value = 0);
GL_EXPORT void set_pack_compressed_block_depth (GLint value = 0);
GL_EXPORT void set_pack_compressed_block_size (GLint value = 0);
GL_EXPORT void set_unpack_swap_bytes (bool value = false);
GL_EXPORT void set_unpack_lsb_first (bool value = false);
GL_EXPORT void set_unpack_row_length (GLint value = 0);
GL_EXPORT void set_unpack_image_height (GLint value = 0);
GL_EXPORT void set_unpack_skip_images (GLint value = 0);
GL_EXPORT void set_unpack_skip_pixels (GLint value = 0);
GL_EXPORT void set_unpack_skip_rows (GLint value = 0);
GL_EXPORT void set_unpack_alignment (GLint value = 4);
GL_EXPORT void set_unpack_compressed_block_width (GLint value = 0);
GL_EXPORT void set_unpack_compressed_block_height (GLint value = 0);
GL_EXPORT void set_unpack_compressed_block_depth (GLint value = 0);
GL_EXPORT void set_unpack_compressed_block_size (GLint value = 0);
// 21.5 Hints.
GL_EXPORT void set_fragment_shader_derivative_hint(GLenum hint = GL_NICEST);
GL_EXPORT void set_texture_compression_hint (GLenum hint = GL_NICEST);
GL_EXPORT void set_line_smooth_hint (GLenum hint = GL_NICEST);
GL_EXPORT void set_polygon_smooth_hint (GLenum hint = GL_NICEST);
// 22.2 String queries.
GL_EXPORT std::string renderer();
GL_EXPORT std::string vendor ();
GL_EXPORT std::string version ();
GL_EXPORT std::vector<std::string> extensions ();
GL_EXPORT std::vector<std::string> shading_language_versions();
GL_EXPORT std::vector<std::string> spir_v_extensions ();
}
#endif | 46.576271 | 76 | 0.697598 | [
"vector"
] |
a13034d9c5d7a3e6f3a4dd51f9991e374e9107ee | 22,879 | cpp | C++ | plugins/radar-android-audio/src/main/jni/opensmile-2.3.0/src/core/dataSelector.cpp | RADAR-base/radar-commons-android | 60234bd449f73c1f4c91a81ffb05f46219a65f0c | [
"Apache-2.0"
] | 1 | 2020-10-08T13:18:51.000Z | 2020-10-08T13:18:51.000Z | plugins/radar-android-audio/src/main/jni/opensmile-2.3.0/src/core/dataSelector.cpp | RADAR-base/radar-commons-android | 60234bd449f73c1f4c91a81ffb05f46219a65f0c | [
"Apache-2.0"
] | 206 | 2018-02-19T15:35:57.000Z | 2022-03-25T11:27:38.000Z | plugins/radar-android-audio/src/main/jni/opensmile-2.3.0/src/core/dataSelector.cpp | RADAR-base/radar-commons-android | 60234bd449f73c1f4c91a81ffb05f46219a65f0c | [
"Apache-2.0"
] | 2 | 2018-08-22T14:47:35.000Z | 2020-04-07T08:38:34.000Z | /*F***************************************************************************
*
* openSMILE - the Munich open source Multimedia Interpretation by
* Large-scale Extraction toolkit
*
* This file is part of openSMILE.
*
* openSMILE is copyright (c) by audEERING GmbH. All rights reserved.
*
* See file "COPYING" for details on usage rights and licensing terms.
* By using, copying, editing, compiling, modifying, reading, etc. this
* file, you agree to the licensing terms in the file COPYING.
* If you do not agree to the licensing terms,
* you must immediately destroy all copies of this file.
*
* THIS SOFTWARE COMES "AS IS", WITH NO WARRANTIES. THIS MEANS NO EXPRESS,
* IMPLIED OR STATUTORY WARRANTY, INCLUDING WITHOUT LIMITATION, WARRANTIES OF
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ANY WARRANTY AGAINST
* INTERFERENCE WITH YOUR ENJOYMENT OF THE SOFTWARE OR ANY WARRANTY OF TITLE
* OR NON-INFRINGEMENT. THERE IS NO WARRANTY THAT THIS SOFTWARE WILL FULFILL
* ANY OF YOUR PARTICULAR PURPOSES OR NEEDS. ALSO, YOU MUST PASS THIS
* DISCLAIMER ON WHENEVER YOU DISTRIBUTE THE SOFTWARE OR DERIVATIVE WORKS.
* NEITHER TUM NOR ANY CONTRIBUTOR TO THE SOFTWARE WILL BE LIABLE FOR ANY
* DAMAGES RELATED TO THE SOFTWARE OR THIS LICENSE AGREEMENT, INCLUDING
* DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL OR INCIDENTAL DAMAGES, TO THE
* MAXIMUM EXTENT THE LAW PERMITS, NO MATTER WHAT LEGAL THEORY IT IS BASED ON.
* ALSO, YOU MUST PASS THIS LIMITATION OF LIABILITY ON WHENEVER YOU DISTRIBUTE
* THE SOFTWARE OR DERIVATIVE WORKS.
*
* Main authors: Florian Eyben, Felix Weninger,
* Martin Woellmer, Bjoern Schuller
*
* Copyright (c) 2008-2013,
* Institute for Human-Machine Communication,
* Technische Universitaet Muenchen, Germany
*
* Copyright (c) 2013-2015,
* audEERING UG (haftungsbeschraenkt),
* Gilching, Germany
*
* Copyright (c) 2016,
* audEERING GmbH,
* Gilching Germany
***************************************************************************E*/
/* openSMILE component:
selects data elements by element name
*/
#include <core/dataSelector.hpp>
#define MODULE "cDataSelector"
#define MAX_LINE_LENGTH 2048
SMILECOMPONENT_STATICS(cDataSelector)
SMILECOMPONENT_REGCOMP(cDataSelector)
{
SMILECOMPONENT_REGCOMP_INIT
scname = COMPONENT_NAME_CDATASELECTOR;
sdescription = COMPONENT_DESCRIPTION_CDATASELECTOR;
// we inherit cDataProcessor configType and extend it:
SMILECOMPONENT_INHERIT_CONFIGTYPE("cDataProcessor")
SMILECOMPONENT_IFNOTREGAGAIN(
ct->setField("selFile","The name of the data selection file to load. The file is a text file containing one element name per line of the elements which should be selected (case-sensitive!). (Note: the first two lines make up a header; the first line always contains 'str', the second line is number of features in list, next each line contains one feature name of the features to select)",(const char*)NULL);
ct->setField("selected","This is an alternative to loading 'selFile'. An array of exact (case-sensitive) names of features / data elements to select.",(const char *)NULL, ARRAY_TYPE);
ct->setField("selectedRange","This is an alternative to loading 'selFile'. It specifies the selected elements(!) by element index ranges. Each array element contains one range in the format of <start>-<end>, where <start> and <end> are the indicies of the startt and end features to *select* in this range. '$' specifies the last element, and '1' indicates the first element. If the '-' is missing, only a single element will be selected, not a range. NOTE: the 'newNames' option does not work in conjunction with this element selection method!",(const char*)NULL,ARRAY_TYPE);
ct->setField("newNames","An array of new names to assign to the selected features / data elements (optional). The order thereby corresponds to the order of data element names in the input.",(const char *)NULL, ARRAY_TYPE);
ct->setField("elementMode","1 = select elements exactly as given in 'selected' array or in 'selFile' (in this case, only full element names are allowed (i.e. mfcc[1], mfcc[2] instead of mfcc, mfcc[], or mfcc[1-2]\n 0 = automatically copy arrays or partial arrays, e.g. if field[1-4] or only 'field' is given as name in the selction array/file, then the partial (1-4) or complete field will be copied to the output",1);
ct->setField("dummyMode","1 = don't set up output level names. Use this option temporarily, to get a working set-up where you can read the input level names, to set up your selection list.",0);
ct->setField("outputSingleField", "If this is set to a string, the output will be a single field (with the name set by this string) for all the elements in the input.", (const char *)NULL);
)
SMILECOMPONENT_MAKEINFO(cDataSelector);
}
SMILECOMPONENT_CREATE(cDataSelector)
//-----
cDataSelector::cDataSelector(const char *_name) :
cDataProcessor(_name),
selFile(NULL),
names(NULL),
mapping(NULL),
elementMode(0),
selectionIsRange(0),
idxSelected(NULL),
vecO(NULL), outputSingleField(NULL)
{
}
int cDataSelector::loadSelection()
{
if (selFile != NULL) {
if (strlen(selFile)<1) return 0;
FILE *f = fopen(selFile,"r");
if (f== NULL) {
SMILE_IERR(2,"error opening feature selection file '%s' for reading! NOT using a feature selection!",selFile);
return 0;
}
// read first line to determine filetype:
char line[MAX_LINE_LENGTH+1];
long nStr=0;
fgets( line, 5, f);
line[3] = 0;
if (!strcmp(line,"str")) { // string list
fselType = 2;
SMILE_IDBG(5,"reading string list of features");
fscanf( f, "%lu\n", &nStr);
if (nStr < 1) { COMP_ERR("Error reading feature selection file, nFeatures < 1!"); }
nSel = nStr;
names = (char**)calloc(1,sizeof(char*) * nSel);
int i=0; line[0] = 0;
while(fgets(line,MAX_LINE_LENGTH,f) != NULL) {
if (strlen( line ) > 1) {
if (i<nStr) {
line[strlen( line ) - 1] = 0;
names[i++] = strdup(line);
} else {
SMILE_IERR(1,"excess line in feature selection file '%s' : '%s' (expected only %i lines with features)",selFile,line,nStr);
}
}
}
if (nSel > i) {
SMILE_IWRN(1,"less feature names (only %i) in feature selection file '%s' than specified in the header (%i).",i,selFile,nSel);
nSel = i;
}
/*
while(fgets(line,MAX_LINE_LENGTH,f) != NULL) {
if (strlen( line ) > 1) {
line[strlen( line ) - 1] = 0;
names[i++] = strdup(line);
}
}*/
SMILE_IDBG(5,"selected %i features",i);
fclose(f);
return 1;
} else if (!strcmp(line,"idx")) { // index list
fclose(f);
SMILE_IERR(1,"feature index list not yet supported in dataSelector.");
COMP_ERR("Aborting.");
/*
fselType = 1;
SMILE_IDBG(5,"reading index list of features");
long idx=0; int i;
// pass1: parse for max index
while(fscanf(f,"%u\n",&idx) == 1)
outputSelIdx.nFull = MAX(outputSelIdx.nFull, idx);
SMILE_IDBG(5,"max index in selection file was found to be %i",outputSelIdx.nFull);
outputSelIdx.nFull++;
outputSelIdx.enabled = (long *)calloc(1,sizeof(long)*outputSelIdx.nFull);
rewind( f );
fgets(line, 5, f); // skip header line;
// pass2: parse for max index
i=0;
while(fscanf(f,"%u\n",&idx) == 1) {
outputSelIdx.enabled[idx] = 1; // enable feature "idx"
i++;
}
outputSelIdx.nSel = i;
Nsel = i;
SMILE_IDBG(5,"enabled %i features",i);
fclose(f);
return 1;
*/
} else { // bogus file...
//TODO: read raw list of names??
fclose( f );
COMP_ERR("error parsing fselection file '%s'. bogus header! expected 'str' or 'idx' at beginning. found '%s'.",selFile,line);
}
}
return 0;
}
void cDataSelector::fetchConfig()
{
cDataProcessor::fetchConfig();
dummyMode = getInt("dummyMode");
outputSingleField = getStr("outputSingleField");
selFile = getStr("selFile");
if (selFile == NULL) {
// load names of selected features:
nSel = getArraySize("selected");
if (nSel>0) {
names = (char**)calloc(1,sizeof(char*) * nSel);
int i;
for (i=0; i<nSel; i++) {
names[i] = (char *)getStr_f(myvprint("selected[%i]",i));
if (names[i] == NULL) {
SMILE_IERR(1, "The %i-th element of the 'selected' names list in the config is empty or invalid. Please fix your config (check for double ; !).", i + 1);
COMP_ERR("aborting");
}
SMILE_IDBG(2,"selected: '%s'",names[i]);
}
} else {
// get feature selection by index ranges:
nSel = getArraySize("selectedRange");
if (nSel > 0) {
names = (char**)calloc(1,sizeof(char*) * nSel);
int i;
for (i=0; i<nSel; i++) {
names[i] = (char *)getStr_f(myvprint("selectedRange[%i]",i));
SMILE_IDBG(2,"selectedRange: '%s'",names[i]);
}
selectionIsRange = 1;
} else {
SMILE_IERR(1,"no features selected, this does not make sense!");
COMP_ERR("stopping here");
}
}
if (selectionIsRange) { elementMode = 1; }
else {
elementMode = getInt("elementMode");
if (elementMode) { SMILE_IDBG(2,"exact element name matching enabled"); }
}
} else {
SMILE_IDBG(2,"exact element name matching enabled");
SMILE_IDBG(2,"loading feature selection from file '%s' (this forces elementMode=1 !).",selFile);
elementMode = 1;
loadSelection();
}
}
/*
int cDataSelector::myConfigureInstance()
{
int ret=1;
// if you would like to change the write level parameters... do so HERE:
//
// .. or override configureWriter() to do so, after the reader config is available!
//
ret *= cDataProcessor::myConfigureInstance();
return ret;
}
*/
/*
int cDataSelector::configureWriter(const sDmLevelConfig *c)
{
// we must return 1, in order to indicate configure success (0 indicates failure)
return 1;
}
*/
// TODO!!!!!!!!!! -> setupNewNames instead of finaliseInstance
// field selection -> fields (arrays) will be added as arrays in output
// element selection -> every output field will be one element
// how to choose the mode??
// --> a) if array index is given -> element selection
// --> b) if no array index for an array is given (field selection, select full field)
// --> c) if array index contains "-", assume range -> field selection (partial)
int cDataSelector::setupNewNames(long nEl)
{
if (dummyMode) {
addNameAppendField(NULL,"dummy");
namesAreSet_=1;
return 1;
}
// match our list of selected names to the list of names obtained from the reader
long i,j,n;
if (elementMode) {
long _N = reader_->getLevelN();
nElSel = 0;
if (selectionIsRange) {
idxSelected = (long *)calloc(1,sizeof(long)*_N);
for (i=0; i<nSel; i++) {
long start, end;
char * sep = strchr(names[i],'-');
char *eptr=NULL;
if (sep != NULL) { //range
*sep = 0;
start = strtol(names[i],&eptr,10); if (eptr == names[i]) { SMILE_IERR(1,"parse error in config option 'selectedRange[%i]' : '%s' ! Expected a range <start>-<end>! Negative numbers are not allowed!",i,names[i]); }
if (*(sep+1) == '$') {
end = _N-1;
} else {
end = strtol(sep+1,&eptr,10); if (eptr == sep+1) { SMILE_IERR(1,"parse error in config option 'selectedRange[%i]' : '%s' ! Expected a range <start>-<end>! Negative numbers are not allowed!",i,names[i]); }
}
} else { // single number
start = strtol(names[i],&eptr,10); if (eptr == names[i]) { SMILE_IERR(1,"parse error in config option 'selectedRange[%i]' : '%s' ! Expected a single integer number (or a range with '-')! Negative numbers are not allowed!",i,names[i]); }
end = start;
}
if (start > end) {
SMILE_IERR(1,"start element index (%i) cannot be greater than end elemet index (%i) ! Setting start = %i",start,end,end);
start = end;
}
if (end>=_N) {
SMILE_IERR(1,"end element index (%i) out of range! Must be < %i. Setting end = %i",end,_N,_N-1);
end = _N-1;
}
nElSel += end-start+1;
for (j=start; j<=end; j++) {
idxSelected[j] = 1;
}
}
for (i=0; i<_N; i++) {
if (idxSelected[i]) {
char * nnn = reader_->getElementName(i);
if (nnn!=NULL) {
SMILE_IMSG(3,"selected element %i, name '%s'\n",i,nnn);
writer_->addField(nnn,1);
free(nnn);
}
// TODO: check for full array fields in range and add them as original array fields...??
}
}
} else {
mapping = (sDataSelectorSelData *)calloc(1,sizeof(sDataSelectorSelData) * nSel);
int *isFound = (int*)calloc(1,sizeof(int)*nSel);
for (n=0; n<_N; n++) {
// int found=0;
// SMILE_IDBG(4,"selstr %i of %i",i,outputSelStr.n);
char * tmpname = reader_->getElementName(n);
for (i=0; i<nSel; i++) {
if (!isFound[i]) {
if (!strcmp(tmpname,names[i])) {
mapping[i].eIdx = n;
nElSel++; isFound[i]=1;
break;
}
}
}
free(tmpname);
if (nElSel >= nSel) break;
}
if (nElSel < nSel) {
SMILE_IERR(1,"%i elements which were requested in element selection file were not found in current input data! please check openSMILE config! These elements are:",nSel-nElSel);
for (i=0; i<nSel; i++) {
if (isFound[i]==0) {
SMILE_IERR(1," element '%s' ",names[i]);
}
}
const FrameMetaInfo * fmeta = reader_->getFrameMetaInfo();
SMILE_IMSG(1, "Available field names are:");
fmeta->printFieldNames();
COMP_ERR("Your system will not run stable, due to data incompatibilities. Thus, we are aborting here!");
} else {
for (i=0; i<nSel; i++) {
if (selFile == NULL) {
const char *newname = getStr_f(myvprint("newNames[%i]",i));
if (newname != NULL) {
writer_->addField(newname);
} else {
if (nameAppend_ != NULL) {
char * tmp = myvprint("%s_%s", names[i], nameAppend_);
writer_->addField(tmp); free(tmp);
} else {
writer_->addField(names[i]); // if no newName is given, add old name
}
}
} else {
if (nameAppend_ != NULL) {
char * tmp = myvprint("%s_%s",names[i],nameAppend_);
writer_->addField(tmp); free(tmp);
} else {
writer_->addField(names[i]); // if no newName is given, add old name
}
}
}
SMILE_IDBG(3,"mapping computed successfully");
}
free(isFound);
}
/*
for (j=0; j<nSel; j++) {
int found = 0;
for (i=0; i<_N; i++) {
char * tmp = reader->getElementName(i);
if (!strcmp(tmp,names[j])) {
// we found a match...
found = 1;
mapping[nElSel++].eIdx = i;
if (selFile == NULL) {
const char *newname = getStr_f(myvprint("newNames[%i]",j));
if (newname != NULL) {
writer->addField(newname);
} else {
writer->addField(tmp); // if no newName is given, add old name
}
} else {
writer->addField(tmp);
}
}
free(tmp);
}
if (found==0) {
SMILE_IERR(1,"element '%s' requested in selection, but not found in input elements! please check input config!",names[j]);
}
}
SMILE_IDBG(2,"selected %i elements of %i requested elements",nElSel,nSel);
*/
} else {
// in non-element mode, create a list of expanded element names, then use the same code as in element mode
int _N = reader_->getLevelNf();
nElSel = 0; nFSel = 0;
mapping = (sDataSelectorSelData *)calloc(1,sizeof(sDataSelectorSelData) * nSel);
/// !!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!
//for (i=0; i<_N; i++) {
long dimensionSingleField = 0;
for (j=0; j<nSel; j++) {
// analyse type of field specified in selection, and extract fieldname (if array)
const char *fieldname=NULL;
int startIdx = 0, endIdx = 0, rangeGiven = 0;
char *tmp2 = NULL;
if (names[j] != NULL) {
tmp2 = strdup(names[j]);
char *ar = strchr(tmp2,'[');
if (ar == NULL) { // is non-array field (no [] in name) or full field
fieldname=names[j];
} else { // is array field ( with [] in name )
*ar = 0;
fieldname=tmp2;
ar++;
int len = (int)strlen(ar);
if (len > 0) {
ar[len-1] = 0; // remove closing ]
// look for element [x] OR range [x-y]
char *rng = strchr(ar,'-');
if (rng != NULL) { // is range
*rng = 0; rng++;
char *end=NULL;
startIdx = strtol(ar, &end, 10); // convert to int
if ((end != NULL)&&(end[0] != 0)) { // error, invalid chars
SMILE_IERR(1,"invalid character in array start index in 'selected' field : '%s'\n",names[j]);
COMP_ERR("stopping");
}
end=NULL;
endIdx = strtol(rng, &end, 10); // convert to int
if ((end != NULL)&&(end[0] != 0)) { // error, invalid chars
SMILE_IERR(1,"invalid character in array end index in 'selected' field : '%s'\n",names[j]);
COMP_ERR("stopping");
}
rangeGiven=1;
} else { // is element in array field
char *end=0;
startIdx = strtol(ar, &end, 10); // convert to int
if ((end != NULL)&&(end[0] != 0)) { // error, invalid chars
SMILE_IERR(1,"invalid character in array index in 'selected' field : '%s'\n",names[j]);
COMP_ERR("stopping");
}
endIdx = startIdx; rangeGiven=1;
}
}
}
}
// check if field exists
int __N=0;
int arrNameOffset=0;
int found = 0;
int elIdx = 0;
for (i=0; i<_N; i++) { // for each field
const char *tmp = reader_->getFieldName(i,&__N,&arrNameOffset);
if (!strcmp(fieldname,tmp)) {
// match found, ok
found = 1;
if (!rangeGiven) { startIdx = 0; endIdx = __N-1; }
else {
startIdx -= arrNameOffset;
endIdx -= arrNameOffset;
}
mapping[nFSel].fIdx = i;
mapping[nFSel].eIdx = elIdx;
break;
}
elIdx += __N;
}
// add to writer, if found
if (!found) {
// warn
SMILE_IWRN(1,"field '%s' requested for selection, but not found in input!",names[j]);
} else {
// check range of start/end array index
if (startIdx < 0) {
SMILE_IWRN(1,"start index (%i) for selected field '%s' is out of range (must be > 0)! Setting start index to 0.",startIdx,names[j]);
startIdx = 0;
}
else if (startIdx >= __N) {
SMILE_IWRN(1,"start index (%i) for selected field '%s' is out of range (must be < %i)! Setting start index to %i.",startIdx,names[j],__N,__N-1);
startIdx = __N-1;
}
if (endIdx < 0) {
SMILE_IWRN(1,"end index (%i) for selected field '%s' is out of range (must be > 0)! Setting end index to 0.",endIdx,names[j]);
endIdx = 0;
}
else if (endIdx >= __N) {
SMILE_IWRN(1,"end index (%i) for selected field '%s' is out of range (must be < %i)! Setting end index to %i.",endIdx,names[j],__N,__N-1);
endIdx = __N-1;
}
//add
if (outputSingleField == NULL) {
writer_->addField(fieldname, endIdx - startIdx + 1, arrNameOffset + startIdx);
} else {
dimensionSingleField += endIdx - startIdx + 1;
}
// set names in mapping, and set nElSel correct
// TODO:::.
//mapping[nElSel++].fIdx = i; // note: i is still valid from the last for() loop
mapping[nFSel].aIdx = startIdx+mapping[nFSel].eIdx; // start index as element index
mapping[nFSel++].N = endIdx-startIdx+1; // start index as element index
nElSel += endIdx-startIdx+1;
}
if (tmp2 != NULL) free(tmp2);
}
if (outputSingleField != NULL) {
writer_->addField(outputSingleField, dimensionSingleField);
}
}
namesAreSet_ = 1;
return nElSel;
}
/*
int cDataSelector::myFinaliseInstance()
{
return cDataProcessor::myFinaliseInstance();
}
*/
int cDataSelector::myTick(long long t)
{
if (dummyMode) return 0;
SMILE_DBG(4,"tick # %i, processing value vector",t);
// get next frame from dataMemory
cVector *vec = reader_->getNextFrame();
if (vec != NULL) {
if (vecO == NULL) vecO = new cVector(nElSel, vec->type);
long i;
if (vec->type == DMEM_FLOAT) {
if (elementMode) {
if (selectionIsRange) {
long j=0;
for (i=0; i<vec->N; i++) {
if (idxSelected[i]) { vecO->dataF[j++] = vec->dataF[i]; }
}
} else {
for (i=0; i<nElSel; i++) {
vecO->dataF[i] = vec->dataF[mapping[i].eIdx];
}
}
} else {
int j; long n=0;
for (i=0; i<nFSel; i++) {
for (j=0; j<mapping[i].N; j++) {
vecO->dataF[n++] = vec->dataF[mapping[i].aIdx+j];
}
}
}
} else if (vec->type == DMEM_INT) {
if (elementMode) {
if (selectionIsRange) {
long j=0;
for (i=0; i<vec->N; i++) {
if (idxSelected[i]) { vecO->dataI[j++] = vec->dataI[i]; }
}
} else {
for (i=0; i<nElSel; i++) {
vecO->dataI[i] = vec->dataI[mapping[i].eIdx];
}
}
} else {
int j; long n=0;
for (i=0; i<nFSel; i++) {
for (j=0; j<mapping[i].N; j++) {
vecO->dataI[n++] = vec->dataI[mapping[i].aIdx+j];
}
}
}
}
vecO->tmetaReplace(vec->tmeta);
// save to dataMemory
writer_->setNextFrame(vecO);
// writer->setNextFrame(myVec);
return 1;
}
return 0;
}
cDataSelector::~cDataSelector()
{
int i;
if (vecO != NULL) delete(vecO);
if (mapping!=NULL) free(mapping);
if (idxSelected!=NULL) free(idxSelected);
if (names!=NULL) {
if (selFile != NULL) {
for (i=0; i<nSel; i++) {
if (names[i] != NULL) free(names[i]); // memory allocated via strdup()
}
} // else we don't free the names, since they are allocated in the config manager!
free(names);
}
}
| 35.198462 | 578 | 0.576424 | [
"vector"
] |
a132e38bc1597df0a91934c7926a7a91f78e686f | 4,812 | cc | C++ | extensions/api/savedpasswords/savedpasswords_api.cc | wedataintelligence/vivaldi-source | 22a46f2c969f6a0b7ca239a05575d1ea2738768c | [
"BSD-3-Clause"
] | null | null | null | extensions/api/savedpasswords/savedpasswords_api.cc | wedataintelligence/vivaldi-source | 22a46f2c969f6a0b7ca239a05575d1ea2738768c | [
"BSD-3-Clause"
] | null | null | null | extensions/api/savedpasswords/savedpasswords_api.cc | wedataintelligence/vivaldi-source | 22a46f2c969f6a0b7ca239a05575d1ea2738768c | [
"BSD-3-Clause"
] | null | null | null | // Copyright (c) 2015 Vivaldi Technologies AS. All rights reserved
#include "extensions/api/savedpasswords/savedpasswords_api.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/url_formatter/url_formatter.h"
#include "content/public/browser/web_ui.h"
#include "extensions/schema/savedpasswords.h"
namespace extensions {
namespace passwords = vivaldi::savedpasswords;
using passwords::SavedPasswordItem;
SavedpasswordsGetListFunction::SavedpasswordsGetListFunction()
:password_manager_presenter_(this)
{
}
bool SavedpasswordsGetListFunction::RunAsync() {
AddRef();
password_manager_presenter_.Initialize();
password_manager_presenter_.UpdatePasswordLists();
return true;
}
SavedpasswordsGetListFunction::~SavedpasswordsGetListFunction() {
}
Profile* SavedpasswordsGetListFunction::GetProfile() {
return ChromeUIThreadExtensionFunction::GetProfile();
}
#if !defined(OS_ANDROID)
gfx::NativeWindow SavedpasswordsGetListFunction::GetNativeWindow() const {
return NULL;
}
#endif
void SavedpasswordsGetListFunction::SetPasswordList(
const std::vector<scoped_ptr<autofill::PasswordForm>>& password_list,
bool show_passwords) {
std::vector<linked_ptr<SavedPasswordItem> > svd_pwd_entries;
base::ListValue entries;
languages_ = GetProfile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
for (size_t i = 0; i < password_list.size(); ++i) {
linked_ptr<vivaldi::savedpasswords::SavedPasswordItem> new_node(
GetSavedPasswordItem(password_list[i], i));
svd_pwd_entries.push_back(new_node);
}
results_ = vivaldi::savedpasswords::GetList::Results::Create(svd_pwd_entries);
SendAsyncResponse();
}
SavedPasswordItem* SavedpasswordsGetListFunction::GetSavedPasswordItem(
const scoped_ptr<autofill::PasswordForm> &form, int id
){
SavedPasswordItem* notes_tree_node = new SavedPasswordItem();
notes_tree_node->username = base::UTF16ToUTF8(form->username_value);
notes_tree_node->origin = base::UTF16ToUTF8(
url_formatter::FormatUrl(form->origin, languages_));
notes_tree_node->id = base::Int64ToString(id);
return notes_tree_node;
}
void SavedpasswordsGetListFunction::SendAsyncResponse() {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&SavedpasswordsGetListFunction::SendResponseToCallback, this));
}
void SavedpasswordsGetListFunction::SendResponseToCallback() {
SendResponse(true);
Release(); // Balanced in RunAsync().
}
void SavedpasswordsGetListFunction::SetPasswordExceptionList(
const std::vector<scoped_ptr<autofill::PasswordForm>>&
password_exception_list) {
}
void SavedpasswordsGetListFunction::ShowPassword(
size_t index,
const std::string& origin_url,
const std::string& username,
const base::string16& password_value) {
}
SavedpasswordsRemoveFunction::SavedpasswordsRemoveFunction():
password_manager_presenter_(this)
{
}
SavedpasswordsRemoveFunction::~SavedpasswordsRemoveFunction(){
}
bool SavedpasswordsRemoveFunction::RunAsync(){
AddRef(); //Balanced in SendResponseToCallback
password_manager_presenter_.Initialize();
password_manager_presenter_.UpdatePasswordLists();
scoped_ptr<passwords::Remove::Params> params(
passwords::Remove::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
base::StringToInt64(params->id, &idToRemove);
return true;
}
Profile* SavedpasswordsRemoveFunction::GetProfile(){
return ChromeUIThreadExtensionFunction::GetProfile();
}
void SavedpasswordsRemoveFunction::ShowPassword(size_t index,
const std::string& origin_url,
const std::string& username,
const base::string16& password_value){
}
void SavedpasswordsRemoveFunction::SetPasswordList(
const std::vector<scoped_ptr<autofill::PasswordForm>>& password_list,
bool show_passwords){
password_manager_presenter_.RemoveSavedPassword(
static_cast<size_t>(idToRemove));
results_ = passwords::Remove::Results::Create();
SendAsyncResponse();
}
void SavedpasswordsRemoveFunction::SetPasswordExceptionList(
const std::vector<scoped_ptr<autofill::PasswordForm>>&
password_exception_list){}
#if !defined(OS_ANDROID)
gfx::NativeWindow SavedpasswordsRemoveFunction::GetNativeWindow() const {
return NULL;
}
#endif
void SavedpasswordsRemoveFunction::SendResponseToCallback() {
SendResponse(true);
Release(); // Balanced in RunAsync().
}
void SavedpasswordsRemoveFunction::SendAsyncResponse() {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&SavedpasswordsRemoveFunction::SendResponseToCallback, this));
}
} // namespace extensions
| 30.075 | 80 | 0.773483 | [
"vector"
] |
a13b6cf53f5eec4d210f83c2b0628a64edd9d2b1 | 2,484 | cpp | C++ | aws-cpp-sdk-ce/source/model/ESInstanceDetails.cpp | Neusoft-Technology-Solutions/aws-sdk-cpp | 88c041828b0dbee18a297c3cfe98c5ecd0706d0b | [
"Apache-2.0"
] | 1 | 2022-02-12T08:09:30.000Z | 2022-02-12T08:09:30.000Z | aws-cpp-sdk-ce/source/model/ESInstanceDetails.cpp | Neusoft-Technology-Solutions/aws-sdk-cpp | 88c041828b0dbee18a297c3cfe98c5ecd0706d0b | [
"Apache-2.0"
] | 1 | 2022-01-03T23:59:37.000Z | 2022-01-03T23:59:37.000Z | aws-cpp-sdk-ce/source/model/ESInstanceDetails.cpp | ravindra-wagh/aws-sdk-cpp | 7d5ff01b3c3b872f31ca98fb4ce868cd01e97696 | [
"Apache-2.0"
] | 1 | 2021-11-09T11:58:03.000Z | 2021-11-09T11:58:03.000Z | /**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/ce/model/ESInstanceDetails.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <utility>
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
namespace Aws
{
namespace CostExplorer
{
namespace Model
{
ESInstanceDetails::ESInstanceDetails() :
m_instanceClassHasBeenSet(false),
m_instanceSizeHasBeenSet(false),
m_regionHasBeenSet(false),
m_currentGeneration(false),
m_currentGenerationHasBeenSet(false),
m_sizeFlexEligible(false),
m_sizeFlexEligibleHasBeenSet(false)
{
}
ESInstanceDetails::ESInstanceDetails(JsonView jsonValue) :
m_instanceClassHasBeenSet(false),
m_instanceSizeHasBeenSet(false),
m_regionHasBeenSet(false),
m_currentGeneration(false),
m_currentGenerationHasBeenSet(false),
m_sizeFlexEligible(false),
m_sizeFlexEligibleHasBeenSet(false)
{
*this = jsonValue;
}
ESInstanceDetails& ESInstanceDetails::operator =(JsonView jsonValue)
{
if(jsonValue.ValueExists("InstanceClass"))
{
m_instanceClass = jsonValue.GetString("InstanceClass");
m_instanceClassHasBeenSet = true;
}
if(jsonValue.ValueExists("InstanceSize"))
{
m_instanceSize = jsonValue.GetString("InstanceSize");
m_instanceSizeHasBeenSet = true;
}
if(jsonValue.ValueExists("Region"))
{
m_region = jsonValue.GetString("Region");
m_regionHasBeenSet = true;
}
if(jsonValue.ValueExists("CurrentGeneration"))
{
m_currentGeneration = jsonValue.GetBool("CurrentGeneration");
m_currentGenerationHasBeenSet = true;
}
if(jsonValue.ValueExists("SizeFlexEligible"))
{
m_sizeFlexEligible = jsonValue.GetBool("SizeFlexEligible");
m_sizeFlexEligibleHasBeenSet = true;
}
return *this;
}
JsonValue ESInstanceDetails::Jsonize() const
{
JsonValue payload;
if(m_instanceClassHasBeenSet)
{
payload.WithString("InstanceClass", m_instanceClass);
}
if(m_instanceSizeHasBeenSet)
{
payload.WithString("InstanceSize", m_instanceSize);
}
if(m_regionHasBeenSet)
{
payload.WithString("Region", m_region);
}
if(m_currentGenerationHasBeenSet)
{
payload.WithBool("CurrentGeneration", m_currentGeneration);
}
if(m_sizeFlexEligibleHasBeenSet)
{
payload.WithBool("SizeFlexEligible", m_sizeFlexEligible);
}
return payload;
}
} // namespace Model
} // namespace CostExplorer
} // namespace Aws
| 20.032258 | 69 | 0.73752 | [
"model"
] |
a14b6b6eec31dc81fbf5c51094e71bacbc94320b | 19,996 | cc | C++ | tensorstore/index_space/internal/iterate.cc | stuarteberg/tensorstore | 2c22a3c9f798b0fbf023031633c58cc7c644235d | [
"Apache-2.0"
] | null | null | null | tensorstore/index_space/internal/iterate.cc | stuarteberg/tensorstore | 2c22a3c9f798b0fbf023031633c58cc7c644235d | [
"Apache-2.0"
] | null | null | null | tensorstore/index_space/internal/iterate.cc | stuarteberg/tensorstore | 2c22a3c9f798b0fbf023031633c58cc7c644235d | [
"Apache-2.0"
] | null | null | null | // Copyright 2020 The TensorStore Authors
//
// 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 "tensorstore/util/internal/iterate.h"
#include "tensorstore/array.h"
#include "tensorstore/index_space/index_transform.h"
#include "tensorstore/index_space/internal/iterate_impl.h"
#include "tensorstore/index_space/internal/transform_rep.h"
#include "tensorstore/index_space/internal/transform_rep_impl.h"
#include "tensorstore/internal/elementwise_function.h"
#include "tensorstore/util/internal/iterate_impl.h"
#include "tensorstore/util/iterate_over_index_range.h"
#include "tensorstore/util/span.h"
#include "tensorstore/util/status.h"
namespace tensorstore {
namespace internal_index_space {
constexpr Index temp_index_buffer_size = 1024;
void MarkSingletonDimsAsSkippable(
span<const Index> input_shape,
input_dimension_iteration_flags::Bitmask* input_dimension_flags) {
for (DimensionIndex i = 0; i < input_shape.size(); ++i) {
if (input_shape[i] <= 1)
input_dimension_flags[i] = input_dimension_iteration_flags::can_skip;
}
}
namespace {
/// Common implementation of the two variants of
/// InitializeSingleArrayIterationState.
///
/// If `UseStridedLayout == true`, the range of `transform` is checked against
/// the domain of `array`; `transform` may be `nullptr`, in which case it is
/// treated as an identity transform of rank `array.rank()`.
///
/// If `UseStridedLayout == false`, `transform` must not be `nullptr`, and
/// `(array.element_pointer(), transform)` is assumed to be a valid
/// `NormalizedTransformedArray`.
template <bool UseStridedLayout>
Status InitializeSingleArrayIterationStateImpl(
OffsetArrayView<const void, (UseStridedLayout ? dynamic_rank : 0)> array,
TransformRep* transform, const Index* iteration_origin,
const Index* iteration_shape, SingleArrayIterationState* single_array_state,
input_dimension_iteration_flags::Bitmask* input_dimension_flags) {
if constexpr (!UseStridedLayout) {
assert(transform != nullptr);
}
const DimensionIndex output_rank =
UseStridedLayout ? array.rank() : transform->output_rank;
single_array_state->base_pointer = const_cast<void*>(array.data());
if constexpr (UseStridedLayout) {
if (!transform) {
// Handle identity transform case.
for (DimensionIndex output_dim = 0; output_dim < output_rank;
++output_dim) {
const DimensionIndex input_dim = output_dim;
const Index byte_stride = array.byte_strides()[output_dim];
single_array_state->input_byte_strides[input_dim] = byte_stride;
if (iteration_shape[input_dim] > 1) {
input_dimension_flags[input_dim] |=
input_dimension_iteration_flags::strided;
}
single_array_state->base_pointer +=
internal::wrap_on_overflow::Multiply(iteration_origin[input_dim],
byte_stride);
}
return absl::OkStatus();
}
}
assert(output_rank == transform->output_rank);
const DimensionIndex input_rank = transform->input_rank;
span<OutputIndexMap> maps = transform->output_index_maps().first(output_rank);
// Updates `single_array_state->input_byte_strides`,
// `single_array_state->base_pointer`,
// `single_array_state->index_array_pointer`,
// `single_array_state->index_array_byte_strides`, and `input_dimension_flags`
// based on the output index maps.
for (DimensionIndex output_dim = 0; output_dim < output_rank; ++output_dim) {
const Index byte_stride =
UseStridedLayout ? array.byte_strides()[output_dim] : 1;
if (byte_stride == 0) continue;
const auto& map = maps[output_dim];
const Index output_offset = map.offset();
const Index output_stride = map.stride();
single_array_state->base_pointer +=
internal::wrap_on_overflow::Multiply(output_offset, byte_stride);
if (output_stride == 0 || map.method() == OutputIndexMethod::constant) {
if constexpr (UseStridedLayout) {
if (!Contains(array.domain()[output_dim], output_offset)) {
return MaybeAnnotateStatus(
CheckContains(array.domain()[output_dim], output_offset),
StrCat(
"Checking bounds of constant output index map for dimension ",
output_dim));
}
} else {
// `output_offset` is assumed to be valid in the normalized
// representation.
}
} else if (map.method() == OutputIndexMethod::single_input_dimension) {
const DimensionIndex input_dim = map.input_dimension();
assert(input_dim >= 0 && input_dim < input_rank);
if constexpr (UseStridedLayout) {
TENSORSTORE_ASSIGN_OR_RETURN(
IndexInterval range,
GetAffineTransformRange(
IndexInterval::UncheckedSized(iteration_origin[input_dim],
iteration_shape[input_dim]),
output_offset, output_stride),
MaybeAnnotateStatus(
_, StrCat("Checking bounds of output index map for dimension ",
output_dim)));
if (!Contains(array.domain()[output_dim], range)) {
return absl::OutOfRangeError(
StrCat("Output dimension ", output_dim, " range of ", range,
" is not contained within array domain of ",
array.domain()[output_dim]));
}
}
single_array_state->base_pointer += internal::wrap_on_overflow::Multiply(
byte_stride, internal::wrap_on_overflow::Multiply(
output_stride, iteration_origin[input_dim]));
// The `input_byte_strides` value for `input_dim` is equal to the sum of
// the `stride`-adjusted array `byte_stride` values for all output
// dimensions that depend on `input_dim` via a `single_input_dimension`
// output index map.
single_array_state->input_byte_strides[input_dim] =
internal::wrap_on_overflow::Add(
single_array_state->input_byte_strides[input_dim],
internal::wrap_on_overflow::Multiply(byte_stride, output_stride));
input_dimension_flags[input_dim] |=
input_dimension_iteration_flags::strided;
} else {
const auto& index_array_data = map.index_array_data();
assert(index_array_data.rank_capacity >= input_rank);
IndexInterval index_bounds = index_array_data.index_range;
if constexpr (UseStridedLayout) {
// propagate bounds back to the index array
TENSORSTORE_ASSIGN_OR_RETURN(
IndexInterval propagated_index_bounds,
GetAffineTransformDomain(array.domain()[output_dim], output_offset,
output_stride),
MaybeAnnotateStatus(
_, StrCat("Propagating bounds from intermediate dimension ",
output_dim, ".")));
index_bounds = Intersect(propagated_index_bounds, index_bounds);
}
ByteStridedPointer<const Index> index_array_pointer =
index_array_data.element_pointer.data();
// Specifies whether the index array (reduced to the specified input
// domain) is a singleton array (has only a single distinct value).
bool has_one_element = true;
// Adjust `index_array_pointer` and `input_dimension_flags`.
for (DimensionIndex input_dim = 0; input_dim < input_rank; ++input_dim) {
const Index index_array_byte_stride =
index_array_data.byte_strides[input_dim];
index_array_pointer += internal::wrap_on_overflow::Multiply(
iteration_origin[input_dim], index_array_byte_stride);
if (index_array_byte_stride != 0 && iteration_shape[input_dim] != 1) {
input_dimension_flags[input_dim] |=
input_dimension_iteration_flags::array_indexed;
has_one_element = false;
}
}
if (has_one_element) {
// The index array has only a single distinct value; therefore, we treat
// it as a constant output index map.
const Index index = *index_array_pointer;
TENSORSTORE_RETURN_IF_ERROR(
CheckContains(index_bounds, index),
MaybeAnnotateStatus(
_, StrCat("In index array map for output dimension ",
output_dim)));
single_array_state->base_pointer +=
internal::wrap_on_overflow::Multiply(
byte_stride,
internal::wrap_on_overflow::Multiply(output_stride, index));
} else {
// The index array has more than a single distinct value; therefore, we
// add it as an index array.
DimensionIndex index_array_num =
single_array_state->num_array_indexed_output_dimensions++;
single_array_state->index_array_byte_strides[index_array_num] =
index_array_data.byte_strides;
single_array_state->index_array_pointers[index_array_num] =
index_array_pointer;
single_array_state->index_array_output_byte_strides[index_array_num] =
internal::wrap_on_overflow::Multiply(byte_stride, output_stride);
TENSORSTORE_RETURN_IF_ERROR(
ValidateIndexArrayBounds(
index_bounds,
ArrayView<const Index>(index_array_pointer.get(),
StridedLayoutView<dynamic_rank>(
input_rank, iteration_shape,
index_array_data.byte_strides))),
MaybeAnnotateStatus(
_, StrCat("In index array map for output dimension ",
output_dim)));
}
}
}
return {};
}
} // namespace
Status InitializeSingleArrayIterationState(
OffsetArrayView<const void> array, TransformRep* transform,
const Index* iteration_origin, const Index* iteration_shape,
SingleArrayIterationState* single_array_state,
input_dimension_iteration_flags::Bitmask* input_dimension_flags) {
return InitializeSingleArrayIterationStateImpl<true>(
array, transform, iteration_origin, iteration_shape, single_array_state,
input_dimension_flags);
}
Status InitializeSingleArrayIterationState(
ElementPointer<const void> element_pointer, TransformRep* transform,
const Index* iteration_origin, const Index* iteration_shape,
SingleArrayIterationState* single_array_state,
input_dimension_iteration_flags::Bitmask* input_dimension_flags) {
return InitializeSingleArrayIterationStateImpl<false>(
element_pointer, transform, iteration_origin, iteration_shape,
single_array_state, input_dimension_flags);
}
Index IndirectInnerProduct(span<const Index> indices,
const DimensionIndex* dimension_order,
const Index* byte_strides) {
Index result = 0;
for (DimensionIndex i = 0; i < indices.size(); ++i) {
result = internal::wrap_on_overflow::Add(
internal::wrap_on_overflow::Multiply(indices[i],
byte_strides[dimension_order[i]]),
result);
}
return result;
}
void FillOffsetsArray(span<Index> offsets, span<const Index> position,
const DimensionIndex* input_dimension_order,
const SingleArrayIterationState& single_array_state,
Index final_input_dim_byte_stride,
Index final_input_dim_start_position) {
std::memset(offsets.data(), 0, sizeof(Index) * offsets.size());
for (DimensionIndex
j = 0,
num_array_indexed_output_dimensions =
single_array_state.num_array_indexed_output_dimensions;
j < num_array_indexed_output_dimensions; ++j) {
ByteStridedPointer<const Index> index_data_pointer =
single_array_state.index_array_pointers[j];
const Index* cur_byte_strides =
single_array_state.index_array_byte_strides[j];
index_data_pointer += internal_index_space::IndirectInnerProduct(
position, input_dimension_order, cur_byte_strides);
const auto final_byte_stride =
cur_byte_strides[input_dimension_order[position.size()]];
const Index output_dim_byte_stride =
single_array_state.index_array_output_byte_strides[j];
if (final_byte_stride == 0) {
const Index index_value = *index_data_pointer;
for (Index j = 0; j < offsets.size(); ++j) {
offsets[j] = internal::wrap_on_overflow::Add(
offsets[j], internal::wrap_on_overflow::Multiply(
index_value, output_dim_byte_stride));
}
} else {
index_data_pointer += internal::wrap_on_overflow::Multiply(
final_byte_stride, final_input_dim_start_position);
for (Index j = 0; j < offsets.size(); ++j) {
offsets[j] = internal::wrap_on_overflow::Add(
offsets[j], internal::wrap_on_overflow::Multiply(
*index_data_pointer, output_dim_byte_stride));
index_data_pointer += final_byte_stride;
}
}
}
if (final_input_dim_byte_stride != 0) {
for (Index j = 0; j < offsets.size(); ++j) {
offsets[j] = internal::wrap_on_overflow::Add(
offsets[j],
internal::wrap_on_overflow::Multiply(final_input_dim_byte_stride, j));
}
}
}
template <std::size_t Arity>
ArrayIterateResult IterateUsingSimplifiedLayout(
const SimplifiedDimensionIterationOrder& layout,
span<const Index> input_shape,
internal::ElementwiseClosure<Arity, Status*> closure, Status* status,
span<absl::optional<SingleArrayIterationState>, Arity> single_array_states,
std::array<std::ptrdiff_t, Arity> element_sizes) {
const Index final_indexed_dim_size =
layout.simplified_shape[layout.pure_strided_start_dim - 1];
std::array<const Index*, Arity> strides;
for (std::size_t i = 0; i < Arity; ++i) {
strides[i] = single_array_states[i]->input_byte_strides.data();
}
internal::StridedLayoutFunctionApplyer<Arity> strided_applyer(
input_shape.data(),
span(layout.input_dimension_order.data() + layout.pure_strided_start_dim,
layout.input_dimension_order.data() + layout.pure_strided_end_dim),
strides, closure, element_sizes);
struct SingleArrayOffsetsBuffer {
Index offsets[temp_index_buffer_size];
};
const DimensionIndex last_indexed_dim = layout.pure_strided_start_dim - 1;
ArrayIterateResult outer_result;
outer_result.count = 0;
// Iterate over all but the last array-indexed dimension. We handle the last
// array-indexed dimension specially for efficiency.
outer_result.success = IterateOverIndexRange(
span(layout.simplified_shape.data(), last_indexed_dim),
[&](span<const Index> position) {
std::array<SingleArrayOffsetsBuffer, Arity> single_array_offset_buffers;
std::array<ByteStridedPointer<void>, Arity> pointers;
std::array<Index, Arity> final_indexed_dim_byte_strides;
for (std::size_t i = 0; i < Arity; ++i) {
const auto& single_array_state = *single_array_states[i];
pointers[i] = single_array_state.base_pointer +
internal_index_space::IndirectInnerProduct(
position, layout.input_dimension_order.data(),
single_array_state.input_byte_strides.data());
final_indexed_dim_byte_strides[i] =
single_array_state
.input_byte_strides[layout.input_dimension_order
[layout.pure_strided_start_dim - 1]];
}
for (Index final_indexed_dim_start_position = 0;
final_indexed_dim_start_position < final_indexed_dim_size;
final_indexed_dim_start_position += temp_index_buffer_size) {
const Index block_size = std::min(
final_indexed_dim_size - final_indexed_dim_start_position,
temp_index_buffer_size);
for (std::size_t i = 0; i < Arity; ++i) {
Index* offsets = single_array_offset_buffers[i].offsets;
FillOffsetsArray(span(offsets, block_size), position,
layout.input_dimension_order.data(),
*single_array_states[i],
final_indexed_dim_byte_strides[i],
final_indexed_dim_start_position);
}
if (strided_applyer.inner_size() == 1) {
std::array<internal::IterationBufferPointer, Arity>
pointers_with_offset_arrays;
for (std::size_t i = 0; i < Arity; ++i) {
pointers_with_offset_arrays[i] = internal::IterationBufferPointer{
pointers[i], single_array_offset_buffers[i].offsets};
}
Index cur_count = internal::InvokeElementwiseClosure(
closure, internal::IterationBufferKind::kIndexed, block_size,
pointers_with_offset_arrays, status);
outer_result.count += cur_count;
if (cur_count != block_size) return false;
} else {
for (Index j = 0; j < block_size; ++j) {
auto cur_pointers = pointers;
for (std::size_t i = 0; i < Arity; ++i) {
cur_pointers[i] += single_array_offset_buffers[i].offsets[j];
}
auto inner_result = strided_applyer(cur_pointers, status);
outer_result.count += inner_result.count;
if (!inner_result.success) return false;
}
}
}
return true;
});
return outer_result;
}
// TODO(jbms): Consider making this a static method of a class template to
// simplify the explicit instantiation.
#define TENSORSTORE_INTERNAL_DO_INSTANTIATE_ITERATE_USING_SIMPLIFIED_LAYOUT( \
Arity) \
template ArrayIterateResult IterateUsingSimplifiedLayout<Arity>( \
const SimplifiedDimensionIterationOrder& layout, \
span<const Index> input_shape, \
internal::ElementwiseClosure<Arity, Status*> closure, Status* status, \
span<absl::optional<SingleArrayIterationState>, Arity> \
single_array_states, \
std::array<std::ptrdiff_t, Arity> element_sizes);
TENSORSTORE_INTERNAL_FOR_EACH_ARITY(
TENSORSTORE_INTERNAL_DO_INSTANTIATE_ITERATE_USING_SIMPLIFIED_LAYOUT)
#undef TENSORSTORE_INTERNAL_DO_INSTANTIATE_ITERATE_USING_SIMPLIFIED_LAYOUT
} // namespace internal_index_space
Status ValidateIndexArrayBounds(
IndexInterval bounds,
ArrayView<const Index, dynamic_rank, offset_origin> index_array) {
const auto finite_bounds = FiniteSubset(bounds);
const Index inclusive_min = finite_bounds.inclusive_min();
const Index exclusive_max = finite_bounds.exclusive_max();
Index bad_index;
if (!IterateOverArrays(
[&](const Index* value) {
if (ABSL_PREDICT_FALSE(*value < inclusive_min ||
*value >= exclusive_max)) {
bad_index = *value;
return false;
}
return true;
},
skip_repeated_elements, index_array)) {
return CheckContains(bounds, bad_index);
}
return absl::OkStatus();
}
} // namespace tensorstore
| 45.036036 | 80 | 0.660932 | [
"transform"
] |
a14dcbad6ae78914713404a55426e08f3848f665 | 2,001 | cpp | C++ | doc/examples/thresholding.cpp | nickporubsky/boost-simd-clone | b81dfcd9d6524a131ea714f1eebb5bb75adddcc7 | [
"BSL-1.0"
] | 5 | 2018-02-20T11:21:12.000Z | 2019-11-12T13:45:09.000Z | doc/examples/thresholding.cpp | nickporubsky/boost-simd-clone | b81dfcd9d6524a131ea714f1eebb5bb75adddcc7 | [
"BSL-1.0"
] | null | null | null | doc/examples/thresholding.cpp | nickporubsky/boost-simd-clone | b81dfcd9d6524a131ea714f1eebb5bb75adddcc7 | [
"BSL-1.0"
] | 2 | 2017-11-17T15:30:36.000Z | 2018-03-01T02:06:25.000Z | //==================================================================================================
/*
Copyright 2016 NumScale SAS
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
//==================================================================================================
//! [threshold]
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <limits>
#include <vector>
#include <boost/simd/pack.hpp>
#include <boost/simd/function/aligned_store.hpp>
#include <boost/simd/function/group.hpp>
#include <boost/simd/function/if_zero_else_one.hpp>
#include <boost/simd/function/is_less.hpp>
#include <boost/simd/memory/allocator.hpp>
int main()
{
namespace bs = boost::simd;
int image_size = 2560 * 2560;
std::vector<std::int16_t, bs::allocator<std::int16_t>> image(image_size);
std::vector<std::int16_t, bs::allocator<std::int16_t>> binary(image_size);
std::generate(image.begin(), image.end(),
[]() { return std::rand() % std::numeric_limits<std::int16_t>::max(); });
// select arbitrary threshold
std::int16_t threshold = 5000;
//! [scalar-threshold]
for (int i = 0; i < image.size(); ++i) {
if (image[i] < threshold) {
binary[i] = 0;
} else {
binary[i] = 1;
}
}
//! [scalar-threshold]
//! [simd-threshold]
using pack_t = bs::pack<std::int16_t>;
using logical_t = bs::pack<bs::logical<std::int16_t>>;
pack_t v_threshold{threshold};
for (int i = 0; i < image.size(); i += pack_t::static_size) {
pack_t v_image(&image[i]);
logical_t v_res = bs::is_less(v_image, v_threshold);
pack_t v_binary = bs::if_zero_else_one(v_res);
bs::aligned_store(v_binary, &binary[i]);
}
//! [simd-threshold]
}
// This code can be compiled using (for instance for gcc)
// g++ thresholding.cpp -msse4.2 -std=c++11 -O3 -DNDEBUG -o thresholding
// -I/path_to/boost_simd/ -I/path_to/boost/
//! [threshold]
| 31.761905 | 100 | 0.598701 | [
"vector"
] |
a1551df5af69c57c9bf02e0f70d622596c949e84 | 2,460 | cpp | C++ | C++/fileSearcherUSN/fileSearcherUSN/fileSearcherUSN.cpp | Alex-vivine/File-Engine | 46fd93a49ab432152347dba30027ba16cbbaba9f | [
"MIT"
] | 1 | 2020-09-30T09:46:19.000Z | 2020-09-30T09:46:19.000Z | C++/fileSearcherUSN/fileSearcherUSN/fileSearcherUSN.cpp | Alex-vivine/File-Engine | 46fd93a49ab432152347dba30027ba16cbbaba9f | [
"MIT"
] | null | null | null | C++/fileSearcherUSN/fileSearcherUSN/fileSearcherUSN.cpp | Alex-vivine/File-Engine | 46fd93a49ab432152347dba30027ba16cbbaba9f | [
"MIT"
] | null | null | null | #include <iostream>
#include "stdafx.h"
#include "Volume.h"
#include <fstream>
#include <thread>
typedef struct{
char disk;
vector<string> ignorePath;
} parameter;
sqlite3* db;
static volatile UINT tasksFinished = 0;
static volatile UINT totalTasks = 0;
void initUSN(parameter p);
void splitString(char* str, vector<string>& vec);
void initUSN(parameter p) {
bool ret = (65 <= p.disk && p.disk <= 90) || (97 <= p.disk && p.disk <= 122);
if (ret) {
Volume volume(p.disk, db, p.ignorePath);
volume.initVolume();
tasksFinished++;
#ifdef TEST
cout << "Initialize done " << p.disk << endl;
#endif
}
}
void splitString(char* str, vector<string>& vec) {
char* _diskPath;
char* remainDisk;
char* p;
char diskPath[5000];
strcpy_s(diskPath, str);
_diskPath = diskPath;
p = strtok_s(_diskPath, ",", &remainDisk);
if (p != NULL) {
vec.push_back(string(p));
}
while (p != NULL) {
p = strtok_s(NULL, ",", &remainDisk);
if (p != NULL) {
vec.push_back(string(p));
}
}
}
int main() {
char diskPath[1000];
char output[1000];
char ignorePath[1000];
size_t diskCount = 0;
vector<string> diskVec;
vector<string> ignorePathsVec;
ifstream input("MFTSearchInfo.dat", ios::in);
input.getline(diskPath, 1000);
input.getline(output, 1000);
input.getline(ignorePath, 1000);
input.close();
diskVec.reserve(26);
sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
sqlite3_config(SQLITE_CONFIG_MEMSTATUS, 0);
size_t ret = sqlite3_open(output, &db);
if (SQLITE_OK != ret) {
cout << "error opening database" << endl;
return 0;
}
sqlite3_exec(db, "PRAGMA TEMP_STORE=MEMORY;", 0, 0, 0);
sqlite3_exec(db, "PRAGMA journal_mode=OFF;", 0, 0, 0);
sqlite3_exec(db, "PRAGMA cache_size=50000;", 0, 0, 0);
sqlite3_exec(db, "PRAGMA page_size=16384;", 0, 0, 0);
sqlite3_exec(db, "PRAGMA auto_vacuum=0;", 0, 0, 0);
sqlite3_exec(db, "PRAGMA mmap_size=4096;", 0, 0, 0);
sqlite3_exec(db, "BEGIN;", 0, 0, 0);
splitString(diskPath, diskVec);
splitString(ignorePath, ignorePathsVec);
char disk;
for (vector<string>::iterator iter = diskVec.begin(); iter != diskVec.end(); iter++) {
disk = (*iter)[0];
if (((65 <= disk) && (disk <= 90)) || ((97 <= disk) && (disk <= 122))) {
parameter p;
p.disk = disk;
p.ignorePath = ignorePathsVec;
thread t(initUSN, p);
totalTasks++;
t.detach();
}
}
while (tasksFinished < totalTasks) {
Sleep(10);
}
sqlite3_exec(db, "COMMIT;", 0, 0, 0);
sqlite3_close(db);
return 0;
} | 22.568807 | 87 | 0.655285 | [
"vector"
] |
a1572d85aaf2f67703c3ba3014b73986d060fe41 | 2,696 | cpp | C++ | algorithms/contiguous-data/find-substr/implem_multi.cpp | dubzzz/various-algorithms | 16af4c05acfcb23d199df0851402b0da3ebba91c | [
"MIT"
] | 1 | 2017-04-17T18:32:46.000Z | 2017-04-17T18:32:46.000Z | algorithms/contiguous-data/find-substr/implem_multi.cpp | dubzzz/various-algorithms | 16af4c05acfcb23d199df0851402b0da3ebba91c | [
"MIT"
] | 10 | 2016-12-25T04:42:56.000Z | 2017-03-30T20:42:25.000Z | algorithms/contiguous-data/find-substr/implem_multi.cpp | dubzzz/various-algorithms | 16af4c05acfcb23d199df0851402b0da3ebba91c | [
"MIT"
] | 1 | 2022-03-25T17:39:05.000Z | 2022-03-25T17:39:05.000Z | #include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include "aim.hpp"
// Algorithm to be tested
std::size_t find_substr(std::string const& raw, std::string const& pattern)
{
if (pattern.empty())
{
return 0;
}
using RawBits = unsigned long long;
constexpr std::size_t rawbits_length = 8 * sizeof(RawBits);
RawBits offset_end_bit = RawBits(1) << (pattern.size() % rawbits_length);
std::size_t num_rawbits = 1 + pattern.size()/rawbits_length;
// build automata changes
std::vector<RawBits> transitions[26];
std::fill(transitions, transitions +26, std::vector<RawBits>(num_rawbits));
for (std::size_t idx {} ; idx != pattern.size() ; ++idx)
{
std::size_t idx_in_state { idx };
std::size_t first_idx { idx_in_state / rawbits_length };
std::size_t second_idx { idx_in_state % rawbits_length };
transitions[pattern[idx] - 'A'][first_idx] |= (RawBits(1) << second_idx);
}
#ifdef DEBUG
std::cout << "Transition table: " << std::endl;
for (char c = 'A' ; c <= 'Z' ; ++c)
{
std::cout << "- Transition for " << c << ':' << std::endl;
auto& transition = transitions[c - 'A'];
for (std::size_t id {} ; id != transition.size() ; ++id)
{
std::cout << " - " << id << ": " << std::bitset<rawbits_length>(transition[id]) << std::endl;
}
}
std::cout << std::endl;
#endif
// apply automata
std::vector<RawBits> current_state(num_rawbits);
current_state[0] = 1;
for (std::size_t idx {} ; idx != raw.size() ; ++idx)
{
auto& transition = transitions[raw[idx] - 'A'];
for (std::size_t id {} ; id != current_state.size() ; ++id) { current_state[id] &= transition[id]; }
std::vector<bool> carry(current_state.size());
for (std::size_t id {} ; id != current_state.size() ; ++id) { carry[id] = !! (current_state[id] & (RawBits(1) << (rawbits_length -1))); }
for (std::size_t id {} ; id != current_state.size() ; ++id) { current_state[id] <<= 1; }
for (std::size_t id {1} ; id < current_state.size() ; ++id) { if (carry[id -1]) { current_state[id] |= 1; } }
current_state[0] |= 1;
#ifdef DEBUG
std::cout << "Input: " << raw[idx] << std::endl;
std::cout << "Status: " << std::endl;
for (std::size_t id {} ; id != current_state.size() ; ++id)
{
std::cout << "- " << id << ": " << std::bitset<rawbits_length>(current_state[id]) << std::endl;
}
std::cout << std::endl;
#endif
if (current_state.back() & offset_end_bit) { return idx +1 -pattern.size(); }
}
return std::string::npos;
}
| 33.283951 | 141 | 0.589021 | [
"vector"
] |
a15c5d11a2d0507ac3cd16a754e7d269f079d75c | 3,666 | hpp | C++ | src/utils/rngen.hpp | rblake-llnl/wcs | ac2d49fb66d89bdcf8f815958b62d9b566a34a8f | [
"MIT-0",
"MIT"
] | null | null | null | src/utils/rngen.hpp | rblake-llnl/wcs | ac2d49fb66d89bdcf8f815958b62d9b566a34a8f | [
"MIT-0",
"MIT"
] | null | null | null | src/utils/rngen.hpp | rblake-llnl/wcs | ac2d49fb66d89bdcf8f815958b62d9b566a34a8f | [
"MIT-0",
"MIT"
] | null | null | null | /******************************************************************************
* *
* Copyright 2020 Lawrence Livermore National Security, LLC and other *
* Whole Cell Simulator Project Developers. See the top-level COPYRIGHT *
* file for details. *
* *
* SPDX-License-Identifier: MIT *
* *
******************************************************************************/
#ifndef __WCS_UTILS_RNGEN_HPP__
#define __WCS_UTILS_RNGEN_HPP__
#include <random>
#include <chrono>
#if defined(WCS_HAS_CONFIG)
#include "wcs_config.hpp"
#else
#error "no config"
#endif
#if defined(WCS_HAS_CEREAL)
#include <cereal/types/vector.hpp>
#include <cereal/archives/binary.hpp>
#include "utils/state_io_cereal.hpp"
ENABLE_CUSTOM_CEREAL (std::minstd_rand);
ENABLE_CUSTOM_CEREAL (std::minstd_rand0);
ENABLE_CUSTOM_CEREAL (std::mt19937)
ENABLE_CUSTOM_CEREAL (std::mt19937_64)
ENABLE_CUSTOM_CEREAL (std::uniform_int_distribution<unsigned long long>)
ENABLE_CUSTOM_CEREAL (std::uniform_int_distribution<long long>)
ENABLE_CUSTOM_CEREAL (std::uniform_int_distribution<uint32_t>)
ENABLE_CUSTOM_CEREAL (std::uniform_int_distribution<int>)
ENABLE_CUSTOM_CEREAL (std::uniform_real_distribution<double>)
ENABLE_CUSTOM_CEREAL (std::uniform_real_distribution<float>)
#endif // WCS_HAS_CEREAL
#include "utils/state_io.hpp"
#include "utils/seed.hpp"
namespace wcs {
template <template <typename> typename D = std::uniform_real_distribution,
typename V = double>
class RNGen {
public:
using result_type = V;
using distribution_t = D<V>;
using param_type = typename distribution_t::param_type;
using generator_type = std::mt19937;
RNGen();
/// Set seed when using a single value for seeding
void set_seed(unsigned s);
/// Set seed using the current time value
void set_seed();
/**
* Set seed_seq input to generate a seed_seq object such that a sequence of
* values (as long as the state size) rather than a single value can be used
* for seeding
*/
void use_seed_seq(const seed_seq_param_t& p);
void param(const param_type& p);
param_type param() const;
result_type operator()();
const distribution_t& distribution() const;
//// Return the length of the generator state in words
static constexpr unsigned get_state_size();
/// Allow read-write acces to the internal generator engine
generator_type& engine();
/// Allow read-only acces to the internal generator engine
const generator_type& engine() const;
#if defined(WCS_HAS_CEREAL)
template <class Archive>
void serialize( Archive & ar )
{
ar(m_seed, m_sseq_used, m_sseq_param, m_gen, m_distribution);
//ar(m_seed, m_sseq_used, m_gen, m_distribution);
}
friend class cereal::access;
#endif // defined(WCS_HAS_CEREAL)
template<typename S> static bool check_bits_compatibility(const S&);
template<typename S> S& save_bits(S &os) const;
template<typename S> S& load_bits(S &is);
size_t byte_size() const;
protected:
/**
* seed value when a single seed value is used or the master seed
* to generate a seed sequence
*/
unsigned m_seed;
/// Whether to use seed_seq
bool m_sseq_used;
/// seed_seq input
seed_seq_param_t m_sseq_param;
generator_type m_gen;
distribution_t m_distribution;
};
} // end of namespce wcs
#include "rngen_impl.hpp"
#endif // __WCS_UTILS_RNGEN_HPP__
| 33.327273 | 80 | 0.6473 | [
"object",
"vector"
] |
a15f3d92600b897c9cd59a377e5a1415fdae15f4 | 2,363 | cpp | C++ | sources/octree_change_detection/octree_change_detection.cpp | SmartKangJohn/PCL191_tutorials_x64 | ba23cfa0c612d11b00b97fba75e2f9b41633b5d1 | [
"MIT"
] | 2 | 2019-04-10T14:04:52.000Z | 2019-05-29T03:41:58.000Z | sources/octree_change_detection/octree_change_detection.cpp | SmartKangJohn/PCL191_tutorials_x64 | ba23cfa0c612d11b00b97fba75e2f9b41633b5d1 | [
"MIT"
] | null | null | null | sources/octree_change_detection/octree_change_detection.cpp | SmartKangJohn/PCL191_tutorials_x64 | ba23cfa0c612d11b00b97fba75e2f9b41633b5d1 | [
"MIT"
] | 1 | 2021-12-20T06:54:41.000Z | 2021-12-20T06:54:41.000Z | #include <pcl/point_cloud.h>
#include <pcl/octree/octree_pointcloud_changedetector.h>
#include <iostream>
#include <vector>
#include <ctime>
int
main (int argc, char** argv)
{
srand ((unsigned int) time (NULL));
// Octree resolution - side length of octree voxels
float resolution = 32.0f;
// Instantiate octree-based point cloud change detection class
pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZ> octree (resolution);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloudA (new pcl::PointCloud<pcl::PointXYZ> );
// Generate pointcloud data for cloudA
cloudA->width = 128;
cloudA->height = 1;
cloudA->points.resize (cloudA->width * cloudA->height);
for (size_t i = 0; i < cloudA->points.size (); ++i)
{
cloudA->points[i].x = 64.0f * rand () / (RAND_MAX + 1.0f);
cloudA->points[i].y = 64.0f * rand () / (RAND_MAX + 1.0f);
cloudA->points[i].z = 64.0f * rand () / (RAND_MAX + 1.0f);
}
// Add points from cloudA to octree
octree.setInputCloud (cloudA);
octree.addPointsFromInputCloud ();
// Switch octree buffers: This resets octree but keeps previous tree structure in memory.
octree.switchBuffers ();
pcl::PointCloud<pcl::PointXYZ>::Ptr cloudB (new pcl::PointCloud<pcl::PointXYZ> );
// Generate pointcloud data for cloudB
cloudB->width = 128;
cloudB->height = 1;
cloudB->points.resize (cloudB->width * cloudB->height);
for (size_t i = 0; i < cloudB->points.size (); ++i)
{
cloudB->points[i].x = 64.0f * rand () / (RAND_MAX + 1.0f);
cloudB->points[i].y = 64.0f * rand () / (RAND_MAX + 1.0f);
cloudB->points[i].z = 64.0f * rand () / (RAND_MAX + 1.0f);
}
// Add points from cloudB to octree
octree.setInputCloud (cloudB);
octree.addPointsFromInputCloud ();
std::vector<int> newPointIdxVector;
// Get vector of point indices from octree voxels which did not exist in previous buffer
octree.getPointIndicesFromNewVoxels (newPointIdxVector);
// Output points
std::cout << "Output from getPointIndicesFromNewVoxels:" << std::endl;
for (size_t i = 0; i < newPointIdxVector.size (); ++i)
std::cout << i << "# Index:" << newPointIdxVector[i]
<< " Point:" << cloudB->points[newPointIdxVector[i]].x << " "
<< cloudB->points[newPointIdxVector[i]].y << " "
<< cloudB->points[newPointIdxVector[i]].z << std::endl;
}
| 32.819444 | 91 | 0.654253 | [
"vector"
] |
a1612e0cea7033830c65e41bac1d6f9cd8baec4b | 1,156 | hpp | C++ | contracts/celes.unregd/src/utils/authority.hpp | celes-dev/celesos.contracts | 698652dbc277fc1334d466cac9134338ae82b8d8 | [
"MIT"
] | null | null | null | contracts/celes.unregd/src/utils/authority.hpp | celes-dev/celesos.contracts | 698652dbc277fc1334d466cac9134338ae82b8d8 | [
"MIT"
] | null | null | null | contracts/celes.unregd/src/utils/authority.hpp | celes-dev/celesos.contracts | 698652dbc277fc1334d466cac9134338ae82b8d8 | [
"MIT"
] | null | null | null | #pragma once
#include <eosiolib/action.hpp>
namespace eosio {
typedef uint16_t weight_type;
struct permission_level_weight {
permission_level permission;
weight_type weight;
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE(permission_level_weight, (permission)(weight))
};
struct key_weight {
eosio::public_key key;
weight_type weight;
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE(key_weight, (key)(weight))
};
struct wait_weight {
uint32_t wait_sec;
weight_type weight;
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE(wait_weight, (wait_sec)(weight))
};
struct authority {
uint32_t threshold;
std::vector<key_weight> keys;
std::vector<permission_level_weight> accounts;
std::vector<wait_weight> waits;
// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE(authority, (threshold)(keys)(accounts)(waits))
};
} // namespace eosio | 26.883721 | 96 | 0.75 | [
"vector"
] |
a16153fdf41bbc09e465a80b962073b690725db0 | 9,370 | hh | C++ | src/c++/include/common/Debug.hh | Illumina/Isaac4 | 0924fba8b467868da92e1c48323b15d7cbca17dd | [
"BSD-3-Clause"
] | 13 | 2018-02-09T22:59:39.000Z | 2021-11-29T06:33:22.000Z | src/c++/include/common/Debug.hh | Illumina/Isaac4 | 0924fba8b467868da92e1c48323b15d7cbca17dd | [
"BSD-3-Clause"
] | 17 | 2018-01-26T11:36:07.000Z | 2022-02-03T18:48:43.000Z | src/c++/include/common/Debug.hh | Illumina/Isaac4 | 0924fba8b467868da92e1c48323b15d7cbca17dd | [
"BSD-3-Clause"
] | 4 | 2018-10-19T20:00:00.000Z | 2020-10-29T14:44:06.000Z | /**
** Isaac Genome Alignment Software
** Copyright (c) 2010-2017 Illumina, Inc.
** All rights reserved.
**
** This software is provided under the terms and conditions of the
** GNU GENERAL PUBLIC LICENSE Version 3
**
** You should have received a copy of the GNU GENERAL PUBLIC LICENSE Version 3
** along with this program. If not, see
** <https://github.com/illumina/licenses/>.
**
** \file Debug.hh
**
** \brief Various debugging-related helpers
**
** \author Roman Petrovski
**/
#ifndef iSAAC_LOG_THREAD_TIMESTAMP_HH
#define iSAAC_LOG_THREAD_TIMESTAMP_HH
#include "config.h"
#include <atomic>
#include <memory>
#include <typeinfo>
#include <boost/algorithm/string.hpp>
#include <boost/date_time.hpp>
#include <boost/io/ios_state.hpp>
#include <boost/thread.hpp>
#include "common/SystemCompatibility.hh"
namespace isaac
{
namespace common
{
#define iSAAC_PROFILING_NOINLINE
//#define iSAAC_PROFILING_NOINLINE __attribute__((noinline))
static std::ostream nostream(0);
//TODO: check why simple CerrLocker(std::cerr) << ... << is not good enough
/**
* \brief helper macro to simplify the thread-guarded logging. All elements on a single << line are serialized
* under one CerrLocker
*/
#define ISAAC_THREAD_CERR \
if(const ::isaac::common::detail::CerrLocker &isaac_cerr_lock = ::isaac::common::detail::CerrLocker()); \
else (isaac_cerr_lock.cerrBlocked() ? ::isaac::common::nostream : std::cerr) << isaac::common::detail::ThreadTimestamp()
#define ISAAC_ASSERT_CERR \
if(::isaac::common::detail::CerrLocker isaac_cerr_lock = ::isaac::common::detail::CerrLocker()); \
else std::cerr << isaac::common::detail::ThreadTimestamp()
#define ISAAC_SCOPE_BLOCK_CERR if (const ::isaac::common::detail::CerrBlocker blocker = ::isaac::common::detail::CerrBlocker()); else
/**
* \brief Evaluates expression always (even if NDEBUG is set and so on). Also uses ostream serialization which,
* unlike the standard assert, has shown not to allocate the dynamic memory at the time when you least
* expect this to happen.
*/
#define ISAAC_VERIFY_MSG(expr, msg) {if (expr) {} else \
{ ISAAC_ASSERT_CERR << "ERROR: ***** Internal Program Error - assertion (" << #expr << ") failed in " \
<< (BOOST_CURRENT_FUNCTION) << ":" << __FILE__ << '(' << __LINE__ << "): " << msg << std::endl; \
::isaac::common::terminateWithCoreDump();}}
#if (ISAAC_BUILD_TYPE == ISAAC_BUILD_Release)
#define ISAAC_ASSERT_MSG(expr, msg)
#else
#define ISAAC_ASSERT_MSG(expr, msg) {if (expr) {} else \
{ ISAAC_ASSERT_CERR << "ERROR: ***** Internal Program Error - assertion (" << #expr << ") failed in " \
<< (BOOST_CURRENT_FUNCTION) << ":" << __FILE__ << '(' << __LINE__ << "): " << msg << std::endl; \
::isaac::common::terminateWithCoreDump();}}
#endif
inline std::string parseStat(const std::string &stat)
{
std::vector<std::string> statFields;
boost::algorithm::split(statFields, stat, boost::algorithm::is_any_of(" "));
return std::string(statFields.at(22) + "vm " + statFields.at(23) + "res");
}
class ScopedMallocBlock : boost::noncopyable
{
public:
enum Mode
{
Invalid = 0,
Off,
Warning,
Strict
};
ScopedMallocBlock(const Mode mode);
~ScopedMallocBlock();
private:
const Mode mode_;
friend class ScopedMallocBlockUnblock;
void block();
void unblock();
};
class ScopedMallocBlockUnblock : boost::noncopyable
{
ScopedMallocBlock &block_;
public:
ScopedMallocBlockUnblock(ScopedMallocBlock & block);
~ScopedMallocBlockUnblock();
};
namespace detail
{
class ThreadTimestamp
{
public:
};
struct IndentBase
{
protected:
static iSAAC_THREAD_LOCAL unsigned width;
public:
static unsigned getWidth() {return width;}
};
template <int i>
struct IndentT: public IndentBase
{
IndentT() {width += i;}
~IndentT() {width -= i;}
};
class IndentStorer
{
public:
IndentStorer(const IndentBase& indent) : indent(indent) {}
const IndentBase & indent;
};
inline std::ostream & operator << (std::ostream &os, const IndentStorer & indenter) {
os << std::setfill(' ') << std::setw(indenter.indent.getWidth()) << "";
return os;
}
/**
* \brief formats time stamp and thread id to simplify threaded logging
*/
inline std::ostream & operator << (std::ostream &os, const ThreadTimestamp &) {
// IMPORTANT: this is the way to serialize date without causing any dynamic memory operations to occur
::std::time_t t;
::std::time(&t);
::std::tm curr, *curr_ptr;
curr_ptr = boost::date_time::c_time::localtime(&t, &curr);
os << (curr_ptr->tm_year + 1900) << '-' <<
std::setfill('0') << std::setw(2) << (curr_ptr->tm_mon + 1) << '-' <<
std::setfill('0') << std::setw(2) << curr_ptr->tm_mday << ' ' <<
std::setfill('0') << std::setw(2) << curr_ptr->tm_hour << ':' <<
std::setfill('0') << std::setw(2) << curr_ptr->tm_min << ':' <<
std::setfill('0') << std::setw(2) << curr_ptr->tm_sec << ' ' <<
"\t[" << boost::this_thread::get_id() << "]\t";
return os;
}
/**
* \brief Blocks ISAAC_THREAD_CERR messages. Use for unit tests
*/
class CerrBlocker
{
static std::atomic_int cerrBlocked_;
public:
CerrBlocker();
~CerrBlocker();
operator bool () const {
return false;
}
static bool blocked() {return cerrBlocked_;}
};
struct CerrStreamBlocker : public std::ostream
{
const bool block_;
CerrStreamBlocker(const bool block) : std::ostream(0), block_(block) {}
template <typename AnyT>
const CerrStreamBlocker& operator << (const AnyT value) const
{
if (!block_)
{
std::cerr << value;
}
return *this;
}
// template <typename AnyT>
// friend const CerrStreamBlocker& operator << (const CerrStreamBlocker& sb, const AnyT &value)
// {
// if (!sb.block_)
// {
// std::cerr << value;
// }
//
// return sb;
// }
};
/**
* \brief Guards std::cerr for the duration of CerrLocker existance
* Restores any changes made to ios::base
*/
class CerrLocker
{
// some people allocate memory from under their trace code. For example by using boost::format.
// if memory control is on, we don't want them to be dead-locked on their own thread cerrMutex_.
static boost::recursive_mutex cerrMutex_;
boost::lock_guard<boost::recursive_mutex> lock_;
boost::io::ios_base_all_saver ias_;
public:
CerrLocker(const CerrLocker &that) : lock_(cerrMutex_), ias_(std::cerr){
}
CerrLocker() : lock_(cerrMutex_), ias_(std::cerr) {
}
operator bool () const {
return false;
}
bool cerrBlocked() const {return CerrBlocker::blocked();}
};
inline CerrBlocker::CerrBlocker()
{
// ISAAC_ASSERT_CERR << "cerr blocked" << std::endl;
++cerrBlocked_;
}
inline CerrBlocker::~CerrBlocker()
{
ISAAC_ASSERT_MSG(cerrBlocked_, "Attempt to unblock more times than blocked. something is really wrong");
--cerrBlocked_;
// ISAAC_ASSERT_CERR << "cerr unblocked" << std::endl;
}
inline void assertion_failed_msg(char const * expr, char const * msg, char const * function,
char const * file, int64_t line)
{
ISAAC_ASSERT_CERR
<< "ERROR: ***** Internal Program Error - assertion (" << expr << ") failed in "
<< function << ":" << file << '(' << line << "): " << msg << std::endl;
common::terminateWithCoreDump();
}
} // namespace detail
inline std::time_t time()
{
std::time_t ret;
ISAAC_VERIFY_MSG(-1 != ::std::time(&ret), "std::time failed, errno: " << errno << strerror(errno));
return ret;
}
} // namespace common
//isaac namespace IsaacDebugTraceIndent gets shadowed by non-incrementing type inside the first trace. This way the indent is
//consistent within the function
typedef isaac::common::detail::IndentT<1> IsaacDebugTraceIndent;
/**
** \brief Provide a mechanism for detailed level of debugging
**/
#ifdef ISAAC_THREAD_CERR_DEV_TRACE_ENABLED
#define ISAAC_THREAD_CERR_DEV_TRACE(trace) {ISAAC_THREAD_CERR << trace << std::endl;}
#define ISAAC_DEV_TRACE_BLOCK(block) block
#define ISAAC_THREAD_CERR_DEV_TRACE_CLUSTER_ID(clusterId, trace) ISAAC_THREAD_CERR_DEV_TRACE(trace)
#else
#define ISAAC_THREAD_CERR_DEV_TRACE(blah)
#ifdef ISAAC_THREAD_CERR_DEV_TRACE_ENABLED_CLUSTER_ID
#define ISAAC_THREAD_CERR_DEV_TRACE_CLUSTER_ID_INDENTING(clusterId, trace, line) const IsaacDebugTraceIndent indent ## line; typedef isaac::common::detail::IndentBase IsaacDebugTraceIndent; isaac::common::detail::IndentStorer indentStorer ## line(indent ## line); if(ISAAC_THREAD_CERR_DEV_TRACE_ENABLED_CLUSTER_ID == (clusterId)) { ISAAC_THREAD_CERR << indentStorer ## line << trace << std::endl; }
#define ISAAC_THREAD_CERR_DEV_TRACE_CLUSTER_ID_PROXY(clusterId, trace, line) ISAAC_THREAD_CERR_DEV_TRACE_CLUSTER_ID_INDENTING(clusterId, trace, line)
#define ISAAC_THREAD_CERR_DEV_TRACE_CLUSTER_ID(clusterId, trace) ISAAC_THREAD_CERR_DEV_TRACE_CLUSTER_ID_PROXY(clusterId, trace, __LINE__)
#define ISAAC_DEV_TRACE_BLOCK(block) block
#else
#define ISAAC_THREAD_CERR_DEV_TRACE_CLUSTER_ID(clusterId, blah)
#define ISAAC_DEV_TRACE_BLOCK(block)
#endif
#endif
} // namespace isaac
#endif // #ifndef iSAAC_LOG_THREAD_TIMESTAMP_HH
| 29.936102 | 406 | 0.67428 | [
"vector"
] |
a1633de4c82e3c2ca1abd45f27b3316fb40de32b | 96,752 | cc | C++ | Mysql/sql/rpl_rli.cc | clockzhong/WrapLAMP | fa7ad07da3f1759e74966a554befa47bbbbb8dd5 | [
"Apache-2.0"
] | 1 | 2015-12-24T16:44:50.000Z | 2015-12-24T16:44:50.000Z | Mysql/sql/rpl_rli.cc | clockzhong/WrapLAMP | fa7ad07da3f1759e74966a554befa47bbbbb8dd5 | [
"Apache-2.0"
] | 1 | 2015-12-24T18:23:56.000Z | 2015-12-24T18:24:26.000Z | Mysql/sql/rpl_rli.cc | clockzhong/WrapLAMP | fa7ad07da3f1759e74966a554befa47bbbbb8dd5 | [
"Apache-2.0"
] | null | null | null | /* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
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,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
#include "rpl_rli.h"
#include "my_dir.h" // MY_STAT
#include "log.h" // sql_print_error
#include "log_event.h" // Log_event
#include "rpl_group_replication.h" // set_group_replication_retrieved_certifi...
#include "rpl_info_factory.h" // Rpl_info_factory
#include "rpl_mi.h" // Master_info
#include "rpl_msr.h" // channel_map
#include "rpl_rli_pdb.h" // Slave_worker
#include "sql_base.h" // close_thread_tables
#include "strfunc.h" // strconvert
#include "transaction.h" // trans_commit_stmt
#include "pfs_file_provider.h"
#include "mysql/psi/mysql_file.h"
#include <algorithm>
using std::min;
using std::max;
/*
Please every time you add a new field to the relay log info, update
what follows. For now, this is just used to get the number of
fields.
*/
const char* info_rli_fields[]=
{
"number_of_lines",
"group_relay_log_name",
"group_relay_log_pos",
"group_master_log_name",
"group_master_log_pos",
"sql_delay",
"number_of_workers",
"id",
"channel_name"
};
Relay_log_info::Relay_log_info(bool is_slave_recovery
#ifdef HAVE_PSI_INTERFACE
,PSI_mutex_key *param_key_info_run_lock,
PSI_mutex_key *param_key_info_data_lock,
PSI_mutex_key *param_key_info_sleep_lock,
PSI_mutex_key *param_key_info_thd_lock,
PSI_mutex_key *param_key_info_data_cond,
PSI_mutex_key *param_key_info_start_cond,
PSI_mutex_key *param_key_info_stop_cond,
PSI_mutex_key *param_key_info_sleep_cond
#endif
, uint param_id, const char *param_channel,
bool is_rli_fake
)
:Rpl_info("SQL"
#ifdef HAVE_PSI_INTERFACE
,param_key_info_run_lock, param_key_info_data_lock,
param_key_info_sleep_lock, param_key_info_thd_lock,
param_key_info_data_cond, param_key_info_start_cond,
param_key_info_stop_cond, param_key_info_sleep_cond
#endif
, param_id, param_channel
),
replicate_same_server_id(::replicate_same_server_id),
cur_log_fd(-1), relay_log(&sync_relaylog_period, SEQ_READ_APPEND),
is_relay_log_recovery(is_slave_recovery),
save_temporary_tables(0),
cur_log_old_open_count(0), group_relay_log_pos(0), event_relay_log_number(0),
event_relay_log_pos(0), event_start_pos(0),
group_master_log_pos(0),
gtid_set(global_sid_map, global_sid_lock),
rli_fake(is_rli_fake),
gtid_retrieved_initialized(false),
is_group_master_log_pos_invalid(false),
log_space_total(0), ignore_log_space_limit(0),
sql_force_rotate_relay(false),
last_master_timestamp(0), slave_skip_counter(0),
abort_pos_wait(0), until_condition(UNTIL_NONE),
until_log_pos(0),
until_sql_gtids(global_sid_map),
until_sql_gtids_first_event(true),
trans_retries(0), retried_trans(0),
tables_to_lock(0), tables_to_lock_count(0),
rows_query_ev(NULL), last_event_start_time(0), deferred_events(NULL),
workers(PSI_NOT_INSTRUMENTED),
workers_array_initialized(false),
curr_group_assigned_parts(PSI_NOT_INSTRUMENTED),
curr_group_da(PSI_NOT_INSTRUMENTED),
slave_parallel_workers(0),
exit_counter(0),
max_updated_index(0),
recovery_parallel_workers(0), checkpoint_seqno(0),
checkpoint_group(opt_mts_checkpoint_group),
recovery_groups_inited(false), mts_recovery_group_cnt(0),
mts_recovery_index(0), mts_recovery_group_seen_begin(0),
mts_group_status(MTS_NOT_IN_GROUP),
stats_exec_time(0), stats_read_time(0),
least_occupied_workers(PSI_NOT_INSTRUMENTED),
current_mts_submode(0),
reported_unsafe_warning(false), rli_description_event(NULL),
commit_order_mngr(NULL),
sql_delay(0), sql_delay_end(0), m_flags(0), row_stmt_start_timestamp(0),
long_find_row_note_printed(false), error_on_rli_init_info(false),
thd_tx_priority(0)
{
DBUG_ENTER("Relay_log_info::Relay_log_info");
#ifdef HAVE_PSI_INTERFACE
relay_log.set_psi_keys(key_RELAYLOG_LOCK_index,
key_RELAYLOG_LOCK_commit,
key_RELAYLOG_LOCK_commit_queue,
key_RELAYLOG_LOCK_done,
key_RELAYLOG_LOCK_flush_queue,
key_RELAYLOG_LOCK_log,
PSI_NOT_INSTRUMENTED, /* Relaylog doesn't support LOCK_binlog_end_pos */
key_RELAYLOG_LOCK_sync,
key_RELAYLOG_LOCK_sync_queue,
key_RELAYLOG_LOCK_xids,
key_RELAYLOG_COND_done,
key_RELAYLOG_update_cond,
key_RELAYLOG_prep_xids_cond,
key_file_relaylog,
key_file_relaylog_index,
key_file_relaylog_cache,
key_file_relaylog_index_cache);
#endif
group_relay_log_name[0]= event_relay_log_name[0]=
group_master_log_name[0]= 0;
until_log_name[0]= ign_master_log_name_end[0]= 0;
set_timespec_nsec(&last_clock, 0);
memset(&cache_buf, 0, sizeof(cache_buf));
cached_charset_invalidate();
inited_hash_workers= FALSE;
channel_open_temp_tables.atomic_set(0);
if (!rli_fake)
{
mysql_mutex_init(key_relay_log_info_log_space_lock,
&log_space_lock, MY_MUTEX_INIT_FAST);
mysql_cond_init(key_relay_log_info_log_space_cond, &log_space_cond);
mysql_mutex_init(key_mutex_slave_parallel_pend_jobs, &pending_jobs_lock,
MY_MUTEX_INIT_FAST);
mysql_cond_init(key_cond_slave_parallel_pend_jobs, &pending_jobs_cond);
mysql_mutex_init(key_mutex_slave_parallel_worker_count, &exit_count_lock,
MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_mts_temp_table_LOCK, &mts_temp_table_LOCK,
MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_mts_gaq_LOCK, &mts_gaq_LOCK,
MY_MUTEX_INIT_FAST);
mysql_cond_init(key_cond_mts_gaq, &logical_clock_cond);
relay_log.init_pthread_objects();
force_flush_postponed_due_to_split_trans= false;
}
do_server_version_split(::server_version, slave_version_split);
DBUG_VOID_RETURN;
}
/**
The method to invoke at slave threads start
*/
void Relay_log_info::init_workers(ulong n_workers)
{
/*
Parallel slave parameters initialization is done regardless
whether the feature is or going to be active or not.
*/
mts_groups_assigned= mts_events_assigned= pending_jobs= wq_size_waits_cnt= 0;
mts_wq_excess_cnt= mts_wq_no_underrun_cnt= mts_wq_overfill_cnt= 0;
mts_total_wait_overlap= 0;
mts_total_wait_worker_avail= 0;
mts_last_online_stat= 0;
workers.reserve(n_workers);
workers_array_initialized= true; //set after init
}
/**
The method to invoke at slave threads stop
*/
void Relay_log_info::deinit_workers()
{
workers.clear();
}
Relay_log_info::~Relay_log_info()
{
DBUG_ENTER("Relay_log_info::~Relay_log_info");
if(!rli_fake)
{
if (recovery_groups_inited)
bitmap_free(&recovery_groups);
delete current_mts_submode;
if(workers_copy_pfs.size())
{
for (int i= static_cast<int>(workers_copy_pfs.size()) - 1; i >= 0; i--)
delete workers_copy_pfs[i];
workers_copy_pfs.clear();
}
mysql_mutex_destroy(&log_space_lock);
mysql_cond_destroy(&log_space_cond);
mysql_mutex_destroy(&pending_jobs_lock);
mysql_cond_destroy(&pending_jobs_cond);
mysql_mutex_destroy(&exit_count_lock);
mysql_mutex_destroy(&mts_temp_table_LOCK);
mysql_mutex_destroy(&mts_gaq_LOCK);
mysql_cond_destroy(&logical_clock_cond);
relay_log.cleanup();
}
set_rli_description_event(NULL);
DBUG_VOID_RETURN;
}
/**
Method is called when MTS coordinator senses the relay-log name
has been changed.
It marks each Worker member with this fact to make an action
at time it will distribute a terminal event of a group to the Worker.
Worker receives the new name at the group commiting phase
@c Slave_worker::slave_worker_ends_group().
*/
void Relay_log_info::reset_notified_relay_log_change()
{
if (!is_parallel_exec())
return;
for (Slave_worker **it= workers.begin(); it != workers.end(); ++it)
{
Slave_worker *w= *it;
w->relay_log_change_notified= FALSE;
}
}
/**
This method is called in mts_checkpoint_routine() to mark that each
worker is required to adapt to a new checkpoint data whose coordinates
are passed to it through GAQ index.
Worker notices the new checkpoint value at the group commit to reset
the current bitmap and starts using the clean bitmap indexed from zero
of being reset checkpoint_seqno.
New seconds_behind_master timestamp is installed.
@param shift number of bits to shift by Worker due to the
current checkpoint change.
@param new_ts new seconds_behind_master timestamp value
unless zero. Zero could be due to FD event.
@param need_data_lock False if caller has locked @c data_lock
*/
void Relay_log_info::reset_notified_checkpoint(ulong shift, time_t new_ts,
bool need_data_lock)
{
/*
If this is not a parallel execution we return immediately.
*/
if (!is_parallel_exec())
return;
for (Slave_worker **it= workers.begin(); it != workers.end(); ++it)
{
Slave_worker *w= *it;
/*
Reseting the notification information in order to force workers to
assign jobs with the new updated information.
Notice that the bitmap_shifted is accumulated to indicate how many
consecutive jobs were successfully processed.
The worker when assigning a new job will set the value back to
zero.
*/
w->checkpoint_notified= FALSE;
w->bitmap_shifted= w->bitmap_shifted + shift;
/*
Zero shift indicates the caller rotates the master binlog.
The new name will be passed to W through the group descriptor
during the first post-rotation time scheduling.
*/
if (shift == 0)
w->master_log_change_notified= false;
DBUG_PRINT("mts", ("reset_notified_checkpoint shift --> %lu, "
"worker->bitmap_shifted --> %lu, worker --> %u.",
shift, w->bitmap_shifted,
static_cast<unsigned>(it - workers.begin())));
}
/*
There should not be a call where (shift == 0 && checkpoint_seqno != 0).
Then the new checkpoint sequence is updated by subtracting the number
of consecutive jobs that were successfully processed.
*/
DBUG_ASSERT(current_mts_submode->get_type() != MTS_PARALLEL_TYPE_DB_NAME ||
!(shift == 0 && checkpoint_seqno != 0));
checkpoint_seqno= checkpoint_seqno - shift;
DBUG_PRINT("mts", ("reset_notified_checkpoint shift --> %lu, "
"checkpoint_seqno --> %u.", shift, checkpoint_seqno));
if (new_ts)
{
if (need_data_lock)
mysql_mutex_lock(&data_lock);
else
mysql_mutex_assert_owner(&data_lock);
last_master_timestamp= new_ts;
if (need_data_lock)
mysql_mutex_unlock(&data_lock);
}
}
/**
Reset recovery info from Worker info table and
mark MTS recovery is completed.
@return false on success true when @c reset_notified_checkpoint failed.
*/
bool Relay_log_info::mts_finalize_recovery()
{
bool ret= false;
uint i;
uint repo_type= get_rpl_info_handler()->get_rpl_info_type();
DBUG_ENTER("Relay_log_info::mts_finalize_recovery");
for (Slave_worker **it= workers.begin(); !ret && it != workers.end(); ++it)
{
Slave_worker *w= *it;
ret= w->reset_recovery_info();
DBUG_EXECUTE_IF("mts_debug_recovery_reset_fails", ret= true;);
}
/*
The loop is traversed in the worker index descending order due
to specifics of the Worker table repository that does not like
even temporary holes. Therefore stale records are deleted
from the tail.
*/
DBUG_EXECUTE_IF("enable_mts_wokrer_failure_in_recovery_finalize",
{DBUG_SET("+d,mts_worker_thread_init_fails");});
for (i= recovery_parallel_workers; i > workers.size() && !ret; i--)
{
Slave_worker *w=
Rpl_info_factory::create_worker(repo_type, i - 1, this, true);
/*
If an error occurs during the above create_worker call, the newly created
worker object gets deleted within the above function call itself and only
NULL is returned. Hence the following check has been added to verify
that a valid worker object exists.
*/
if (w)
{
ret= w->remove_info();
delete w;
}
else
{
ret= true;
goto err;
}
}
recovery_parallel_workers= slave_parallel_workers;
err:
DBUG_RETURN(ret);
}
static inline int add_relay_log(Relay_log_info* rli,LOG_INFO* linfo)
{
MY_STAT s;
DBUG_ENTER("add_relay_log");
if (!mysql_file_stat(key_file_relaylog,
linfo->log_file_name, &s, MYF(0)))
{
sql_print_error("log %s listed in the index, but failed to stat.",
linfo->log_file_name);
DBUG_RETURN(1);
}
rli->log_space_total += s.st_size;
#ifndef DBUG_OFF
char buf[22];
DBUG_PRINT("info",("log_space_total: %s", llstr(rli->log_space_total,buf)));
#endif
DBUG_RETURN(0);
}
int Relay_log_info::count_relay_log_space()
{
LOG_INFO flinfo;
DBUG_ENTER("Relay_log_info::count_relay_log_space");
log_space_total= 0;
if (relay_log.find_log_pos(&flinfo, NullS, 1))
{
sql_print_error("Could not find first log while counting relay log space.");
DBUG_RETURN(1);
}
do
{
if (add_relay_log(this, &flinfo))
DBUG_RETURN(1);
} while (!relay_log.find_next_log(&flinfo, 1));
/*
As we have counted everything, including what may have written in a
preceding write, we must reset bytes_written, or we may count some space
twice.
*/
relay_log.reset_bytes_written();
DBUG_RETURN(0);
}
/**
Resets UNTIL condition for Relay_log_info
*/
void Relay_log_info::clear_until_condition()
{
DBUG_ENTER("clear_until_condition");
until_condition= Relay_log_info::UNTIL_NONE;
until_log_name[0]= 0;
until_log_pos= 0;
until_sql_gtids.clear();
until_sql_gtids_first_event= true;
DBUG_VOID_RETURN;
}
/**
Opens and intialize the given relay log. Specifically, it does what follows:
- Closes old open relay log files.
- If we are using the same relay log as the running IO-thread, then sets.
rli->cur_log to point to the same IO_CACHE entry.
- If not, opens the 'log' binary file.
@todo check proper initialization of
group_master_log_name/group_master_log_pos. /alfranio
@param rli[in] Relay information (will be initialized)
@param log[in] Name of relay log file to read from. NULL = First log
@param pos[in] Position in relay log file
@param need_data_lock[in] If true, this function will acquire the
relay_log.data_lock(); otherwise the caller should already have
acquired it.
@param errmsg[out] On error, this function will store a pointer to
an error message here
@param keep_looking_for_fd[in] If true, this function will
look for a Format_description_log_event. We only need this when the
SQL thread starts and opens an existing relay log and has to execute
it (possibly from an offset >4); then we need to read the first
event of the relay log to be able to parse the events we have to
execute.
@retval 0 ok,
@retval 1 error. In this case, *errmsg is set to point to the error
message.
*/
int Relay_log_info::init_relay_log_pos(const char* log,
ulonglong pos, bool need_data_lock,
const char** errmsg,
bool keep_looking_for_fd)
{
DBUG_ENTER("Relay_log_info::init_relay_log_pos");
DBUG_PRINT("info", ("pos: %lu", (ulong) pos));
*errmsg=0;
const char* errmsg_fmt= 0;
static char errmsg_buff[MYSQL_ERRMSG_SIZE + FN_REFLEN];
mysql_mutex_t *log_lock= relay_log.get_log_lock();
if (need_data_lock)
mysql_mutex_lock(&data_lock);
else
mysql_mutex_assert_owner(&data_lock);
/*
By default the relay log is in binlog format 3 (4.0).
Even if format is 4, this will work enough to read the first event
(Format_desc) (remember that format 4 is just lenghtened compared to format
3; format 3 is a prefix of format 4).
*/
set_rli_description_event(new Format_description_log_event(3));
mysql_mutex_lock(log_lock);
/* Close log file and free buffers if it's already open */
if (cur_log_fd >= 0)
{
end_io_cache(&cache_buf);
mysql_file_close(cur_log_fd, MYF(MY_WME));
cur_log_fd = -1;
}
group_relay_log_pos= event_relay_log_pos= pos;
/*
Test to see if the previous run was with the skip of purging
If yes, we do not purge when we restart
*/
if (relay_log.find_log_pos(&linfo, NullS, 1))
{
*errmsg="Could not find first log during relay log initialization";
goto err;
}
if (log && relay_log.find_log_pos(&linfo, log, 1))
{
errmsg_fmt= "Could not find target log file mentioned in "
"relay log info in the index file '%s' during "
"relay log initialization";
sprintf(errmsg_buff, errmsg_fmt, relay_log.get_index_fname());
*errmsg= errmsg_buff;
goto err;
}
set_group_relay_log_name(linfo.log_file_name);
set_event_relay_log_name(linfo.log_file_name);
if (relay_log.is_active(linfo.log_file_name))
{
/*
The IO thread is using this log file.
In this case, we will use the same IO_CACHE pointer to
read data as the IO thread is using to write data.
*/
my_b_seek((cur_log=relay_log.get_log_file()), (off_t)0);
if (check_binlog_magic(cur_log, errmsg))
goto err;
cur_log_old_open_count=relay_log.get_open_count();
}
else
{
/*
Open the relay log and set cur_log to point at this one
*/
if ((cur_log_fd=open_binlog_file(&cache_buf,
linfo.log_file_name,errmsg)) < 0)
goto err;
cur_log = &cache_buf;
}
/*
In all cases, check_binlog_magic() has been called so we're at offset 4 for
sure.
*/
if (pos > BIN_LOG_HEADER_SIZE) /* If pos<=4, we stay at 4 */
{
Log_event* ev;
while (keep_looking_for_fd)
{
/*
Read the possible Format_description_log_event; if position
was 4, no need, it will be read naturally.
*/
DBUG_PRINT("info",("looking for a Format_description_log_event"));
if (my_b_tell(cur_log) >= pos)
break;
/*
Because of we have data_lock and log_lock, we can safely read an
event
*/
if (!(ev= Log_event::read_log_event(cur_log, 0,
rli_description_event,
opt_slave_sql_verify_checksum)))
{
DBUG_PRINT("info",("could not read event, cur_log->error=%d",
cur_log->error));
if (cur_log->error) /* not EOF */
{
*errmsg= "I/O error reading event at position 4";
goto err;
}
break;
}
else if (ev->get_type_code() == binary_log::FORMAT_DESCRIPTION_EVENT)
{
DBUG_PRINT("info",("found Format_description_log_event"));
set_rli_description_event((Format_description_log_event *)ev);
/*
As ev was returned by read_log_event, it has passed is_valid(), so
my_malloc() in ctor worked, no need to check again.
*/
/*
Ok, we found a Format_description event. But it is not sure that this
describes the whole relay log; indeed, one can have this sequence
(starting from position 4):
Format_desc (of slave)
Previous-GTIDs (of slave IO thread, if GTIDs are enabled)
Rotate (of master)
Format_desc (of master)
So the Format_desc which really describes the rest of the relay log
can be the 3rd or the 4th event (depending on GTIDs being enabled or
not, it can't be further than that, because we rotate
the relay log when we queue a Rotate event from the master).
But what describes the Rotate is the first Format_desc.
So what we do is:
go on searching for Format_description events, until you exceed the
position (argument 'pos') or until you find an event other than
Previous-GTIDs, Rotate or Format_desc.
*/
}
else
{
DBUG_PRINT("info",("found event of another type=%d",
ev->get_type_code()));
keep_looking_for_fd=
(ev->get_type_code() == binary_log::ROTATE_EVENT ||
ev->get_type_code() == binary_log::PREVIOUS_GTIDS_LOG_EVENT);
delete ev;
}
}
my_b_seek(cur_log,(off_t)pos);
#ifndef DBUG_OFF
{
char llbuf1[22], llbuf2[22];
DBUG_PRINT("info", ("my_b_tell(cur_log)=%s >event_relay_log_pos=%s",
llstr(my_b_tell(cur_log),llbuf1),
llstr(get_event_relay_log_pos(),llbuf2)));
}
#endif
}
err:
/*
If we don't purge, we can't honour relay_log_space_limit ;
silently discard it
*/
if (!relay_log_purge)
{
log_space_limit= 0; // todo: consider to throw a warning at least
}
mysql_cond_broadcast(&data_cond);
mysql_mutex_unlock(log_lock);
if (need_data_lock)
mysql_mutex_unlock(&data_lock);
if (!rli_description_event->is_valid() && !*errmsg)
*errmsg= "Invalid Format_description log event; could be out of memory";
DBUG_RETURN ((*errmsg) ? 1 : 0);
}
/**
Update the error number, message and timestamp fields. This function is
different from va_report() as va_report() also logs the error message in the
log apart from updating the error fields.
SYNOPSIS
@param[in] level specifies the level- error, warning or information,
@param[in] err_code error number,
@param[in] buff_coord error message to be used.
*/
void Relay_log_info::fill_coord_err_buf(loglevel level, int err_code,
const char *buff_coord) const
{
mysql_mutex_lock(&err_lock);
if(level == ERROR_LEVEL)
{
m_last_error.number = err_code;
strncpy(m_last_error.message, buff_coord, MAX_SLAVE_ERRMSG);
m_last_error.update_timestamp();
}
mysql_mutex_unlock(&err_lock);
}
/**
Waits until the SQL thread reaches (has executed up to) the
log/position or timed out.
SYNOPSIS
@param[in] thd client thread that sent @c SELECT @c MASTER_POS_WAIT,
@param[in] log_name log name to wait for,
@param[in] log_pos position to wait for,
@param[in] timeout @c timeout in seconds before giving up waiting.
@c timeout is longlong whereas it should be ulong; but this is
to catch if the user submitted a negative timeout.
@retval -2 improper arguments (log_pos<0)
or slave not running, or master info changed
during the function's execution,
or client thread killed. -2 is translated to NULL by caller,
@retval -1 timed out
@retval >=0 number of log events the function had to wait
before reaching the desired log/position
*/
int Relay_log_info::wait_for_pos(THD* thd, String* log_name,
longlong log_pos,
longlong timeout)
{
int event_count = 0;
ulong init_abort_pos_wait;
int error=0;
struct timespec abstime; // for timeout checking
PSI_stage_info old_stage;
DBUG_ENTER("Relay_log_info::wait_for_pos");
if (!inited)
DBUG_RETURN(-2);
DBUG_PRINT("enter",("log_name: '%s' log_pos: %lu timeout: %lu",
log_name->c_ptr_safe(), (ulong) log_pos, (ulong) timeout));
set_timespec(&abstime, timeout);
mysql_mutex_lock(&data_lock);
thd->ENTER_COND(&data_cond, &data_lock,
&stage_waiting_for_the_slave_thread_to_advance_position,
&old_stage);
/*
This function will abort when it notices that some CHANGE MASTER or
RESET MASTER has changed the master info.
To catch this, these commands modify abort_pos_wait ; We just monitor
abort_pos_wait and see if it has changed.
Why do we have this mechanism instead of simply monitoring slave_running
in the loop (we do this too), as CHANGE MASTER/RESET SLAVE require that
the SQL thread be stopped?
This is becasue if someones does:
STOP SLAVE;CHANGE MASTER/RESET SLAVE; START SLAVE;
the change may happen very quickly and we may not notice that
slave_running briefly switches between 1/0/1.
*/
init_abort_pos_wait= abort_pos_wait;
/*
We'll need to
handle all possible log names comparisons (e.g. 999 vs 1000).
We use ulong for string->number conversion ; this is no
stronger limitation than in find_uniq_filename in sql/log.cc
*/
ulong log_name_extension;
char log_name_tmp[FN_REFLEN]; //make a char[] from String
strmake(log_name_tmp, log_name->ptr(), min<uint32>(log_name->length(), FN_REFLEN-1));
char *p= fn_ext(log_name_tmp);
char *p_end;
if (!*p || log_pos<0)
{
error= -2; //means improper arguments
goto err;
}
// Convert 0-3 to 4
log_pos= max(log_pos, static_cast<longlong>(BIN_LOG_HEADER_SIZE));
/* p points to '.' */
log_name_extension= strtoul(++p, &p_end, 10);
/*
p_end points to the first invalid character.
If it equals to p, no digits were found, error.
If it contains '\0' it means conversion went ok.
*/
if (p_end==p || *p_end)
{
error= -2;
goto err;
}
/* The "compare and wait" main loop */
while (!thd->killed &&
init_abort_pos_wait == abort_pos_wait &&
slave_running)
{
bool pos_reached;
int cmp_result= 0;
DBUG_PRINT("info",
("init_abort_pos_wait: %ld abort_pos_wait: %ld",
init_abort_pos_wait, abort_pos_wait));
DBUG_PRINT("info",("group_master_log_name: '%s' pos: %lu",
group_master_log_name, (ulong) group_master_log_pos));
/*
group_master_log_name can be "", if we are just after a fresh
replication start or after a CHANGE MASTER TO MASTER_HOST/PORT
(before we have executed one Rotate event from the master) or
(rare) if the user is doing a weird slave setup (see next
paragraph). If group_master_log_name is "", we assume we don't
have enough info to do the comparison yet, so we just wait until
more data. In this case master_log_pos is always 0 except if
somebody (wrongly) sets this slave to be a slave of itself
without using --replicate-same-server-id (an unsupported
configuration which does nothing), then group_master_log_pos
will grow and group_master_log_name will stay "".
Also in case the group master log position is invalid (e.g. after
CHANGE MASTER TO RELAY_LOG_POS ), we will wait till the first event
is read and the log position is valid again.
*/
if (*group_master_log_name && !is_group_master_log_pos_invalid)
{
char *basename= (group_master_log_name +
dirname_length(group_master_log_name));
/*
First compare the parts before the extension.
Find the dot in the master's log basename,
and protect against user's input error :
if the names do not match up to '.' included, return error
*/
char *q= (fn_ext(basename)+1);
if (strncmp(basename, log_name_tmp, (int)(q-basename)))
{
error= -2;
break;
}
// Now compare extensions.
char *q_end;
ulong group_master_log_name_extension= strtoul(q, &q_end, 10);
if (group_master_log_name_extension < log_name_extension)
cmp_result= -1 ;
else
cmp_result= (group_master_log_name_extension > log_name_extension) ? 1 : 0 ;
pos_reached= ((!cmp_result && group_master_log_pos >= (ulonglong)log_pos) ||
cmp_result > 0);
if (pos_reached || thd->killed)
break;
}
//wait for master update, with optional timeout.
DBUG_PRINT("info",("Waiting for master update"));
/*
We are going to mysql_cond_(timed)wait(); if the SQL thread stops it
will wake us up.
*/
thd_wait_begin(thd, THD_WAIT_BINLOG);
if (timeout > 0)
{
/*
Note that mysql_cond_timedwait checks for the timeout
before for the condition ; i.e. it returns ETIMEDOUT
if the system time equals or exceeds the time specified by abstime
before the condition variable is signaled or broadcast, _or_ if
the absolute time specified by abstime has already passed at the time
of the call.
For that reason, mysql_cond_timedwait will do the "timeoutting" job
even if its condition is always immediately signaled (case of a loaded
master).
*/
error= mysql_cond_timedwait(&data_cond, &data_lock, &abstime);
}
else
mysql_cond_wait(&data_cond, &data_lock);
thd_wait_end(thd);
DBUG_PRINT("info",("Got signal of master update or timed out"));
if (error == ETIMEDOUT || error == ETIME)
{
#ifndef DBUG_OFF
/*
Doing this to generate a stack trace and make debugging
easier.
*/
if (DBUG_EVALUATE_IF("debug_crash_slave_time_out", 1, 0))
DBUG_ASSERT(0);
#endif
error= -1;
break;
}
error=0;
event_count++;
DBUG_PRINT("info",("Testing if killed or SQL thread not running"));
}
err:
mysql_mutex_unlock(&data_lock);
thd->EXIT_COND(&old_stage);
DBUG_PRINT("exit",("killed: %d abort: %d slave_running: %d \
improper_arguments: %d timed_out: %d",
thd->killed_errno(),
(int) (init_abort_pos_wait != abort_pos_wait),
(int) slave_running,
(int) (error == -2),
(int) (error == -1)));
if (thd->killed || init_abort_pos_wait != abort_pos_wait ||
!slave_running)
{
error= -2;
}
DBUG_RETURN( error ? error : event_count );
}
int Relay_log_info::wait_for_gtid_set(THD* thd, String* gtid,
longlong timeout)
{
DBUG_ENTER("Relay_log_info::wait_for_gtid_set(thd, String, timeout)");
DBUG_PRINT("info", ("Waiting for %s timeout %lld", gtid->c_ptr_safe(),
timeout));
Gtid_set wait_gtid_set(global_sid_map);
global_sid_lock->rdlock();
if (wait_gtid_set.add_gtid_text(gtid->c_ptr_safe()) != RETURN_STATUS_OK)
{
global_sid_lock->unlock();
DBUG_PRINT("exit",("improper gtid argument"));
DBUG_RETURN(-2);
}
global_sid_lock->unlock();
DBUG_RETURN(wait_for_gtid_set(thd, &wait_gtid_set, timeout));
}
/*
TODO: This is a duplicated code that needs to be simplified.
This will be done while developing all possible sync options.
See WL#3584's specification.
/Alfranio
*/
int Relay_log_info::wait_for_gtid_set(THD* thd, const Gtid_set* wait_gtid_set,
longlong timeout)
{
int event_count = 0;
ulong init_abort_pos_wait;
int error=0;
struct timespec abstime; // for timeout checking
PSI_stage_info old_stage;
DBUG_ENTER("Relay_log_info::wait_for_gtid_set(thd, gtid_set, timeout)");
if (!inited)
DBUG_RETURN(-2);
set_timespec(&abstime, timeout);
mysql_mutex_lock(&data_lock);
thd->ENTER_COND(&data_cond, &data_lock,
&stage_waiting_for_the_slave_thread_to_advance_position,
&old_stage);
/*
This function will abort when it notices that some CHANGE MASTER or
RESET MASTER has changed the master info.
To catch this, these commands modify abort_pos_wait ; We just monitor
abort_pos_wait and see if it has changed.
Why do we have this mechanism instead of simply monitoring slave_running
in the loop (we do this too), as CHANGE MASTER/RESET SLAVE require that
the SQL thread be stopped?
This is becasue if someones does:
STOP SLAVE;CHANGE MASTER/RESET SLAVE; START SLAVE;
the change may happen very quickly and we may not notice that
slave_running briefly switches between 1/0/1.
*/
init_abort_pos_wait= abort_pos_wait;
/* The "compare and wait" main loop */
while (!thd->killed &&
init_abort_pos_wait == abort_pos_wait &&
slave_running)
{
DBUG_PRINT("info",
("init_abort_pos_wait: %ld abort_pos_wait: %ld",
init_abort_pos_wait, abort_pos_wait));
//wait for master update, with optional timeout.
global_sid_lock->wrlock();
const Gtid_set* executed_gtids= gtid_state->get_executed_gtids();
const Owned_gtids* owned_gtids= gtid_state->get_owned_gtids();
char *wait_gtid_set_buf;
wait_gtid_set->to_string(&wait_gtid_set_buf);
DBUG_PRINT("info", ("Waiting for '%s'. is_subset: %d and "
"!is_intersection_nonempty: %d",
wait_gtid_set_buf,
wait_gtid_set->is_subset(executed_gtids),
!owned_gtids->is_intersection_nonempty(wait_gtid_set)));
my_free(wait_gtid_set_buf);
executed_gtids->dbug_print("gtid_executed:");
owned_gtids->dbug_print("owned_gtids:");
/*
Since commit is performed after log to binary log, we must also
check if any GTID of wait_gtid_set is not yet committed.
*/
if (wait_gtid_set->is_subset(executed_gtids) &&
!owned_gtids->is_intersection_nonempty(wait_gtid_set))
{
global_sid_lock->unlock();
break;
}
global_sid_lock->unlock();
DBUG_PRINT("info",("Waiting for master update"));
/*
We are going to mysql_cond_(timed)wait(); if the SQL thread stops it
will wake us up.
*/
thd_wait_begin(thd, THD_WAIT_BINLOG);
if (timeout > 0)
{
/*
Note that mysql_cond_timedwait checks for the timeout
before for the condition ; i.e. it returns ETIMEDOUT
if the system time equals or exceeds the time specified by abstime
before the condition variable is signaled or broadcast, _or_ if
the absolute time specified by abstime has already passed at the time
of the call.
For that reason, mysql_cond_timedwait will do the "timeoutting" job
even if its condition is always immediately signaled (case of a loaded
master).
*/
error= mysql_cond_timedwait(&data_cond, &data_lock, &abstime);
}
else
mysql_cond_wait(&data_cond, &data_lock);
thd_wait_end(thd);
DBUG_PRINT("info",("Got signal of master update or timed out"));
if (error == ETIMEDOUT || error == ETIME)
{
#ifndef DBUG_OFF
/*
Doing this to generate a stack trace and make debugging
easier.
*/
if (DBUG_EVALUATE_IF("debug_crash_slave_time_out", 1, 0))
DBUG_ASSERT(0);
#endif
error= -1;
break;
}
error=0;
event_count++;
DBUG_PRINT("info",("Testing if killed or SQL thread not running"));
}
mysql_mutex_unlock(&data_lock);
thd->EXIT_COND(&old_stage);
DBUG_PRINT("exit",("killed: %d abort: %d slave_running: %d \
improper_arguments: %d timed_out: %d",
thd->killed_errno(),
(int) (init_abort_pos_wait != abort_pos_wait),
(int) slave_running,
(int) (error == -2),
(int) (error == -1)));
if (thd->killed || init_abort_pos_wait != abort_pos_wait ||
!slave_running)
{
error= -2;
}
DBUG_RETURN( error ? error : event_count );
}
int Relay_log_info::inc_group_relay_log_pos(ulonglong log_pos,
bool need_data_lock)
{
int error= 0;
DBUG_ENTER("Relay_log_info::inc_group_relay_log_pos");
if (need_data_lock)
mysql_mutex_lock(&data_lock);
else
mysql_mutex_assert_owner(&data_lock);
inc_event_relay_log_pos();
group_relay_log_pos= event_relay_log_pos;
strmake(group_relay_log_name,event_relay_log_name,
sizeof(group_relay_log_name)-1);
notify_group_relay_log_name_update();
/*
In 4.x we used the event's len to compute the positions here. This is
wrong if the event was 3.23/4.0 and has been converted to 5.0, because
then the event's len is not what is was in the master's binlog, so this
will make a wrong group_master_log_pos (yes it's a bug in 3.23->4.0
replication: Exec_master_log_pos is wrong). Only way to solve this is to
have the original offset of the end of the event the relay log. This is
what we do in 5.0: log_pos has become "end_log_pos" (because the real use
of log_pos in 4.0 was to compute the end_log_pos; so better to store
end_log_pos instead of begin_log_pos.
If we had not done this fix here, the problem would also have appeared
when the slave and master are 5.0 but with different event length (for
example the slave is more recent than the master and features the event
UID). It would give false MASTER_POS_WAIT, false Exec_master_log_pos in
SHOW SLAVE STATUS, and so the user would do some CHANGE MASTER using this
value which would lead to badly broken replication.
Even the relay_log_pos will be corrupted in this case, because the len is
the relay log is not "val".
With the end_log_pos solution, we avoid computations involving lengthes.
*/
DBUG_PRINT("info", ("log_pos: %lu group_master_log_pos: %lu",
(long) log_pos, (long) group_master_log_pos));
if (log_pos > 0) // 3.23 binlogs don't have log_posx
group_master_log_pos= log_pos;
/*
If the master log position was invalidiated by say, "CHANGE MASTER TO
RELAY_LOG_POS=N", it is now valid,
*/
if (is_group_master_log_pos_invalid)
is_group_master_log_pos_invalid= false;
/*
In MTS mode FD or Rotate event commit their solitary group to
Coordinator's info table. Callers make sure that Workers have been
executed all assignements.
Broadcast to master_pos_wait() waiters should be done after
the table is updated.
*/
DBUG_ASSERT(!is_parallel_exec() ||
mts_group_status != Relay_log_info::MTS_IN_GROUP);
/*
We do not force synchronization at this point, note the
parameter false, because a non-transactional change is
being committed.
For that reason, the synchronization here is subjected to
the option sync_relay_log_info.
See sql/rpl_rli.h for further information on this behavior.
*/
error= flush_info(FALSE);
mysql_cond_broadcast(&data_cond);
if (need_data_lock)
mysql_mutex_unlock(&data_lock);
DBUG_RETURN(error);
}
void Relay_log_info::close_temporary_tables()
{
TABLE *table,*next;
int num_closed_temp_tables= 0;
DBUG_ENTER("Relay_log_info::close_temporary_tables");
for (table=save_temporary_tables ; table ; table=next)
{
next=table->next;
/*
Don't ask for disk deletion. For now, anyway they will be deleted when
slave restarts, but it is a better intention to not delete them.
*/
DBUG_PRINT("info", ("table: 0x%lx", (long) table));
close_temporary(table, 1, 0);
num_closed_temp_tables++;
}
save_temporary_tables= 0;
slave_open_temp_tables.atomic_add(-num_closed_temp_tables);
channel_open_temp_tables.atomic_add(-num_closed_temp_tables);
DBUG_VOID_RETURN;
}
/**
Purges relay logs. It assumes to have a run lock on rli and that no
slave thread are running.
@param[in] THD connection,
@param[in] just_reset if false, it tells that logs should be purged
and @c init_relay_log_pos() should be called,
@errmsg[out] errmsg store pointer to an error message.
@retval 0 successfuly executed,
@retval 1 otherwise error, where errmsg is set to point to the error message.
*/
int Relay_log_info::purge_relay_logs(THD *thd, bool just_reset,
const char** errmsg, bool delete_only)
{
int error=0;
DBUG_ENTER("Relay_log_info::purge_relay_logs");
/*
Even if inited==0, we still try to empty master_log_* variables. Indeed,
inited==0 does not imply that they already are empty.
It could be that slave's info initialization partly succeeded: for example
if relay-log.info existed but *relay-bin*.* have been manually removed,
init_info reads the old relay-log.info and fills rli->master_log_*, then
init_info checks for the existence of the relay log, this fails and
init_info leaves inited to 0.
In that pathological case, master_log_pos* will be properly reinited at
the next START SLAVE (as RESET SLAVE or CHANGE MASTER, the callers of
purge_relay_logs, will delete bogus *.info files or replace them with
correct files), however if the user does SHOW SLAVE STATUS before START
SLAVE, he will see old, confusing master_log_*. In other words, we reinit
master_log_* for SHOW SLAVE STATUS to display fine in any case.
*/
group_master_log_name[0]= 0;
group_master_log_pos= 0;
/*
Following the the relay log purge, the master_log_pos will be in sync
with relay_log_pos, so the flag should be cleared. Refer bug#11766010.
*/
is_group_master_log_pos_invalid= false;
if (!inited)
{
DBUG_PRINT("info", ("inited == 0"));
DBUG_RETURN(0);
}
DBUG_ASSERT(slave_running == 0);
DBUG_ASSERT(mi->slave_running == 0);
/* Reset the transaction boundary parser and clear the last GTID queued */
mi->transaction_parser.reset();
mi->clear_last_gtid_queued();
slave_skip_counter= 0;
mysql_mutex_lock(&data_lock);
/*
we close the relay log fd possibly left open by the slave SQL thread,
to be able to delete it; the relay log fd possibly left open by the slave
I/O thread will be closed naturally in reset_logs() by the
close(LOG_CLOSE_TO_BE_OPENED) call
*/
if (cur_log_fd >= 0)
{
end_io_cache(&cache_buf);
my_close(cur_log_fd, MYF(MY_WME));
cur_log_fd= -1;
}
if (relay_log.reset_logs(thd, delete_only))
{
*errmsg = "Failed during log reset";
error=1;
goto err;
}
/**
Clear the retrieved gtid set for this channel.
global_sid_lock->wrlock() is needed.
*/
global_sid_lock->wrlock();
(const_cast<Gtid_set *>(get_gtid_set()))->clear();
global_sid_lock->unlock();
/* Save name of used relay log file */
set_group_relay_log_name(relay_log.get_log_fname());
set_event_relay_log_name(relay_log.get_log_fname());
group_relay_log_pos= event_relay_log_pos= BIN_LOG_HEADER_SIZE;
if (!delete_only && count_relay_log_space())
{
*errmsg= "Error counting relay log space";
error= 1;
goto err;
}
if (!just_reset)
error= init_relay_log_pos(group_relay_log_name,
group_relay_log_pos,
false/*need_data_lock=false*/, errmsg, 0);
err:
#ifndef DBUG_OFF
char buf[22];
#endif
DBUG_PRINT("info",("log_space_total: %s",llstr(log_space_total,buf)));
mysql_mutex_unlock(&data_lock);
DBUG_RETURN(error);
}
/*
When --relay-bin option is not provided, the names of the
relay log files are host-relay-bin.0000x or
host-relay-bin-CHANNEL.00000x in the case of MSR.
However, if that option is provided, then the names of the
relay log files are <relay-bin-option>.0000x or
<relay-bin-option>-CHANNEL.00000x in the case of MSR.
The function adds a channel suffix (according to the channel to file name
conventions and conversions) to the relay log file.
@todo: truncate the log file if length exceeds.
*/
const char*
Relay_log_info::add_channel_to_relay_log_name(char *buff, uint buff_size,
const char *base_name)
{
char *ptr;
char channel_to_file[FN_REFLEN];
uint errors, length;
uint base_name_len;
uint suffix_buff_size;
DBUG_ASSERT(base_name !=NULL);
base_name_len= strlen(base_name);
suffix_buff_size= buff_size - base_name_len;
ptr= strmake(buff, base_name, buff_size-1);
if (channel[0])
{
/* adding a "-" */
ptr= strmake(ptr, "-", suffix_buff_size-1);
/*
Convert the channel name to the file names charset.
Channel name is in system_charset which is UTF8_general_ci
as it was defined as utf8 in the mysql.slaveinfo tables.
*/
length= strconvert(system_charset_info, channel, &my_charset_filename,
channel_to_file, NAME_LEN, &errors);
ptr= strmake(ptr, channel_to_file, suffix_buff_size-length-1);
}
return (const char*)buff;
}
/**
Checks if condition stated in UNTIL clause of START SLAVE is reached.
Specifically, it checks if UNTIL condition is reached. Uses caching result
of last comparison of current log file name and target log file name. So
cached value should be invalidated if current log file name changes (see
@c Relay_log_info::notify_... functions).
This caching is needed to avoid of expensive string comparisons and
@c strtol() conversions needed for log names comparison. We don't need to
compare them each time this function is called, we only need to do this
when current log name changes. If we have @c UNTIL_MASTER_POS condition we
need to do this only after @c Rotate_log_event::do_apply_event() (which is
rare, so caching gives real benifit), and if we have @c UNTIL_RELAY_POS
condition then we should invalidate cached comarison value after
@c inc_group_relay_log_pos() which called for each group of events (so we
have some benefit if we have something like queries that use
autoincrement or if we have transactions).
Should be called ONLY if @c until_condition @c != @c UNTIL_NONE !
@param master_beg_pos position of the beginning of to be executed event
(not @c log_pos member of the event that points to
the beginning of the following event)
@retval true condition met or error happened (condition seems to have
bad log file name),
@retval false condition not met.
*/
bool Relay_log_info::is_until_satisfied(THD *thd, Log_event *ev)
{
char error_msg[]= "Slave SQL thread is stopped because UNTIL "
"condition is bad.";
DBUG_ENTER("Relay_log_info::is_until_satisfied");
switch (until_condition)
{
case UNTIL_MASTER_POS:
case UNTIL_RELAY_POS:
{
const char *log_name= NULL;
ulonglong log_pos= 0;
if (until_condition == UNTIL_MASTER_POS)
{
if (ev && ev->server_id == (uint32) ::server_id && !replicate_same_server_id)
DBUG_RETURN(false);
/*
Rotate events originating from the slave have server_id==0,
and their log_pos is relative to the slave, so in case their
log_pos is greater than the log_pos we are waiting for, they
can cause the slave to stop prematurely. So we ignore such
events.
*/
if (ev && ev->server_id == 0)
DBUG_RETURN(false);
log_name= group_master_log_name;
if (!ev || is_in_group() || !ev->common_header->log_pos)
log_pos= group_master_log_pos;
else
log_pos= ev->common_header->log_pos - ev->common_header->data_written;
}
else
{ /* until_condition == UNTIL_RELAY_POS */
log_name= group_relay_log_name;
log_pos= group_relay_log_pos;
}
#ifndef DBUG_OFF
{
char buf[32];
DBUG_PRINT("info", ("group_master_log_name='%s', group_master_log_pos=%s",
group_master_log_name, llstr(group_master_log_pos, buf)));
DBUG_PRINT("info", ("group_relay_log_name='%s', group_relay_log_pos=%s",
group_relay_log_name, llstr(group_relay_log_pos, buf)));
DBUG_PRINT("info", ("(%s) log_name='%s', log_pos=%s",
until_condition == UNTIL_MASTER_POS ? "master" : "relay",
log_name, llstr(log_pos, buf)));
DBUG_PRINT("info", ("(%s) until_log_name='%s', until_log_pos=%s",
until_condition == UNTIL_MASTER_POS ? "master" : "relay",
until_log_name, llstr(until_log_pos, buf)));
}
#endif
if (until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_UNKNOWN)
{
/*
We have no cached comparison results so we should compare log names
and cache result.
If we are after RESET SLAVE, and the SQL slave thread has not processed
any event yet, it could be that group_master_log_name is "". In that case,
just wait for more events (as there is no sensible comparison to do).
*/
if (*log_name)
{
const char *basename= log_name + dirname_length(log_name);
const char *q= (const char*)(fn_ext(basename)+1);
if (strncmp(basename, until_log_name, (int)(q-basename)) == 0)
{
/* Now compare extensions. */
char *q_end;
ulong log_name_extension= strtoul(q, &q_end, 10);
if (log_name_extension < until_log_name_extension)
until_log_names_cmp_result= UNTIL_LOG_NAMES_CMP_LESS;
else
until_log_names_cmp_result=
(log_name_extension > until_log_name_extension) ?
UNTIL_LOG_NAMES_CMP_GREATER : UNTIL_LOG_NAMES_CMP_EQUAL ;
}
else
{
/* Base names do not match, so we abort */
sql_print_error("%s", error_msg);
DBUG_RETURN(true);
}
}
else
DBUG_RETURN(until_log_pos == 0);
}
if (((until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_EQUAL &&
log_pos >= until_log_pos) ||
until_log_names_cmp_result == UNTIL_LOG_NAMES_CMP_GREATER))
{
char buf[22];
sql_print_information("Slave SQL thread stopped because it reached its"
" UNTIL position %s", llstr(until_pos(), buf));
DBUG_RETURN(true);
}
DBUG_RETURN(false);
}
case UNTIL_SQL_BEFORE_GTIDS:
/*
We only need to check once if executed_gtids set
contains any of the until_sql_gtids.
*/
if (until_sql_gtids_first_event)
{
until_sql_gtids_first_event= false;
global_sid_lock->wrlock();
/* Check if until GTIDs were already applied. */
const Gtid_set* executed_gtids= gtid_state->get_executed_gtids();
if (until_sql_gtids.is_intersection_nonempty(executed_gtids))
{
char *buffer;
until_sql_gtids.to_string(&buffer);
global_sid_lock->unlock();
sql_print_information("Slave SQL thread stopped because "
"UNTIL SQL_BEFORE_GTIDS %s is already "
"applied", buffer);
my_free(buffer);
DBUG_RETURN(true);
}
global_sid_lock->unlock();
}
if (ev != NULL && ev->get_type_code() == binary_log::GTID_LOG_EVENT)
{
Gtid_log_event *gev= (Gtid_log_event *)ev;
global_sid_lock->rdlock();
if (until_sql_gtids.contains_gtid(gev->get_sidno(false), gev->get_gno()))
{
char *buffer;
until_sql_gtids.to_string(&buffer);
global_sid_lock->unlock();
sql_print_information("Slave SQL thread stopped because it reached "
"UNTIL SQL_BEFORE_GTIDS %s", buffer);
my_free(buffer);
DBUG_RETURN(true);
}
global_sid_lock->unlock();
}
DBUG_RETURN(false);
break;
case UNTIL_SQL_AFTER_GTIDS:
{
global_sid_lock->wrlock();
const Gtid_set* executed_gtids= gtid_state->get_executed_gtids();
if (until_sql_gtids.is_subset(executed_gtids))
{
char *buffer;
until_sql_gtids.to_string(&buffer);
global_sid_lock->unlock();
sql_print_information("Slave SQL thread stopped because it reached "
"UNTIL SQL_AFTER_GTIDS %s", buffer);
my_free(buffer);
DBUG_RETURN(true);
}
global_sid_lock->unlock();
DBUG_RETURN(false);
}
break;
case UNTIL_SQL_AFTER_MTS_GAPS:
#ifndef DBUG_OFF
case UNTIL_DONE:
#endif
/*
TODO: this condition is actually post-execution or post-scheduling
so the proper place to check it before SQL thread goes
into next_event() where it can wait while the condition
has been satisfied already.
It's deployed here temporarily to be fixed along the regular UNTIL
support for MTS is provided.
*/
if (mts_recovery_group_cnt == 0)
{
sql_print_information("Slave SQL thread stopped according to "
"UNTIL SQL_AFTER_MTS_GAPS as it has "
"processed all gap transactions left from "
"the previous slave session.");
#ifndef DBUG_OFF
until_condition= UNTIL_DONE;
#endif
DBUG_RETURN(true);
}
else
{
DBUG_RETURN(false);
}
break;
case UNTIL_SQL_VIEW_ID:
if (ev != NULL && ev->get_type_code() == binary_log::VIEW_CHANGE_EVENT)
{
View_change_log_event *view_event= (View_change_log_event *)ev;
if (until_view_id.compare(view_event->get_view_id()) == 0)
{
set_group_replication_retrieved_certification_info(view_event);
until_view_id_found= true;
DBUG_RETURN(false);
}
}
if (until_view_id_found && ev != NULL && ev->ends_group())
{
until_view_id_commit_found= true;
DBUG_RETURN(false);
}
if (until_view_id_commit_found && ev == NULL)
{
DBUG_RETURN(true);
}
DBUG_RETURN(false);
break;
case UNTIL_NONE:
DBUG_ASSERT(0);
break;
}
DBUG_ASSERT(0);
DBUG_RETURN(false);
}
void Relay_log_info::cached_charset_invalidate()
{
DBUG_ENTER("Relay_log_info::cached_charset_invalidate");
/* Full of zeroes means uninitialized. */
memset(cached_charset, 0, sizeof(cached_charset));
DBUG_VOID_RETURN;
}
bool Relay_log_info::cached_charset_compare(char *charset) const
{
DBUG_ENTER("Relay_log_info::cached_charset_compare");
if (memcmp(cached_charset, charset, sizeof(cached_charset)))
{
memcpy(const_cast<char*>(cached_charset), charset, sizeof(cached_charset));
DBUG_RETURN(1);
}
DBUG_RETURN(0);
}
int Relay_log_info::stmt_done(my_off_t event_master_log_pos)
{
int error= 0;
clear_flag(IN_STMT);
DBUG_ASSERT(!belongs_to_client());
/* Worker does not execute binlog update position logics */
DBUG_ASSERT(!is_mts_worker(info_thd));
/*
Replication keeps event and group positions to specify the
set of events that were executed.
Event positions are incremented after processing each event
whereas group positions are incremented when an event or a
set of events is processed such as in a transaction and are
committed or rolled back.
A transaction can be ended with a Query Event, i.e. either
commit or rollback, or by a Xid Log Event. Query Event is
used to terminate pseudo-transactions that are executed
against non-transactional engines such as MyIsam. Xid Log
Event denotes though that a set of changes executed
against a transactional engine is about to commit.
Events' positions are incremented at stmt_done(). However,
transactions that are ended with Xid Log Event have their
group position incremented in the do_apply_event() and in
the do_apply_event_work().
Notice that the type of the engine, i.e. where data and
positions are stored, against what events are being applied
are not considered in this logic.
Regarding the code that follows, notice that the executed
group coordinates don't change if the current event is internal
to the group. The same applies to MTS Coordinator when it
handles a Format Descriptor event that appears in the middle
of a group that is about to be assigned.
*/
if ((!is_parallel_exec() && is_in_group()) ||
mts_group_status != MTS_NOT_IN_GROUP)
{
inc_event_relay_log_pos();
}
else
{
if (is_parallel_exec())
{
DBUG_ASSERT(!is_mts_worker(info_thd));
/*
Format Description events only can drive MTS execution to this
point. It is a special event group that is handled with
synchronization. For that reason, the checkpoint routine is
called here.
*/
error= mts_checkpoint_routine(this, 0, false,
true/*need_data_lock=true*/);
}
if (!error)
error= inc_group_relay_log_pos(event_master_log_pos,
true/*need_data_lock=true*/);
}
return error;
}
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
void Relay_log_info::cleanup_context(THD *thd, bool error)
{
DBUG_ENTER("Relay_log_info::cleanup_context");
DBUG_ASSERT(info_thd == thd);
/*
1) Instances of Table_map_log_event, if ::do_apply_event() was called on them,
may have opened tables, which we cannot be sure have been closed (because
maybe the Rows_log_event have not been found or will not be, because slave
SQL thread is stopping, or relay log has a missing tail etc). So we close
all thread's tables. And so the table mappings have to be cancelled.
2) Rows_log_event::do_apply_event() may even have started statements or
transactions on them, which we need to rollback in case of error.
3) If finding a Format_description_log_event after a BEGIN, we also need
to rollback before continuing with the next events.
4) so we need this "context cleanup" function.
*/
if (error)
{
trans_rollback_stmt(thd); // if a "statement transaction"
trans_rollback(thd); // if a "real transaction"
}
if (rows_query_ev)
{
delete rows_query_ev;
rows_query_ev= NULL;
info_thd->reset_query();
}
m_table_map.clear_tables();
slave_close_thread_tables(thd);
if (error)
thd->mdl_context.release_transactional_locks();
clear_flag(IN_STMT);
/*
Cleanup for the flags that have been set at do_apply_event.
*/
thd->variables.option_bits&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
thd->variables.option_bits&= ~OPTION_RELAXED_UNIQUE_CHECKS;
/*
Reset state related to long_find_row notes in the error log:
- timestamp
- flag that decides whether the slave prints or not
*/
reset_row_stmt_start_timestamp();
unset_long_find_row_note_printed();
DBUG_VOID_RETURN;
}
void Relay_log_info::clear_tables_to_lock()
{
DBUG_ENTER("Relay_log_info::clear_tables_to_lock()");
#ifndef DBUG_OFF
/**
When replicating in RBR and MyISAM Merge tables are involved
open_and_lock_tables (called in do_apply_event) appends the
base tables to the list of tables_to_lock. Then these are
removed from the list in close_thread_tables (which is called
before we reach this point).
This assertion just confirms that we get no surprises at this
point.
*/
uint i=0;
for (TABLE_LIST *ptr= tables_to_lock ; ptr ; ptr= ptr->next_global, i++) ;
DBUG_ASSERT(i == tables_to_lock_count);
#endif
while (tables_to_lock)
{
uchar* to_free= reinterpret_cast<uchar*>(tables_to_lock);
if (tables_to_lock->m_tabledef_valid)
{
tables_to_lock->m_tabledef.table_def::~table_def();
tables_to_lock->m_tabledef_valid= FALSE;
}
/*
If blob fields were used during conversion of field values
from the master table into the slave table, then we need to
free the memory used temporarily to store their values before
copying into the slave's table.
*/
if (tables_to_lock->m_conv_table)
free_blobs(tables_to_lock->m_conv_table);
tables_to_lock=
static_cast<RPL_TABLE_LIST*>(tables_to_lock->next_global);
tables_to_lock_count--;
my_free(to_free);
}
DBUG_ASSERT(tables_to_lock == NULL && tables_to_lock_count == 0);
DBUG_VOID_RETURN;
}
void Relay_log_info::slave_close_thread_tables(THD *thd)
{
thd->get_stmt_da()->set_overwrite_status(true);
DBUG_ENTER("Relay_log_info::slave_close_thread_tables(THD *thd)");
thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd);
thd->get_stmt_da()->set_overwrite_status(false);
close_thread_tables(thd);
/*
- If transaction rollback was requested due to deadlock
perform it and release metadata locks.
- If inside a multi-statement transaction,
defer the release of metadata locks until the current
transaction is either committed or rolled back. This prevents
other statements from modifying the table for the entire
duration of this transaction. This provides commit ordering
and guarantees serializability across multiple transactions.
- If in autocommit mode, or outside a transactional context,
automatically release metadata locks of the current statement.
*/
if (thd->transaction_rollback_request)
{
trans_rollback_implicit(thd);
thd->mdl_context.release_transactional_locks();
}
else if (! thd->in_multi_stmt_transaction_mode())
thd->mdl_context.release_transactional_locks();
else
thd->mdl_context.release_statement_locks();
clear_tables_to_lock();
DBUG_VOID_RETURN;
}
/**
Execute a SHOW RELAYLOG EVENTS statement.
When multiple replication channels exist on this slave
and no channel name is specified through FOR CHANNEL clause
this function errors out and exits.
@param thd Pointer to THD object for the client thread executing the
statement.
@retval FALSE success
@retval TRUE failure
*/
bool mysql_show_relaylog_events(THD* thd)
{
Master_info *mi =0;
List<Item> field_list;
bool res;
DBUG_ENTER("mysql_show_relaylog_events");
DBUG_ASSERT(thd->lex->sql_command == SQLCOM_SHOW_RELAYLOG_EVENTS);
channel_map.wrlock();
if (!thd->lex->mi.for_channel && channel_map.get_num_instances() > 1)
{
my_error(ER_SLAVE_MULTIPLE_CHANNELS_CMD, MYF(0));
res= true;
goto err;
}
Log_event::init_show_field_list(&field_list);
if (thd->send_result_metadata(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
{
res= true;
goto err;
}
mi= channel_map.get_mi(thd->lex->mi.channel);
if (!mi && strcmp(thd->lex->mi.channel, channel_map.get_default_channel()))
{
my_error(ER_SLAVE_CHANNEL_DOES_NOT_EXIST, MYF(0), thd->lex->mi.channel);
res= true;
goto err;
}
if (mi == NULL)
{
my_error(ER_SLAVE_CONFIGURATION, MYF(0));
res= true;
goto err;
}
res= show_binlog_events(thd, &mi->rli->relay_log);
err:
channel_map.unlock();
DBUG_RETURN(res);
}
#endif
int Relay_log_info::rli_init_info()
{
int error= 0;
enum_return_check check_return= ERROR_CHECKING_REPOSITORY;
const char *msg= NULL;
/* Store the GTID of a transaction spanned in multiple relay log files */
Gtid gtid_partial_trx= {0, 0};
DBUG_ENTER("Relay_log_info::rli_init_info");
mysql_mutex_assert_owner(&data_lock);
/*
If Relay_log_info is issued again after a failed init_info(), for
instance because of missing relay log files, it will generate new
files and ignore the previous failure, to avoid that we set
error_on_rli_init_info as true.
This a consequence of the behaviour change, in the past server was
stopped when there were replication initialization errors, now it is
not and so init_info() must be aware of previous failures.
*/
if (error_on_rli_init_info)
goto err;
if (inited)
{
/*
We have to reset read position of relay-log-bin as we may have
already been reading from 'hotlog' when the slave was stopped
last time. If this case pos_in_file would be set and we would
get a crash when trying to read the signature for the binary
relay log.
We only rewind the read position if we are starting the SQL
thread. The handle_slave_sql thread assumes that the read
position is at the beginning of the file, and will read the
"signature" and then fast-forward to the last position read.
*/
bool hot_log= FALSE;
/*
my_b_seek does an implicit flush_io_cache, so we need to:
1. check if this log is active (hot)
2. if it is we keep log_lock until the seek ends, otherwise
release it right away.
If we did not take log_lock, SQL thread might race with IO
thread for the IO_CACHE mutex.
*/
mysql_mutex_t *log_lock= relay_log.get_log_lock();
mysql_mutex_lock(log_lock);
hot_log= relay_log.is_active(linfo.log_file_name);
if (!hot_log)
mysql_mutex_unlock(log_lock);
my_b_seek(cur_log, (my_off_t) 0);
if (hot_log)
mysql_mutex_unlock(log_lock);
DBUG_RETURN(recovery_parallel_workers ? mts_recovery_groups(this) : 0);
}
cur_log_fd = -1;
slave_skip_counter= 0;
abort_pos_wait= 0;
log_space_limit= relay_log_space_limit;
log_space_total= 0;
tables_to_lock= 0;
tables_to_lock_count= 0;
char pattern[FN_REFLEN];
(void) my_realpath(pattern, slave_load_tmpdir, 0);
/*
@TODO:
In MSR, sometimes slave fail with the following error:
Unable to use slave's temporary directory /tmp -
Can't create/write to file '/tmp/SQL_LOAD-92d1eee0-9de4-11e3-8874-68730ad50fcb' (Errcode: 17 - File exists), Error_code: 1
*/
if (fn_format(pattern, PREFIX_SQL_LOAD, pattern, "",
MY_SAFE_PATH | MY_RETURN_REAL_PATH) == NullS)
{
sql_print_error("Unable to use slave's temporary directory '%s'.",
slave_load_tmpdir);
DBUG_RETURN(1);
}
unpack_filename(slave_patternload_file, pattern);
slave_patternload_file_size= strlen(slave_patternload_file);
/*
The relay log will now be opened, as a SEQ_READ_APPEND IO_CACHE.
Note that the I/O thread flushes it to disk after writing every
event, in flush_info within the master info.
*/
/*
For the maximum log size, we choose max_relay_log_size if it is
non-zero, max_binlog_size otherwise. If later the user does SET
GLOBAL on one of these variables, fix_max_binlog_size and
fix_max_relay_log_size will reconsider the choice (for example
if the user changes max_relay_log_size to zero, we have to
switch to using max_binlog_size for the relay log) and update
relay_log.max_size (and mysql_bin_log.max_size).
*/
{
/* Reports an error and returns, if the --relay-log's path
is a directory.*/
if (opt_relay_logname &&
opt_relay_logname[strlen(opt_relay_logname) - 1] == FN_LIBCHAR)
{
sql_print_error("Path '%s' is a directory name, please specify \
a file name for --relay-log option.", opt_relay_logname);
DBUG_RETURN(1);
}
/* Reports an error and returns, if the --relay-log-index's path
is a directory.*/
if (opt_relaylog_index_name &&
opt_relaylog_index_name[strlen(opt_relaylog_index_name) - 1]
== FN_LIBCHAR)
{
sql_print_error("Path '%s' is a directory name, please specify \
a file name for --relay-log-index option.", opt_relaylog_index_name);
DBUG_RETURN(1);
}
char buf[FN_REFLEN];
/* The base name of the relay log file considering multisource rep */
const char *ln;
/*
relay log name without channel prefix taking into account
--relay-log option.
*/
const char *ln_without_channel_name;
static bool name_warning_sent= 0;
/*
Buffer to add channel name suffix when relay-log option is provided.
*/
char relay_bin_channel[FN_REFLEN];
/*
Buffer to add channel name suffix when relay-log-index option is provided
*/
char relay_bin_index_channel[FN_REFLEN];
/* name of the index file if opt_relaylog_index_name is set*/
const char* log_index_name;
ln_without_channel_name= relay_log.generate_name(opt_relay_logname,
"-relay-bin", buf);
ln= add_channel_to_relay_log_name(relay_bin_channel, FN_REFLEN,
ln_without_channel_name);
/* We send the warning only at startup, not after every RESET SLAVE */
if (!opt_relay_logname && !opt_relaylog_index_name && !name_warning_sent)
{
/*
User didn't give us info to name the relay log index file.
Picking `hostname`-relay-bin.index like we do, causes replication to
fail if this slave's hostname is changed later. So, we would like to
instead require a name. But as we don't want to break many existing
setups, we only give warning, not error.
*/
sql_print_warning("Neither --relay-log nor --relay-log-index were used;"
" so replication "
"may break when this MySQL server acts as a "
"slave and has his hostname changed!! Please "
"use '--relay-log=%s' to avoid this problem.",
ln_without_channel_name);
name_warning_sent= 1;
}
relay_log.is_relay_log= TRUE;
/*
If relay log index option is set, convert into channel specific
index file. If the opt_relaylog_index has an extension, we strip
it too. This is inconsistent to relay log names.
*/
if (opt_relaylog_index_name)
{
char index_file_withoutext[FN_REFLEN];
relay_log.generate_name(opt_relaylog_index_name,"",
index_file_withoutext);
log_index_name= add_channel_to_relay_log_name(relay_bin_index_channel,
FN_REFLEN,
index_file_withoutext);
}
else
log_index_name= 0;
if (relay_log.open_index_file(log_index_name, ln, TRUE))
{
sql_print_error("Failed in open_index_file() called from Relay_log_info::rli_init_info().");
DBUG_RETURN(1);
}
#ifndef DBUG_OFF
global_sid_lock->wrlock();
gtid_set.dbug_print("set of GTIDs in relay log before initialization");
global_sid_lock->unlock();
#endif
/*
In the init_gtid_set below we pass the mi->transaction_parser.
This will be useful to ensure that we only add a GTID to
the Retrieved_Gtid_Set for fully retrieved transactions. Also, it will
be useful to ensure the Retrieved_Gtid_Set behavior when auto
positioning is disabled (we could have transactions spanning multiple
relay log files in this case).
*/
if (!gtid_retrieved_initialized &&
relay_log.init_gtid_sets(>id_set, NULL,
opt_slave_sql_verify_checksum,
true/*true=need lock*/,
&mi->transaction_parser, >id_partial_trx))
{
sql_print_error("Failed in init_gtid_sets() called from Relay_log_info::rli_init_info().");
DBUG_RETURN(1);
}
gtid_retrieved_initialized= true;
#ifndef DBUG_OFF
global_sid_lock->wrlock();
gtid_set.dbug_print("set of GTIDs in relay log after initialization");
global_sid_lock->unlock();
#endif
if (!gtid_partial_trx.is_empty())
{
/*
The init_gtid_set has found an incomplete transaction in the relay log.
We add this transaction's GTID to the last_gtid_queued so the IO thread
knows which GTID to add to the Retrieved_Gtid_Set when reaching the end
of the incomplete transaction.
*/
mi->set_last_gtid_queued(gtid_partial_trx);
}
else
{
mi->clear_last_gtid_queued();
}
/*
Configures what object is used by the current log to store processed
gtid(s). This is necessary in the MYSQL_BIN_LOG::MYSQL_BIN_LOG to
corretly compute the set of previous gtids.
*/
relay_log.set_previous_gtid_set_relaylog(>id_set);
/*
note, that if open() fails, we'll still have index file open
but a destructor will take care of that
*/
mysql_mutex_t *log_lock= relay_log.get_log_lock();
mysql_mutex_lock(log_lock);
if (relay_log.open_binlog(ln, 0,
(max_relay_log_size ? max_relay_log_size :
max_binlog_size), true,
true/*need_lock_index=true*/,
true/*need_sid_lock=true*/,
mi->get_mi_description_event()))
{
mysql_mutex_unlock(log_lock);
sql_print_error("Failed in open_log() called from Relay_log_info::rli_init_info().");
DBUG_RETURN(1);
}
mysql_mutex_unlock(log_lock);
}
/*
This checks if the repository was created before and thus there
will be values to be read. Please, do not move this call after
the handler->init_info().
*/
if ((check_return= check_info()) == ERROR_CHECKING_REPOSITORY)
{
msg= "Error checking relay log repository";
error= 1;
goto err;
}
if (handler->init_info())
{
msg= "Error reading relay log configuration";
error= 1;
goto err;
}
if (check_return == REPOSITORY_DOES_NOT_EXIST)
{
/* Init relay log with first entry in the relay index file */
if (init_relay_log_pos(NullS, BIN_LOG_HEADER_SIZE,
false/*need_data_lock=false (lock should be held
prior to invoking this function)*/,
&msg, 0))
{
error= 1;
goto err;
}
group_master_log_name[0]= 0;
group_master_log_pos= 0;
}
else
{
if (read_info(handler))
{
msg= "Error reading relay log configuration";
error= 1;
goto err;
}
if (is_relay_log_recovery && init_recovery(mi, &msg))
{
error= 1;
goto err;
}
if (init_relay_log_pos(group_relay_log_name,
group_relay_log_pos,
false/*need_data_lock=false (lock should be held
prior to invoking this function)*/,
&msg, 0))
{
char llbuf[22];
sql_print_error("Failed to open the relay log '%s' (relay_log_pos %s).",
group_relay_log_name,
llstr(group_relay_log_pos, llbuf));
error= 1;
goto err;
}
#ifndef DBUG_OFF
{
char llbuf1[22], llbuf2[22];
DBUG_PRINT("info", ("my_b_tell(cur_log)=%s event_relay_log_pos=%s",
llstr(my_b_tell(cur_log),llbuf1),
llstr(event_relay_log_pos,llbuf2)));
DBUG_ASSERT(event_relay_log_pos >= BIN_LOG_HEADER_SIZE);
DBUG_ASSERT((my_b_tell(cur_log) == event_relay_log_pos));
}
#endif
}
inited= 1;
error_on_rli_init_info= false;
if (flush_info(TRUE))
{
msg= "Error reading relay log configuration";
error= 1;
goto err;
}
if (count_relay_log_space())
{
msg= "Error counting relay log space";
error= 1;
goto err;
}
is_relay_log_recovery= FALSE;
DBUG_RETURN(error);
err:
handler->end_info();
inited= 0;
error_on_rli_init_info= true;
if (msg)
sql_print_error("%s.", msg);
relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
DBUG_RETURN(error);
}
void Relay_log_info::end_info()
{
DBUG_ENTER("Relay_log_info::end_info");
error_on_rli_init_info= false;
if (!inited)
DBUG_VOID_RETURN;
handler->end_info();
if (cur_log_fd >= 0)
{
end_io_cache(&cache_buf);
(void)my_close(cur_log_fd, MYF(MY_WME));
cur_log_fd= -1;
}
inited = 0;
relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
relay_log.harvest_bytes_written(&log_space_total);
/*
Delete the slave's temporary tables from memory.
In the future there will be other actions than this, to ensure persistance
of slave's temp tables after shutdown.
*/
close_temporary_tables();
DBUG_VOID_RETURN;
}
int Relay_log_info::flush_current_log()
{
DBUG_ENTER("Relay_log_info::flush_current_log");
/*
When we come to this place in code, relay log may or not be initialized;
the caller is responsible for setting 'flush_relay_log_cache' accordingly.
*/
IO_CACHE *log_file= relay_log.get_log_file();
if (flush_io_cache(log_file))
DBUG_RETURN(2);
DBUG_RETURN(0);
}
void Relay_log_info::set_master_info(Master_info* info)
{
mi= info;
}
/**
Stores the file and position where the execute-slave thread are in the
relay log:
- As this is only called by the slave thread or on STOP SLAVE, with the
log_lock grabbed and the slave thread stopped, we don't need to have
a lock here.
- If there is an active transaction, then we don't update the position
in the relay log. This is to ensure that we re-execute statements
if we die in the middle of an transaction that was rolled back.
- As a transaction never spans binary logs, we don't have to handle the
case where we do a relay-log-rotation in the middle of the transaction.
If this would not be the case, we would have to ensure that we
don't delete the relay log file where the transaction started when
we switch to a new relay log file.
@retval 0 ok,
@retval 1 write error, otherwise.
*/
/**
Store the file and position where the slave's SQL thread are in the
relay log.
Notes:
- This function should be called either from the slave SQL thread,
or when the slave thread is not running. (It reads the
group_{relay|master}_log_{pos|name} and delay fields in the rli
object. These may only be modified by the slave SQL thread or by
a client thread when the slave SQL thread is not running.)
- If there is an active transaction, then we do not update the
position in the relay log. This is to ensure that we re-execute
statements if we die in the middle of an transaction that was
rolled back.
- As a transaction never spans binary logs, we don't have to handle
the case where we do a relay-log-rotation in the middle of the
transaction. If transactions could span several binlogs, we would
have to ensure that we do not delete the relay log file where the
transaction started before switching to a new relay log file.
- Error can happen if writing to file fails or if flushing the file
fails.
@param rli The object representing the Relay_log_info.
@todo Change the log file information to a binary format to avoid
calling longlong2str.
@return 0 on success, 1 on error.
*/
int Relay_log_info::flush_info(const bool force)
{
DBUG_ENTER("Relay_log_info::flush_info");
if (!inited)
DBUG_RETURN(0);
/*
We update the sync_period at this point because only here we
now that we are handling a relay log info. This needs to be
update every time we call flush because the option maybe
dinamically set.
*/
mysql_mutex_lock(&mts_temp_table_LOCK);
handler->set_sync_period(sync_relayloginfo_period);
if (write_info(handler))
goto err;
if (handler->flush_info(force || force_flush_postponed_due_to_split_trans))
goto err;
force_flush_postponed_due_to_split_trans= false;
mysql_mutex_unlock(&mts_temp_table_LOCK);
DBUG_RETURN(0);
err:
sql_print_error("Error writing relay log configuration.");
mysql_mutex_unlock(&mts_temp_table_LOCK);
DBUG_RETURN(1);
}
size_t Relay_log_info::get_number_info_rli_fields()
{
return sizeof(info_rli_fields)/sizeof(info_rli_fields[0]);
}
bool Relay_log_info::read_info(Rpl_info_handler *from)
{
int lines= 0;
char *first_non_digit= NULL;
ulong temp_group_relay_log_pos= 0;
ulong temp_group_master_log_pos= 0;
int temp_sql_delay= 0;
int temp_internal_id= internal_id;
DBUG_ENTER("Relay_log_info::read_info");
/*
Should not read RLI from file in client threads. Client threads
only use RLI to execute BINLOG statements.
@todo Uncomment the following assertion. Currently,
Relay_log_info::init() is called from init_master_info() before
the THD object Relay_log_info::sql_thd is created. That means we
cannot call belongs_to_client() since belongs_to_client()
dereferences Relay_log_info::sql_thd. So we need to refactor
slightly: the THD object should be created by Relay_log_info
constructor (or passed to it), so that we are guaranteed that it
exists at this point. /Sven
*/
//DBUG_ASSERT(!belongs_to_client());
/*
Starting from 5.1.x, relay-log.info has a new format. Now, its
first line contains the number of lines in the file. By reading
this number we can determine which version our master.info comes
from. We can't simply count the lines in the file, since
versions before 5.1.x could generate files with more lines than
needed. If first line doesn't contain a number, or if it
contains a number less than LINES_IN_RELAY_LOG_INFO_WITH_DELAY,
then the file is treated like a file from pre-5.1.x version.
There is no ambiguity when reading an old master.info: before
5.1.x, the first line contained the binlog's name, which is
either empty or has an extension (contains a '.'), so can't be
confused with an integer.
So we're just reading first line and trying to figure which
version is this.
*/
/*
The first row is temporarily stored in mi->master_log_name, if
it is line count and not binlog name (new format) it will be
overwritten by the second row later.
*/
if (from->prepare_info_for_read() ||
from->get_info(group_relay_log_name, sizeof(group_relay_log_name),
(char *) ""))
DBUG_RETURN(TRUE);
lines= strtoul(group_relay_log_name, &first_non_digit, 10);
if (group_relay_log_name[0]!='\0' &&
*first_non_digit=='\0' && lines >= LINES_IN_RELAY_LOG_INFO_WITH_DELAY)
{
/* Seems to be new format => read group relay log name */
if (from->get_info(group_relay_log_name, sizeof(group_relay_log_name),
(char *) ""))
DBUG_RETURN(TRUE);
}
else
DBUG_PRINT("info", ("relay_log_info file is in old format."));
if (from->get_info(&temp_group_relay_log_pos,
(ulong) BIN_LOG_HEADER_SIZE) ||
from->get_info(group_master_log_name,
sizeof(group_relay_log_name),
(char *) "") ||
from->get_info(&temp_group_master_log_pos,
0UL))
DBUG_RETURN(TRUE);
if (lines >= LINES_IN_RELAY_LOG_INFO_WITH_DELAY)
{
if (from->get_info(&temp_sql_delay, 0))
DBUG_RETURN(TRUE);
}
if (lines >= LINES_IN_RELAY_LOG_INFO_WITH_WORKERS)
{
if (from->get_info(&recovery_parallel_workers, 0UL))
DBUG_RETURN(TRUE);
}
if (lines >= LINES_IN_RELAY_LOG_INFO_WITH_ID)
{
if (from->get_info(&temp_internal_id, 1))
DBUG_RETURN(TRUE);
}
if (lines >= LINES_IN_RELAY_LOG_INFO_WITH_CHANNEL)
{
/* the default value is empty string"" */
if (from->get_info(channel, sizeof(channel), (char*)""))
DBUG_RETURN(TRUE);
}
group_relay_log_pos= temp_group_relay_log_pos;
group_master_log_pos= temp_group_master_log_pos;
sql_delay= (int32) temp_sql_delay;
internal_id= (uint) temp_internal_id;
DBUG_ASSERT(lines < LINES_IN_RELAY_LOG_INFO_WITH_ID ||
(lines >= LINES_IN_RELAY_LOG_INFO_WITH_ID && internal_id == 1));
DBUG_RETURN(FALSE);
}
bool Relay_log_info::set_info_search_keys(Rpl_info_handler *to)
{
DBUG_ENTER("Relay_log_info::set_info_search_keys");
if (to->set_info(LINES_IN_RELAY_LOG_INFO_WITH_CHANNEL, channel))
DBUG_RETURN(TRUE);
DBUG_RETURN(FALSE);
}
bool Relay_log_info::write_info(Rpl_info_handler *to)
{
DBUG_ENTER("Relay_log_info::write_info");
/*
@todo Uncomment the following assertion. See todo in
Relay_log_info::read_info() for details. /Sven
*/
//DBUG_ASSERT(!belongs_to_client());
if (to->prepare_info_for_write() ||
to->set_info((int) LINES_IN_RELAY_LOG_INFO_WITH_ID) ||
to->set_info(group_relay_log_name) ||
to->set_info((ulong) group_relay_log_pos) ||
to->set_info(group_master_log_name) ||
to->set_info((ulong) group_master_log_pos) ||
to->set_info((int) sql_delay) ||
to->set_info(recovery_parallel_workers) ||
to->set_info((int) internal_id) ||
to->set_info(channel))
DBUG_RETURN(TRUE);
DBUG_RETURN(FALSE);
}
/**
The method is run by SQL thread/MTS Coordinator.
It replaces the current FD event with a new one.
A version adaptation routine is invoked for the new FD
to align the slave applier execution context with the master version.
Since FD are shared by Coordinator and Workers in the MTS mode,
deletion of the old FD is done through decrementing its usage counter.
The destructor runs when the later drops to zero,
also see @c Slave_worker::set_rli_description_event().
The usage counter of the new FD is incremented.
Although notice that MTS worker runs it, inefficiently (see assert),
once at its destruction time.
@param a pointer to be installed into execution context
FormatDescriptor event
*/
void Relay_log_info::set_rli_description_event(Format_description_log_event *fe)
{
DBUG_ENTER("Relay_log_info::set_rli_description_event");
DBUG_ASSERT(!info_thd || !is_mts_worker(info_thd) || !fe);
if (fe)
{
ulong fe_version= adapt_to_master_version(fe);
if (info_thd)
{
// See rpl_rli_pdb.h:Slave_worker::set_rli_description_event.
if (!is_in_group() &&
(info_thd->variables.gtid_next.type == AUTOMATIC_GROUP ||
info_thd->variables.gtid_next.type == UNDEFINED_GROUP))
{
DBUG_PRINT("info", ("Setting gtid_next.type to NOT_YET_DETERMINED_GROUP"));
info_thd->variables.gtid_next.set_not_yet_determined();
}
if (is_parallel_exec() && fe_version > 0)
{
/*
Prepare for workers' adaption to a new FD version. Workers
will see notification through scheduling of a first event of
a new post-new-FD.
*/
for (Slave_worker **it= workers.begin(); it != workers.end(); ++it)
(*it)->fd_change_notified= false;
}
}
}
if (rli_description_event &&
rli_description_event->usage_counter.atomic_add(-1) == 1)
delete rli_description_event;
#ifndef DBUG_OFF
else
/* It must be MTS mode when the usage counter greater than 1. */
DBUG_ASSERT(!rli_description_event || is_parallel_exec());
#endif
rli_description_event= fe;
if (rli_description_event)
rli_description_event->usage_counter.atomic_add(1);
DBUG_VOID_RETURN;
}
struct st_feature_version
{
/*
The enum must be in the version non-descending top-down order,
the last item formally corresponds to highest possible server
version (never reached, thereby no adapting actions here);
enumeration starts from zero.
*/
enum
{
WL6292_TIMESTAMP_EXPLICIT_DEFAULT= 0,
_END_OF_LIST // always last
} item;
/*
Version where the feature is introduced.
*/
uchar version_split[3];
/*
Action to perform when according to FormatDescriptor event Master
is found to be feature-aware while previously it has *not* been.
*/
void (*upgrade) (THD*);
/*
Action to perform when according to FormatDescriptor event Master
is found to be feature-*un*aware while previously it has been.
*/
void (*downgrade) (THD*);
};
void wl6292_upgrade_func(THD *thd)
{
thd->variables.explicit_defaults_for_timestamp= false;
if (global_system_variables.explicit_defaults_for_timestamp)
thd->variables.explicit_defaults_for_timestamp= true;
return;
}
void wl6292_downgrade_func(THD *thd)
{
if (global_system_variables.explicit_defaults_for_timestamp)
thd->variables.explicit_defaults_for_timestamp= false;
return;
}
/**
Sensitive to Master-vs-Slave version difference features
should be listed in the version non-descending order.
*/
static st_feature_version s_features[]=
{
// order is the same as in the enum
{ st_feature_version::WL6292_TIMESTAMP_EXPLICIT_DEFAULT,
{5, 6, 6}, wl6292_upgrade_func, wl6292_downgrade_func },
{ st_feature_version::_END_OF_LIST,
{255, 255, 255}, NULL, NULL }
};
/**
The method computes the incoming "master"'s FD server version and that
of the currently installed (if ever) rli_description_event, to
invoke more specific method to compare the two and adapt slave applier execution
context to the new incoming master's version.
This method is specifically for STS applier/MTS Coordinator as well as
for a user thread applying binlog events.
@param fdle a pointer to new Format Description event that is being
set up a new execution context.
@return 0 when the versions are equal,
master_version otherwise
*/
ulong Relay_log_info::adapt_to_master_version(Format_description_log_event *fdle)
{
ulong master_version, current_version, slave_version;
slave_version= version_product(slave_version_split);
/* When rli_description_event is uninitialized yet take the slave's version */
master_version= !fdle ? slave_version : fdle->get_product_version();
current_version= !rli_description_event ? slave_version :
rli_description_event->get_product_version();
return adapt_to_master_version_updown(master_version, current_version);
}
/**
The method compares two supplied versions and carries out down- or
up- grade customization of execution context of the slave applier
(thd).
The method is invoked in the STS case through
Relay_log_info::adapt_to_master_version() right before a new master
FD is installed into the applier execution context; in the MTS
case it's done by the Worker when it's assigned with a first event
after the latest new FD has been installed.
Comparison of the current (old, existing) and the master (new,
incoming) versions yields adaptive actions.
To explain that, let's denote V_0 as the current, and the master's
one as V_1.
In the downgrade case (V_1 < V_0) a server feature that is undefined
in V_1 but is defined starting from some V_f of [V_1 + 1, V_0] range
(+1 to mean V_1 excluded) are invalidated ("removed" from execution context)
by running so called here downgrade action.
Conversely in the upgrade case a feature defined in [V_0 + 1, V_1] range
is validated ("added" to execution context) by running its upgrade action.
A typical use case showing how adaptive actions are necessary for the slave
applier is when the master version is lesser than the slave's one.
In such case events generated on the "older" master may need to be applied
in their native server context. And such context can be provided by downgrade
actions.
Conversely, when the old master events are run out and a newer master's events
show up for applying, the execution context will be upgraded through
the namesake actions.
Notice that a relay log may have two FD events, one the slave local
and the other from the Master. As there's no concern for the FD
originator this leads to two adapt_to_master_version() calls.
It's not harmful as can be seen from the following example.
Say the currently installed FD's version is
V_m, then at relay-log rotation the following transition takes
place:
V_m -adapt-> V_s -adapt-> V_m.
here and further `m' subscript stands for the master, `s' for the slave.
It's clear that in this case an ineffective V_m -> V_m transition occurs.
At composing downgrade/upgrade actions keep in mind that the slave applier
version transition goes the following route:
The initial version is that of the slave server (V_ss).
It changes to a magic 4.0 at the slave relay log initialization.
In the following course versions are extracted from each FD read out,
regardless of what server generated it. Here is a typical version
transition sequence underscored with annotation:
V_ss -> 4.0 -> V(FD_s^1) -> V(FD_m^2) ---> V(FD_s^3) -> V(FD_m^4) ...
---------- ----------------- -------- ------------------ ---
bootstrap 1st relay log rotation 2nd log etc
The upper (^) subscipt enumerates Format Description events, V(FD^i) stands
for a function extrating the version data from the i:th FD.
There won't be any action to execute when info_thd is undefined,
e.g at bootstrap.
@param master_version an upcoming new version
@param current_version the current version
@return 0 when the new version is equal to the current one,
master_version otherwise
*/
ulong Relay_log_info::adapt_to_master_version_updown(ulong master_version,
ulong current_version)
{
THD *thd= info_thd;
/*
When the SQL thread or MTS Coordinator executes this method
there's a constraint on current_version argument.
*/
DBUG_ASSERT(!thd ||
thd->rli_fake != NULL ||
thd->system_thread == SYSTEM_THREAD_SLAVE_WORKER ||
(thd->system_thread == SYSTEM_THREAD_SLAVE_SQL &&
(!rli_description_event ||
current_version ==
rli_description_event->get_product_version())));
if (master_version == current_version)
return 0;
else if (!thd)
return master_version;
bool downgrade= master_version < current_version;
/*
find item starting from and ending at for which adaptive actions run
for downgrade or upgrade branches.
(todo: convert into bsearch when number of features will grow significantly)
*/
long i, i_first= st_feature_version::_END_OF_LIST, i_last= i_first;
for (i= 0; i < st_feature_version::_END_OF_LIST; i++)
{
ulong ver_f= version_product(s_features[i].version_split);
if ((downgrade ? master_version : current_version) < ver_f &&
i_first == st_feature_version::_END_OF_LIST)
i_first= i;
if ((downgrade ? current_version : master_version) < ver_f)
{
i_last= i;
DBUG_ASSERT(i_last >= i_first);
break;
}
}
/*
actions, executed in version non-descending st_feature_version order
*/
for (i= i_first; i < i_last; i++)
{
/* Run time check of the st_feature_version items ordering */
DBUG_ASSERT(!i ||
version_product(s_features[i - 1].version_split) <=
version_product(s_features[i].version_split));
DBUG_ASSERT((downgrade ? master_version : current_version) <
version_product(s_features[i].version_split) &&
(downgrade ? current_version : master_version >=
version_product(s_features[i].version_split)));
if (downgrade && s_features[i].downgrade)
{
s_features[i].downgrade(thd);
}
else if (s_features[i].upgrade)
{
s_features[i].upgrade(thd);
}
}
return master_version;
}
void Relay_log_info::relay_log_number_to_name(uint number,
char name[FN_REFLEN+1])
{
char *str= NULL;
char relay_bin_channel[FN_REFLEN+1];
const char *relay_log_basename_channel=
add_channel_to_relay_log_name(relay_bin_channel, FN_REFLEN+1,
relay_log_basename);
/* str points to closing null of relay log basename channel */
str= strmake(name, relay_log_basename_channel, FN_REFLEN+1);
*str++= '.';
sprintf(str, "%06u", number);
}
uint Relay_log_info::relay_log_name_to_number(const char *name)
{
return static_cast<uint>(atoi(fn_ext(name)+1));
}
bool is_mts_db_partitioned(Relay_log_info * rli)
{
return (rli->current_mts_submode->get_type() ==
MTS_PARALLEL_TYPE_DB_NAME);
}
const char* Relay_log_info::get_for_channel_str(bool upper_case) const
{
if (rli_fake)
return "";
else
return mi->get_for_channel_str(upper_case);
}
| 33.688022 | 129 | 0.674539 | [
"object"
] |
a168ac84afa90c6caffdfce4fbfc106213fdc443 | 1,674 | cpp | C++ | graph/lowest_common_ancestor.cpp | ShinyaKato/algorithm-snipets | 53ae76cdc427dd816a7a11147d80a172fb16bcc3 | [
"Apache-2.0"
] | 1 | 2018-09-22T16:53:07.000Z | 2018-09-22T16:53:07.000Z | graph/lowest_common_ancestor.cpp | ShinyaKato/competitive-programming-utils | 53ae76cdc427dd816a7a11147d80a172fb16bcc3 | [
"Apache-2.0"
] | 2 | 2018-07-03T17:19:18.000Z | 2018-07-03T17:23:10.000Z | graph/lowest_common_ancestor.cpp | ShinyaKato/competitive-programming-utils | 53ae76cdc427dd816a7a11147d80a172fb16bcc3 | [
"Apache-2.0"
] | null | null | null | #include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
class LowestCommonAncestor {
ll N, D;
vector<ll> depth;
vector<vector<ll>> parent, E;
public:
LowestCommonAncestor(ll N, ll D = 24): N(N), D(D) {
depth.resize(N);
parent.resize(D, vector<ll>(N));
E.resize(N);
}
void add_edge(ll u, ll v) {
E[u].push_back(v);
E[v].push_back(u);
}
void init(ll root) {
dfs(root, -1, 0);
REP(i, 0, D - 1) REP(j, 0, N) {
if (parent[i][j] == -1) parent[i + 1][j] = -1;
else parent[i + 1][j] = parent[i][parent[i][j]];
}
}
ll query(ll u, ll v) {
if (depth[u] > depth[v]) swap(u, v);
REP(i, 0, D) {
if ((depth[v] - depth[u]) & 1LL << i) {
v = parent[i][v];
}
}
if (u == v) return u;
for (ll i = D - 1; i >= 0; i--) {
if (parent[i][u] != parent[i][v]) {
u = parent[i][u];
v = parent[i][v];
}
}
return parent[0][u];
}
ll dist(ll u, ll v) {
return depth[u] + depth[v] - depth[query(u, v)] * 2;
}
private:
void dfs(ll v, ll p, ll d) {
parent[0][v] = p;
depth[v] = d;
REP(i, 0, E[v].size()) {
if (E[v][i] != p) {
dfs(E[v][i], v, d + 1);
}
}
}
};
/* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp */
int main(void) {
ll N;
cin >> N;
LowestCommonAncestor lca(N);
REP(i, 0, N) {
ll k;
cin >> k;
REP(j, 0, k) {
ll v;
cin >> v;
lca.add_edge(i, v);
}
}
lca.init(0);
ll Q;
cin >> Q;
REP(i, 0, Q) {
ll U, V;
cin >> U >> V;
cout << lca.query(U, V) << endl;
}
}
| 19.022727 | 60 | 0.456392 | [
"vector"
] |
a17500117a08d14a34cd18db9aa498ab87f1b138 | 1,010 | cpp | C++ | graph/nearest-1-from-each-cell.cpp | Strider-7/code | e096c0d0633b53a07bf3f295cb3bd685b694d4ce | [
"MIT"
] | null | null | null | graph/nearest-1-from-each-cell.cpp | Strider-7/code | e096c0d0633b53a07bf3f295cb3bd685b694d4ce | [
"MIT"
] | null | null | null | graph/nearest-1-from-each-cell.cpp | Strider-7/code | e096c0d0633b53a07bf3f295cb3bd685b694d4ce | [
"MIT"
] | null | null | null | #include <bits/stdc++.h>
using namespace std;
int distance(vector<vector<int>> &mat, int i, int j, int N, int M, vector<vector<int>> &res)
{
if (i < 0 || i >= N || j < 0 || j >= M || mat[i][j] == 5)
return INT32_MAX;
if (mat[i][j] == 0)
return 0;
int x = mat[i][j];
mat[i][j] == 5;
int a = distance(mat, i, j - 1, N, M, res);
int b = distance(mat, i, j + 1, N, M, res);
int c = distance(mat, i - 1, j, N, M, res);
int d = distance(mat, i + 1, j, N, M, res);
res[i][j] = (x == 1) ? 0 : 1 + min({a, b, c, d});
return res[i][j];
}
vector<vector<int>> nearest(vector<vector<int>> &mat, int N, int M)
{
vector<vector<int>> res(N, vector<int>(M, 0));
distance(mat, 0, 0, N, M, res);
return res;
}
int main()
{
vector<vector<int>> v = {{1, 0}, {0, 1}};
v = nearest(v, 2, 2);
for (auto &&i : v)
{
for (auto &&j : i)
cout << j << " ";
cout << endl;
}
} | 23.488372 | 93 | 0.445545 | [
"vector"
] |
a176627e3105f1dff4f6429a7c692b5a1d098ebb | 54,236 | cc | C++ | mpid/nt2unix/src/nt2unix.cc | RWTH-OS/MP-MPICH | f2ae296477bb9d812fda587221b3419c09f85b4a | [
"mpich2"
] | null | null | null | mpid/nt2unix/src/nt2unix.cc | RWTH-OS/MP-MPICH | f2ae296477bb9d812fda587221b3419c09f85b4a | [
"mpich2"
] | null | null | null | mpid/nt2unix/src/nt2unix.cc | RWTH-OS/MP-MPICH | f2ae296477bb9d812fda587221b3419c09f85b4a | [
"mpich2"
] | 1 | 2021-01-23T11:01:01.000Z | 2021-01-23T11:01:01.000Z | /*
nt2unix is Copyright (c) 1997, 1998 by
| _ : Sven M. Paas, Lehrstuhl fuer Betriebssysteme (LfBS)
|_|_`__ : RWTH Aachen, Kopernikusstr. 16, D-52056 Aachen
| |__) : Tel. : +49-241-80-5162, Fax: +49-241-8888-339
|__) : e-mail: sven@lfbs.rwth-aachen.de [PGP-public-key]
*/
#ifdef __POSIX_THREADS__
#include <pthread.h>
#else
#include <thread.h>
#endif
#ifndef linux
#include <synch.h>
#endif
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#ifndef linux
#include <sys/systeminfo.h>
#include <stropts.h>
#include <poll.h>
#include <sys/mman.h>
#else
#include <sys/ioctl.h>
#include <fstream.h>
#endif
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <vector>
#include <map>
#ifndef __cplusplus
#error "nt2unix.cc: this file is C++."
#endif
#include "nt2unix.h"
#ifdef __POSIX_THREADS__
#define thr_self pthread_self
#define thread_t pthread_t
#ifndef linux
#define SIGUNUSED SIGUSR1
#endif
// Mutex-functions and types
#define mutex_t pthread_mutex_t
#define mutex_destroy pthread_mutex_destroy
#define mutex_unlock pthread_mutex_unlock
#define mutex_trylock pthread_mutex_trylock
#define mutex_lock pthread_mutex_lock
// Local storage
#define thread_key_t pthread_key_t
#endif
#ifdef _DEBUG
CRITICAL_SECTION _DBGCS;
#define DBG(m) { cerr<<"[nt2unix:"<<thr_self()<<": "<<m<<"]"<<endl<<flush; }
#else
#define DBG(m) {}
#endif
// #define _DEBUGSYNC
#ifdef _DEBUGSYNC
//CRITICAL_SECTION _DBGCS;
#define DBGS(m) { cerr<<"[nt2unix:"<<thr_self()<<": "<<m<<"]"<<endl<<flush; }
#else
#define DBGS(m) {}
#endif
#ifdef sparc
#define PATH_PREFIX "/global/tmp"
#else
#define PATH_PREFIX 0
#endif
// A comfortable critical section object.
class CriticalSection {
public:
CriticalSection::CriticalSection() {
InitializeCriticalSection(&cs);
}
CriticalSection::~CriticalSection() {
DeleteCriticalSection(&cs);
}
inline void CriticalSection::enter() {
EnterCriticalSection(&cs);
}
inline void CriticalSection::leave() {
LeaveCriticalSection(&cs);
}
protected:
CRITICAL_SECTION cs;
};
#define SYSVSEGMENT 0
#define FILESEGMENT 1
// We manage a list (a vector) of created file mappings.
struct FileMapping {
LPVOID lpBaseAddress; // base address of mapping
DWORD dwNumberOfBytesToMap; // mapping size
HANDLE hFileMappingObject; // file handle
char FileName[MAX_PATH]; // file name
DWORD refcnt; // number of references to the mapping
DWORD type;
};
static vector<FileMapping> FileMappings;
// The NT kernel stores various information along with each thread.
// We try to emulate this by our ThreadInfo struct for each thread.
#define THREAD_RUNNING 0
#define THREAD_SUSPENDED 1
#define THREAD_TERMINATED 2
//Threads----------------------------------------------------------------------------------------------
struct ThreadInfo {
ThreadInfo::ThreadInfo() {
ThreadInfo::init(THREAD_RUNNING);
}
ThreadInfo::ThreadInfo(DWORD aState) {
ThreadInfo::init(aState);
}
#ifdef __POSIX_THREADS__
// We need a copy constructor because the map copies
// elements. We have to avoid destruction of the
// mutex and the condition when struct is copied.
// And creation of unused synch. objects.
ThreadInfo::ThreadInfo(const ThreadInfo& other) {
state=other.state;
suspendCount=other.suspendCount;
exitCode=other.exitCode;
mutex=other.mutex;
cond=other.cond;
// other.cond=0;
// other.mutex=0;
counter=other.counter;
(*counter)++;
}
ThreadInfo::~ThreadInfo() {
(*counter)--;
if(*counter) return;
if(cond) {
pthread_cond_destroy(cond);
delete cond;
cond=0;
}
if(mutex) {
pthread_mutex_destroy(mutex);
delete mutex;
mutex=0;
}
delete counter;
counter=0;
}
private:
// Hide assignment operator to avoid dangerous copies.
bool ThreadInfo::operator=(ThreadInfo& other);
public:
#endif
inline void ThreadInfo::init(DWORD aState) {
state = aState;
suspendCount=0;
exitCode = 0;
#ifdef __POSIX_THREADS__
cond=new pthread_cond_t;
mutex= new pthread_mutex_t;
pthread_cond_init(cond,0);
pthread_mutex_init(mutex,0);
counter=new DWORD;
*counter=1;
#else
threadHasBeenResumed = FALSE;
#endif
}
volatile DWORD suspendCount; // suspend count, see ThreadResume(), ThreadSuspend()
volatile DWORD state; // state: THREAD_*
DWORD exitCode; // the thread's exit code
#ifdef __POSIX_THREADS__
pthread_cond_t *cond;
pthread_mutex_t *mutex;
DWORD *counter;
#else
volatile BOOL threadHasBeenResumed;
// A special flag to synchronize SuspendThread() / ResumeThread()
#endif
};
typedef map<HANDLE, ThreadInfo, less<HANDLE> > ThreadInfoMap;
static ThreadInfoMap ThreadInfos;
// We must protect the access to the ThreadInfoMap:
static CriticalSection ThreadInfoLock;
/*Si*/
/*
// not used yet
struct HandleInfo {
DWORD handleType; // handletype of this handle (see below)
void *obj; // pointer to handled object
DWORD refcnt;
};
*/
// not used yet
#define HANDLETYPE_CONSOLE 0 // not supported
#define HANDLETYPE_EVENTFILE 1 // not supported
#define HANDLETYPE_FILEMAPPING 2
#define HANDLETYPE_MUTEX 3
#define HANDLETYPE_NAMEDPIPE 4
#define HANDLETYPE_PROCESS 5
#define HANDLETYPE_SEMAPHORE 6
#define HANDLETYPE_THREAD 7
#define HANDLETYPE_TOKEN 8
#ifdef __cplusplus
extern "C" {
#endif
// Try to map a NT-style PTHREAD_START_ROUTINE to a Solaris-style
// start_func() (see "man -s 3T thr_create()").
typedef void * (*solaris_PTHREAD_START_ROUTINE)(void *);
#ifdef __POSIX_THREADS__
struct pthread_start_struct {
solaris_PTHREAD_START_ROUTINE routine;
void *arg;
DWORD suspended;
};
void *posix_start_routine(pthread_start_struct * s) {
DSECTION("posix_start_routine");
void *erg;
DSECTENTRYPOINT;
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,0);
if(s->suspended==CREATE_SUSPENDED) SuspendThread((HANDLE)pthread_self());
erg=s->routine(s->arg);
delete s;
DSECTLEAVE
return erg;
}
#endif
// Threading functions ---------------------------------------------------
WINBASEAPI
HANDLE
WINAPI
CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
DWORD dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
)
{
DSECTION("CreateThread");
ThreadInfoLock.enter();
DWORD state = THREAD_RUNNING; // the new thread's default state.
#ifdef __POSIX_THREADS__
pthread_attr_t attr;
pthread_start_struct *start_struct;
#endif
DSECTENTRYPOINT;
if (lpThreadAttributes)
DBG("CreateThread(): LPSECURITY_ATTRIBUTES not supported.");
#ifdef __POSIX_THREADS__
pthread_attr_init(&attr);
/* system-wide contention */
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
start_struct=new pthread_start_struct;
start_struct->arg=lpParameter;
start_struct->suspended=dwCreationFlags;
start_struct->routine=(solaris_PTHREAD_START_ROUTINE)lpStartAddress;
if (pthread_create((thread_t *)lpThreadId,&attr,
(solaris_PTHREAD_START_ROUTINE) posix_start_routine,
start_struct)) {
DSECTLEAVE
return 0;
}
#else
if (thr_create(0, (size_t)dwStackSize,
(solaris_PTHREAD_START_ROUTINE) lpStartAddress,
lpParameter,
(long)dwCreationFlags | THR_BOUND | THR_NEW_LWP,
(thread_t *)lpThreadId)) {
DSECTLEAVE
return 0;
}
#endif
if ((dwCreationFlags & CREATE_SUSPENDED) == CREATE_SUSPENDED) {
DBG("Creating suspended thread");
state = THREAD_SUSPENDED;
}
// Create a ThreadInfo struct for the new thread.
ThreadInfo thisThreadInfo(state);
#ifndef __POSIX_THREADS__
if (state==THREAD_SUSPENDED) {
thisThreadInfo.suspendCount=1;
thisThreadInfo.threadHasBeenResumed = TRUE;
}
#endif
// add it to the global Map of ThreadInfos with the handle as key.
DBG("CreateThread(): inserting handle "<< *lpThreadId);
ThreadInfos.insert(ThreadInfoMap::value_type((HANDLE)*lpThreadId, thisThreadInfo));
ThreadInfoLock.leave();
// Under UNIX, we define the thread id as the handle.
// This is incompatible to NT, but should work to some extend.
DSECTLEAVE
return (HANDLE)*lpThreadId;
}
WINBASEAPI
HANDLE
WINAPI
CreateRemoteThread(
HANDLE hProcess,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
DWORD dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
)
{
DBG("CreateRemoteThread() not supported.");
return 0;
}
WINBASEAPI
HANDLE
WINAPI
GetCurrentThread(
VOID
)
{
#ifdef __POSIX_THREADS__
return (HANDLE)pthread_self();
#else
return (HANDLE)thr_self();
#endif
}
WINBASEAPI
DWORD
WINAPI
GetCurrentThreadId(
VOID
)
{
return (DWORD)thr_self();
}
WINBASEAPI
DWORD
WINAPI
SetThreadAffinityMask(
HANDLE hThread,
DWORD dwThreadAffinityMask
)
{
DBG("SetThreadAffinityMask() not supported.");
return 0;
}
WINBASEAPI
BOOL
WINAPI
SetThreadPriority(
HANDLE hThread,
int nPriority
)
{
DBG("SetThreadPriority() not supported.");
return 0;
}
WINBASEAPI
int
WINAPI
GetThreadPriority(
HANDLE hThread
)
{
DBG("GetThreadPriority() not supported.");
return 0;
}
WINBASEAPI
BOOL
WINAPI
GetThreadTimes(
HANDLE hThread,
LPFILETIME lpCreationTime,
LPFILETIME lpExitTime,
LPFILETIME lpKernelTime,
LPFILETIME lpUserTime
)
{
DBG("GetThreadTimes() not supported.");
return FALSE;
}
WINBASEAPI
VOID
WINAPI
ExitThread(
DWORD dwExitCode
)
{
DSECTION("ExitThread");
DSECTENTRYPOINT;
ThreadInfoLock.enter();
ThreadInfoMap::iterator thisThreadInfo =
ThreadInfos.find(GetCurrentThread());
if (thisThreadInfo != ThreadInfos.end()) {
// found it.
(*thisThreadInfo).second.exitCode = dwExitCode;
(*thisThreadInfo).second.state = THREAD_TERMINATED;
ThreadInfoLock.leave();
#ifdef __POSIX_THREADS__
pthread_exit((void *)dwExitCode);
#else
thr_exit((void *)dwExitCode);
#endif
}
ThreadInfoLock.leave();
DBG("ExitThread() failed.");
DSECTLEAVE;
}
VOID ExitProcess(UINT uExitCode)
{
exit((int)uExitCode);
}
WINBASEAPI
BOOL
WINAPI
TerminateThread(
HANDLE hThread,
DWORD dwExitCode
)
{
DSECTION("TerminateThread");
DSECTENTRYPOINT;
ThreadInfoLock.enter();
ThreadInfoMap::iterator thisThreadInfo =
ThreadInfos.find(hThread);
if (thisThreadInfo != ThreadInfos.end()) {
// found it.
(*thisThreadInfo).second.exitCode = dwExitCode;
(*thisThreadInfo).second.state = THREAD_TERMINATED;
ThreadInfoLock.leave();
#ifdef __POSIX_THREADS__
if (pthread_cancel((pthread_t)hThread))
#else
if (thr_kill((thread_t)hThread, SIGKILL))
#endif
// failed.
DSECTLEAVE
return FALSE;
}
ThreadInfoLock.leave();
DSECTLEAVE
return FALSE;
}
WINBASEAPI
BOOL
WINAPI
GetExitCodeThread(
HANDLE hThread,
LPDWORD lpExitCode
)
{
DSECTION("GetExitCodeThread");
if (!lpExitCode)
return FALSE;
DSECTENTRYPOINT;
ThreadInfoLock.enter();
ThreadInfoMap::iterator thisThreadInfo =
ThreadInfos.find(hThread);
if (thisThreadInfo != ThreadInfos.end()) {
// found it.
if ((*thisThreadInfo).second.state != THREAD_TERMINATED)
*lpExitCode = (*thisThreadInfo).second.exitCode;
else
*lpExitCode = STILL_ACTIVE;
ThreadInfoLock.leave();
DSECTLEAVE
return TRUE;
}
ThreadInfoLock.leave();
DSECTLEAVE
return FALSE;
}
WINBASEAPI
BOOL
WINAPI
GetThreadSelectorEntry(
HANDLE hThread,
DWORD dwSelector,
LPLDT_ENTRY lpSelectorEntry
)
{
DBG("GetThreadSelectorEntry not supported.");
return FALSE;
}
DWORD ResumeThread(HANDLE hThread)
{
DSECTION("ResumeThread");
DWORD oldSuspendCount ;
DSECTENTRYPOINT;
ThreadInfoLock.enter();
DBG("Entering: ResumeThread, hThread ==" <<hThread);
ThreadInfoMap::iterator thisThreadInfo = ThreadInfos.find(hThread);
if (thisThreadInfo != ThreadInfos.end()) {
// found it.
#ifdef __POSIX_THREADS__
pthread_mutex_lock((*thisThreadInfo).second.mutex);
#endif
oldSuspendCount = (*thisThreadInfo).second.suspendCount;
if ((oldSuspendCount > 0)&&((*thisThreadInfo).second.state==THREAD_SUSPENDED)) {
(*thisThreadInfo).second.suspendCount--;
if (oldSuspendCount < 2) {
// oldSuspendCount == 1 -> new value is 0 -> really resume thread
// (*thisThreadInfo).second.state = THREAD_RUNNING;
#ifdef __POSIX_THREADS__
pthread_cond_signal((*thisThreadInfo).second.cond);
pthread_cond_wait((*thisThreadInfo).second.cond,(*thisThreadInfo).second.mutex);
DBG("Thread is now resumed...");
#else
do {
// Loop until the target thread is really resumed.
if (thr_continue((thread_t)hThread)) {
perror("thr_continue()");
ThreadInfoLock.leave();
DSECTLEAVE
return 0xFFFFFFFF;
}
// Give up the CPU so that the resumed thread has a chance to
// update the associated threadHasBeenResumed flag.
thr_yield();
} while (!(*thisThreadInfo).second.threadHasBeenResumed);
(*thisThreadInfo).second.state = THREAD_RUNNING;
DBG("ResumeThread(): thread really resumed, handle == "<<hThread);
#endif
} else {
DBG("ResumeThread(): thread stays suspended, cnt =="<<oldSuspendCount-1);
}
} else {
DBG("ResumeThread(): thread is not suspended, oldSuspendCount == "<<oldSuspendCount);
// oldSuspendCount == 0 -> thread is not currently suspended.
}
#ifdef __POSIX_THREADS__
pthread_mutex_unlock((*thisThreadInfo).second.mutex);
#endif
DBG("returning "<<oldSuspendCount<<flush);
ThreadInfoLock.leave();
DSECTLEAVE
return oldSuspendCount;
}
// thread not found.
DBG("ResumeThread(): thread handle not found, hThread == " << hThread);
ThreadInfoLock.leave();
DSECTLEAVE
return 0xFFFFFFFF;
}
DWORD SuspendThread(HANDLE hThread)
{
DSECTION("SuspendThread");
BOOL same = FALSE;
// this flag indicates whether a thread suspends itself.
// If same == TRUE, we must avoid a "lost signal" problem, see below.
DSECTENTRYPOINT;
ThreadInfoLock.enter();
ThreadInfoMap::iterator thisThreadInfo = ThreadInfos.find(hThread);
if (thisThreadInfo != ThreadInfos.end()) {
// found it.
DWORD oldSuspendCount = (*thisThreadInfo).second.suspendCount;
if (oldSuspendCount < MAXIMUM_SUSPEND_COUNT)
(*thisThreadInfo).second.suspendCount++;
if (oldSuspendCount < 1) {
#ifndef __POSIX_THREADS__
(*thisThreadInfo).second.state = THREAD_SUSPENDED;
#else
pthread_mutex_t *mutex=(*thisThreadInfo).second.mutex;
pthread_cond_t *cond=(*thisThreadInfo).second.cond;
pthread_mutex_lock(mutex);
#endif
if (same = (thr_self() == (thread_t)hThread)) {
// if the thread suspends itself, we must release the lock
// before actually calling thr_suspend(). Otherwise, the
// thread would hold the mutex while being suspended, resulting
// in a deadlock.
#ifdef __POSIX_THREADS__
(*thisThreadInfo).second.state = THREAD_SUSPENDED;
ThreadInfoLock.leave();
pthread_cond_wait(cond,mutex);
(*thisThreadInfo).second.state=THREAD_RUNNING;
pthread_cond_signal(cond);
pthread_mutex_unlock(mutex);
DSECTLEAVE
return 0;
// DANGER!!! If at this point, another thread
// is scheduled in ResumeThread(), the resume "signal" may get lost.
// To avoid this, ResumeThread() polls until the thread is
// really resumed, i.e. until threadHasBeenResumed == TRUE.
} else if(pthread_kill(pthread_t(hThread),SIGUNUSED)) {
#else
DBG("Suspending thread "<<hThread<<flush);
(*thisThreadInfo).second.threadHasBeenResumed = FALSE;
ThreadInfoLock.leave();
}
// (*thisThreadInfo).second.state = THREAD_SUSPENDED;
if (thr_suspend((thread_t)hThread)) {
#endif
perror("thr_suspend()");
DSECTLEAVE
return 0xFFFFFFFF;
}
#ifdef __POSIX_THREADS__
else {
pthread_cond_wait(cond,mutex);
}
pthread_mutex_unlock(mutex);
#else
(*thisThreadInfo).second.threadHasBeenResumed = TRUE;
#endif
if (!same)
ThreadInfoLock.leave();
} else {
DBG("SuspendThread(): thread already sleeping.");
ThreadInfoLock.leave();
}
DSECTLEAVE
return oldSuspendCount;
}
// Thread not found.
DBG("SuspendThread(): Thread handle not found, hThread == "<<hThread);
ThreadInfoLock.leave();
DSECTLEAVE
return 0xFFFFFFFF;
}
#ifdef __POSIX_THREADS__
#define thr_keycreate pthread_key_create
#define thr_setspecific pthread_setspecific
#endif
WINBASEAPI
DWORD
WINAPI
TlsAlloc(
VOID
)
{
DWORD key;
if(thr_keycreate( (thread_key_t *)&key, 0)) {
// failed.
perror("TlsAlloc(): thr_keycreate()");
return TLS_OUT_OF_INDEXES;
}
return key;
}
WINBASEAPI
LPVOID
WINAPI
TlsGetValue(
DWORD dwTlsIndex
)
{
LPVOID value;
#ifdef __POSIX_THREADS__
if ((value=pthread_getspecific((thread_key_t)dwTlsIndex))==0) {
#else
if (thr_getspecific((thread_key_t)dwTlsIndex, &value)) {
#endif
// failed.
perror("TlsGetValue(): thr_getspecific()");
return 0;
}
return value;
}
WINBASEAPI
BOOL
WINAPI
TlsSetValue(
DWORD dwTlsIndex,
LPVOID lpTlsValue
)
{
if (thr_setspecific((thread_key_t)dwTlsIndex, lpTlsValue)) {
// failed.
perror("TlsSetValue(): thr_setspecific()");
return FALSE;
}
return TRUE;
}
WINBASEAPI
BOOL
WINAPI
TlsFree(
DWORD dwTlsIndex
)
{
// Solaris doesnot support key delete functions!
// POSIX defines pthread_key_delete(), however.
#ifdef __POSIX_THREADS__
pthread_key_delete((pthread_key_t)dwTlsIndex);
#else
DBG("TlsFree() not supported.");
#endif
return TRUE;
}
//EndThreads---------------------------------------------------------------------------------------------
WINBASEAPI
BOOL
WINAPI
CloseHandle(
HANDLE hObject
)
{
DSECTION("CloseHandle");
DSECTENTRYPOINT;
// Handles are somewhat NT-specific. At the moment, we ignore them.
HandleInfo* Object; // *******
Object = new HandleInfo; // *******
Object = (HandleInfo*)hObject; // *******
vector<FileMapping>::iterator i=FileMappings.begin();
while(i != FileMappings.end() && i->hFileMappingObject != Object->obj) // *******
i++;
if (i != FileMappings.end()) {
if(i->type==SYSVSEGMENT) {
if(shmctl((int)Object->obj,IPC_RMID,0)<0) {
perror("shmctl");
}
} else {
close((int)Object->obj);
}
}
DSCECTLEAVE
return TRUE;
}
WINBASEAPI
BOOL
WINAPI
DuplicateHandle(
HANDLE hSourceProcessHandle,
HANDLE hSourceHandle,
HANDLE hTargetProcessHandle,
LPHANDLE lpTargetHandle,
DWORD dwDesiredAccess,
BOOL bInheritHandle,
DWORD dwOptions
)
{
DSECTION("DuplicateHandle");
HandleInfo* SourceInfo;
DSECTENTRYPOINT;
// we ignore handles. Just copy the "handle".
// We should use dup() or dup2() for file handles, however.
DBG("DuplicateHandle() not supported. Use dup(2)/dup2(2) if appropriate.");
SourceInfo = (HandleInfo*) hSourceHandle;
SourceInfo->refcnt++;
hSourceHandle = (HANDLE) SourceInfo;
*lpTargetHandle = hSourceHandle;
DSECTLEAVE
return TRUE;
}
WINBASEAPI
BOOL
WINAPI
GetHandleInformation(
HANDLE hObject,
LPDWORD lpdwFlags
)
{
// we ignore handles.
DBG("GetHandleInformation() not supported.");
return FALSE;
}
DWORD WaitForSingleObject(
HANDLE hHandle,
DWORD dwMilliseconds
)
{
DSECTION("WaitForSingleObject");
DSECTENTRYPOINT;
if (dwMilliseconds != INFINITE)
DBG("WaitForSingleObject(): dwMilliseconds != INFINITE not supported.");
DBG("Calling thr_join");
#ifdef __POSIX_THREADS__
DNOTICE("calling pthread_join");
if(pthread_join((pthread_t)hHandle,0)) {
#else
DNOTICE("calling thr_join");
if (thr_join((thread_t)hHandle, 0, 0)) {
#endif
DBG("WaitForSingleObject(): thr_join() failed\n");
DSECTLEAVE
return WAIT_FAILED;
}
DBG("Back from join");
DSECTLEAVE
return WAIT_OBJECT_0;
}
//EndHandles---------------------------------------------------------------------------------------------------------------
//Begin Process-------------------------------------------------------------------------------------------------------
// Process Functions --------------------------------------------------------
WINBASEAPI
DWORD
WINAPI
GetCurrentProcessId(
VOID
)
{
return (DWORD)getpid();
}
WINBASEAPI
HANDLE
WINAPI
GetCurrentProcess(
VOID
)
{
return (HANDLE)getpid();
}
//End Process----------------------------------------------------------------------------------------
// Thread-Synchronization Functions -----------------------------------------
WINBASEAPI
VOID
WINAPI
InitializeCriticalSection(
LPCRITICAL_SECTION lpCriticalSection
)
{
DSECTION("InitializeCriticalSection");
assert(lpCriticalSection);
DSECTENTRYPOINT;
lpCriticalSection->LockCount = 0;
lpCriticalSection->RecursionCount = 0;
lpCriticalSection->OwningThread = (HANDLE)0xFFFFFFFF;
lpCriticalSection->LockSemaphore = malloc(sizeof(mutex_t));
if (!lpCriticalSection->LockSemaphore)
perror("InitializeCriticalSection(): malloc()");
#ifdef __POSIX_THREADS__
pthread_mutex_init((mutex_t *)(lpCriticalSection->LockSemaphore),0);
#else
mutex_init((mutex_t *)(lpCriticalSection->LockSemaphore),
USYNC_THREAD, 0);
#endif
DSECTLEAVE
return;
}
WINBASEAPI
VOID
WINAPI
DeleteCriticalSection(
LPCRITICAL_SECTION lpCriticalSection
)
{
DSECTION("DeleteCriticalSection");
assert(lpCriticalSection);
DSECTENTRYPOINT;
mutex_destroy((mutex_t *)(lpCriticalSection->LockSemaphore));
free(lpCriticalSection->LockSemaphore);
lpCriticalSection->LockSemaphore = 0;
DSECTLEAVE
return;
}
WINBASEAPI
VOID
WINAPI
EnterCriticalSection(
LPCRITICAL_SECTION lpCriticalSection
)
{
DSECTION("EnterCriticalSection");
thread_t me;
DSECTENTRYPOINT;
me = thr_self();
assert(lpCriticalSection);
if(mutex_trylock((mutex_t *)(lpCriticalSection->LockSemaphore))) {
// The mutex is not free...
if (lpCriticalSection->OwningThread == (HANDLE)me) {
// I have the lock. This cannot be a race condition.
lpCriticalSection->RecursionCount++;
DBGS("New Recursion count of mutex is: "<<lpCriticalSection->RecursionCount++);
DSECTLEAVE
return;
}
DBGS("Trying to lock, LockSema =="<<lpCriticalSection->LockSemaphore);
if(mutex_lock((mutex_t *)(lpCriticalSection->LockSemaphore)))
cerr<<"EnterCriticalSection(): mutex_lock() failed, errno == "<<GetLastError()<<endl<<flush;
}
// got it. I must be the first thread:
if (lpCriticalSection->RecursionCount) {
cerr<<"EnterCriticalSection(): RecursionCount != 0"<<endl<<flush;
DSECTLEAVE
return;
}
lpCriticalSection->RecursionCount = 1;
lpCriticalSection->OwningThread = (HANDLE)me;
DBGS("Mutex Acquired, Owner == "<<me<<" LockSema == " <<
lpCriticalSection->LockSemaphore);
DSECTLEAVE
return;
}
WINBASEAPI
VOID
WINAPI
LeaveCriticalSection(
LPCRITICAL_SECTION lpCriticalSection
)
{
DSECTION("LeaveCriticalSection");
thread_t me;
DSECTENTRYPOINT;
assert(lpCriticalSection);
DBGS("Trying to unlock, LockSema =="<<lpCriticalSection->LockSemaphore);
me = thr_self();
if (lpCriticalSection->OwningThread == (HANDLE)me) {
lpCriticalSection->RecursionCount--;
if (lpCriticalSection->RecursionCount < 1) {
lpCriticalSection->OwningThread = (HANDLE)0xFFFFFFFF;
DBGS("Mutex release, me == "<<me<<" LockSema == "<<lpCriticalSection->LockSemaphore);
if(mutex_unlock((mutex_t *)lpCriticalSection->LockSemaphore))
cerr<<"LeaveCriticalSection(): mutex_unlock() failed, errno == "<<GetLastError()<<endl<<flush;
}
} else {
cerr<<"LeaveCriticalSection(): not lock owner, me == "<<me<<" owner == "<<lpCriticalSection->OwningThread<<" LockSema =="<<lpCriticalSection->LockSemaphore<<endl<<flush;
}
DSECTLEAVE
return;
}
//EndThreadSync---------------------------------------------------------------------------------------------------
// Virtual Memory Management Funtions -----------------------------------------------------------------------------
BOOL VirtualLock(LPVOID lpAddress, DWORD dwSize)
{
if (mlock((caddr_t)lpAddress, (size_t)dwSize))
// failed
return FALSE;
return TRUE;
}
BOOL VirtualUnlock(LPVOID lpAddress, DWORD dwSize)
{
if (munlock((caddr_t)lpAddress, (size_t)dwSize))
// failed
return FALSE;
return TRUE;
}
WINBASEAPI
LPVOID
WINAPI
VirtualAlloc(
LPVOID lpAddress,
DWORD dwSize,
DWORD flAllocationType,
DWORD flProtect
)
{
DSECTION("VirtualAlloc");
int flags = 0;
DSECTENTRYPOINT;
/*
cerr<<"VirtualAlloc() "<<lpAddress<<" Size "<<dwSize;
if (flAllocationType & MEM_COMMIT)
cerr<<" MEM_COMMIT ";
if (flAllocationType & MEM_RESERVE)
cerr<<" MEM_RESERVE ";
if (flProtect & PROT_READ)
cerr<<" READ ";
if (flProtect & PROT_WRITE)
cerr<<" WRITE ";
cerr<<endl;
*/
if ( ((flProtect & PAGE_GUARD) == PAGE_GUARD) ||
((flProtect & PAGE_NOCACHE) == PAGE_NOCACHE) )
DBG("VirtualAlloc(): PAGE_GUARD, PAGE_NOCACHE not supported.");
if ( ((flAllocationType & MEM_TOP_DOWN) == MEM_TOP_DOWN) )
DBG("VirtualAlloc(): MEM_TOP_DOWN not supported.");
// We have to emulate the MEM_RESERVE and MEM_COMMIT options.
// Under Unix, we reserve an address range by allocating
// it via valloc() but protecting in totally via mprotect().
// To commit an address range, the same is done -- but with
// user defined access rights.
// MEM_RESERVE
/*
if ( ((flAllocationType & MEM_RESERVE) == MEM_RESERVE) ) {
flags = MAP_PRIVATE;
if (lpAddress)
flags |= MAP_FIXED;
lpAddress = mmap(lpAddress, (size_t)dwSize, PROT_NONE, flags, -1, 0);
if (!lpAddress) {
perror("VirtualAlloc(): mmap()");
return 0;
}
}
*/
// First of all, allocate the region, if necessary.
if (!lpAddress) {
lpAddress = valloc((size_t)dwSize);
if (!lpAddress) {
perror("VirtualAlloc(): valloc()");
DSECTLEAVE
return 0;
}
}
// Note that, in this implementation, if both flags
// are specified, the range is just commited.
// (Because the memory is implicitely reserved.)
if ( ((flAllocationType & MEM_COMMIT) == MEM_COMMIT) ) {
// Just set the protection flags on the memory range.
if (mprotect((caddr_t)lpAddress, (size_t)dwSize, (int)flProtect) == -1) {
perror("VirtualAlloc(): mprotect()");
DSECTLEAVE
return 0;
}
} else {
if ( ((flAllocationType & MEM_RESERVE) == MEM_RESERVE) ) {
// Just protect the region totally.
if (mprotect((caddr_t)lpAddress, (size_t)dwSize, PROT_NONE) == -1) {
perror("VirtualAlloc(): mprotect()");
DSECTLEAVE
return 0;
}
}
}
DSECTLEAVE
return lpAddress;
}
WINBASEAPI
BOOL
WINAPI
VirtualFree(
LPVOID lpAddress,
DWORD dwSize,
DWORD dwFreeType
)
{
DSECTION("VirtualFree");
DSECTENTRYPOINT;
if ( (dwFreeType & MEM_DECOMMIT) == MEM_DECOMMIT ) {
// Hmm, this is not supported under UNIX.
// We just protect the pages totally, however.
if (mprotect((caddr_t)lpAddress, (size_t)dwSize, PROT_NONE) == -1) {
perror("VirtualFree(): mprotect()");
DSECTLEAVE
return FALSE;
}
//if (memcntl((caddr_t)lpAddress, (size_t)dwSize, MC_SYNC, MS_INVALIDATE, 0, 0) == -1)
// perror("memcntl()");
} else if ( (dwFreeType & MEM_RELEASE) == MEM_RELEASE ) {
if (dwSize) {
DSECTLEAVE
return FALSE; // man page says that dwSize must be zero in this case.
}
// Just free the memory range.
free(lpAddress);
} else{
// unknown parameter.
DSECTLEAVE
return FALSE;
}
// Everything ok.
DSECTLEAVE
return TRUE;
}
WINBASEAPI
BOOL
WINAPI
VirtualProtect(
LPVOID lpAddress,
DWORD dwSize,
DWORD flNewProtect,
PDWORD lpflOldProtect
)
{
DSECTION("VirtualProtect");
DSECTENTRYPOINT;
//sigset_t newSigset;
/*
cerr<<"VirtualProtect "<<lpAddress<< " Size "<<dwSize;
if (flNewProtect & PROT_READ)
cerr<<" READ ";
if (flNewProtect & PROT_WRITE)
cerr<<" WRITE ";
cerr<<endl;
*/
// DUMMY
DBG("VirtualProtect("<<lpAddress<<","<<flNewProtect<<"): returning lpflOldProtect not supported.");
if (lpflOldProtect)
*lpflOldProtect = 0;
//sigemptyset(&newSigset);
//sigaddset(&newSigset, SIGSEGV);
//sigprocmask(SIG_BLOCK, &newSigset, 0);
if (mprotect((caddr_t)lpAddress, (size_t)dwSize, (int)flNewProtect) == -1) {
perror("VirtualProtect(): mprotect()");
DSECTLEAVE
return FALSE;
}
//if (memcntl((caddr_t)lpAddress, (size_t)dwSize, MC_SYNC, MS_INVALIDATE | MS_SYNC, (int)flNewProtect, 0) == -1)
// perror("memcntl()");
//sigprocmask(SIG_UNBLOCK, &newSigset, 0);
DSECTLEAVE
return TRUE;
}
//Files------------------------------------------------------------------------------------------------------------------
WINBASEAPI
LPVOID
WINAPI
MapViewOfFile(
HANDLE hFileMappingObject,
DWORD dwDesiredAccess,
DWORD dwFileOffsetHigh,
DWORD dwFileOffsetLow,
DWORD dwNumberOfBytesToMap
)
{
return MapViewOfFileEx(hFileMappingObject,
dwDesiredAccess,
dwFileOffsetHigh,
dwFileOffsetLow,
dwNumberOfBytesToMap,
0);
}
#ifndef MAP_FAILED
#define MAP_FAILED -1
#endif
WINBASEAPI
LPVOID
WINAPI
MapViewOfFileEx(
HANDLE hFileMappingObject,
DWORD dwDesiredAccess,
DWORD dwFileOffsetHigh,
DWORD dwFileOffsetLow,
DWORD dwNumberOfBytesToMap,
LPVOID lpBaseAddress
)
{
DSECTION("MapViewOfFileEx");
int prot = 0, flags = 0;
LPVOID ret;
HandleInfo* Map; // *******
DSECTENTRYPOINT;
// Map = new HandleInfo; // *******
Map = (HandleInfo*)hFileMappingObject; // *******
DBG("Entering MapViewOfFileEx(). DesiredAccess== "<<dwDesiredAccess<<" FILE_MAP_COPY=="<<FILE_MAP_COPY);
if (dwFileOffsetHigh > 0)
DBG("MapViewOfFileEx(): ignoring dwFileOffsetHigh");
// Filter the protection bits ...
prot = dwDesiredAccess & FILE_MAP_ALL_ACCESS;
// ... and mapping flags:
flags = ((dwDesiredAccess & FILE_MAP_COPY)==FILE_MAP_COPY) ? MAP_PRIVATE : MAP_SHARED;
DBG("mapping "<<(flags==MAP_PRIVATE?"private":"shared"));
/* MAP_SHARED doesnot work correctly under Solaris SPARC 2.5.1 */
if (lpBaseAddress)
flags |= MAP_FIXED;
// Search and update the mapping in the vector.
vector<FileMapping>::iterator i=FileMappings.begin();
while(i != FileMappings.end() && i->hFileMappingObject != Map->obj) // *******
i++;
if (i != FileMappings.end()) {
if (dwNumberOfBytesToMap) {
DBG("Setting dwNumberOfBytesToMap to "<<dwNumberOfBytesToMap);
i->dwNumberOfBytesToMap = dwNumberOfBytesToMap;
}
} else {
DBG("MapViewOfFileEx(): mapping not found.");
DSECTLEAVE
return 0;
}
#if defined(_DEBUG) && !defined(SYSVSHM)
fprintf(stderr, "mmap(): lpBaseAddress == %x, prot == %d, flags == %d\n",
lpBaseAddress, prot, flags);
fprintf(stderr, " dwNumberOfBytesToMap == %d, dwFileOffsetLow == %d\n",
i->dwNumberOfBytesToMap, dwFileOffsetLow);
#endif
if(i->type==FILESEGMENT) {
if ((ret = (LPVOID)mmap((caddr_t)lpBaseAddress,
(size_t)i->dwNumberOfBytesToMap,
prot, flags, (int)Map->obj, // *******
(off_t)dwFileOffsetLow)) == (LPVOID)MAP_FAILED) {
perror("MapViewOfFileEx(): mmap() failed. \n");
DSECTLEAVE
return 0;
}
} else {
ret=shmat((int)Map->obj,(const void *)lpBaseAddress,0); // *******
if((int)ret==-1) {
perror("shmat");
DSECTLEAVE
return 0;
}
}
// Initialize the mapping.
DBG("Initializing mapping ...");
if (mprotect((caddr_t)ret, (size_t)i->dwNumberOfBytesToMap, PROT_WRITE) == -1)
perror("mprotect()");
/*
memset(ret, 0x00, (size_t)i->dwNumberOfBytesToMap);
*/
/* The following memset() is absolutely necessary,
even for NFS file systems !!!! */
memset(ret, 0x00, 4);
DBG("... done. prot is now "<< prot);
if (mprotect((caddr_t)ret, (size_t)i->dwNumberOfBytesToMap, prot) == -1)
perror("mprotect()");
DBG("MapViewOfFileEx(): set lpBaseAddress to "<<ret);
i->lpBaseAddress = ret;
DSECTLEAVE
return ret;
}
WINBASEAPI
BOOL
WINAPI
UnmapViewOfFile(
LPCVOID lpBaseAddress
)
{
DSECTION("UnmapViewOfFile");
// Search the mapping according to the lpBaseAddress.
DBG("UnmapViewOfFile(): searching for "<<lpBaseAddress);
vector<FileMapping>::iterator i=FileMappings.begin();
while(i != FileMappings.end() && i->lpBaseAddress != (LPVOID)lpBaseAddress)
i++;
if (i != FileMappings.end()) {
// found
if(i->type==FILESEGMENT) {
if (munmap((caddr_t)lpBaseAddress, (size_t)(i->dwNumberOfBytesToMap))<0) {
DBG("UnmapViewOfFile(): munmap() failed.");
DSECTLEAVE
return FALSE;
}
} else {
shmdt((char*)lpBaseAddress);
}
i->refcnt--;
/*
if (i->refcnt < 1)
FileMappings.erase(i);
bullshit
*/
DSECTLEAVE
return TRUE;
} else {
DBG("UnmapViewOfFile(): mapping not found.");
}
DSECTLEAVE
return FALSE;
}
WINBASEAPI
HANDLE
WINAPI
CreateFileMappingA(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCSTR lpName
)
{
DSECTION("CreateFileMappingA");
DSECTENTRYPOINT;
DBG("Entering CreateFileMappingA(), hFile == "<<hFile);
HandleInfo* Map;
Map = new HandleInfo;
Map->handleType = HANDLETYPE_FILEMAPPING;
int fildes;
struct FileMapping thisMapping;
// Initialize FileMapping structure
thisMapping.lpBaseAddress = 0;
thisMapping.dwNumberOfBytesToMap = 0;
thisMapping.hFileMappingObject = 0;
thisMapping.FileName[0] = 0;
thisMapping.refcnt = 1;
if (lpFileMappingAttributes)
DBG("CreateFileMappingA(): lpFileMappingAttributes not supported.");
if (hFile == (HANDLE)0xFFFFFFFF) {
// user must specify file size
if ((dwMaximumSizeHigh < 1) && (dwMaximumSizeLow < 1))
DBG("CreateFileMappingA(): dwMaximumSize == 0");
DBG("Creating segment of size "<<dwMaximumSizeLow);
// Open a file of size dwMaximumSizeLow.
if (dwMaximumSizeHigh > 0)
DBG("CreateFileMappingA(): ignoring dwMaximumSizeHigh");
#ifdef SYSVSHM
fildes=shmget(IPC_PRIVATE,dwMaximumSizeLow,0600);
if(fildes==-1) {
perror("shmget()");
DBG("Cannot SHMOpen\n");
DSECTLEAVE
return 0;
}
thisMapping.type=SYSVSEGMENT;
#else
thisMapping.type=FILESEGMENT;
#endif
if (!lpName) {
#ifndef SYSVSHM
// We dont use tmpfile(), since it obviously generates only
// one file per process.
// NOTE: Mapping with MAP_SHARED doesnot
// work correctly on a non-NFS file system under Solaris SPARC.
lpName = tempnam(PATH_PREFIX,"svm__");
if (!lpName) {
DBG("CreateFileMappingA: tempnam() failed.");
DSECTLEAVE
return 0;
}
DBG("CreateFileMappingA(): creating temporary file: "<<lpName<<" Prefix is: "<<PATH_PREFIX);
fildes = open((const char*)lpName,
O_CREAT | O_RDWR, 0600);
if (!fildes) {
DBG("CreateFileMappingA(): cannot create file.");
DSECTLEAVE
return 0;
}
// make sure the file is really of the right size.
if(ftruncate(fildes, (off_t)((dwMaximumSizeLow/8192+1)*8192) ) == -1)
perror("CreateFileMappingA(): ftruncate()");
unlink((const char *)lpName);
#endif
} else {
#ifndef SYSVSHM
fildes = open((const char*)lpName, O_RDWR);
#endif
strcpy(thisMapping.FileName, lpName);
}
if (!fildes) {
DBG("CreateFileMappingA(): cannot create / open file.");
DSECTLEAVE
return 0;
}
thisMapping.hFileMappingObject = (HANDLE)fildes;
thisMapping.dwNumberOfBytesToMap = dwMaximumSizeLow;
FileMappings.push_back(thisMapping);
Map->obj = (HANDLE)fildes;
DSECTLEAVE
return (HANDLE)Map;
}
fildes = (int)hFile;
thisMapping.hFileMappingObject = hFile;
thisMapping.type=FILESEGMENT;
if(!dwMaximumSizeLow) {
// In this case, we must take the size of the specified file
// as the size of the mapping.
if ( (off_t)(dwMaximumSizeLow = lseek(fildes, 0, SEEK_END)) == -1)
perror("CreateFileMappingA(): lseek()");
if (dwMaximumSizeLow < 1) {
DBG("CreateFileMappingA(): cannot create empty file mapping.");
DSECTLEAVE
return 0;
}
}
thisMapping.dwNumberOfBytesToMap = dwMaximumSizeLow;
FileMappings.push_back(thisMapping);
Map->obj = hFile; /*Si*/
DSECTLEAVE
return (HANDLE)Map;
}
//----------------------------------------------------------------------------------------------------------
DWORD GetLastError(VOID)
{
perror("GetLastError()");
return (DWORD)errno;
}
VOID SetLastError(DWORD dwErrCode)
{
errno = (DWORD)dwErrCode;
}
UINT SetErrorMode(UINT uMode)
{
DBG("SetErrorMode() not supported.\n");
return 0;
}
VOID Sleep(DWORD dwMilliseconds)
{
switch(dwMilliseconds) {
case 0:
thr_yield();
break;
case INFINITE:
#ifdef __POSIX_THREADS__
// pthread_kill(pthread_self(),SIGSTOP);
select(0,0,0,0,0);
#else
thr_suspend(thr_self());
#endif
break;
default:
// We could also use the POSIX call nanosleep(2) here
#ifdef linux
usleep(dwMilliseconds*1000);
#else
poll(0, 0, (int)dwMilliseconds);
#endif
break;
}
return;
}
#ifdef linux
int calcNumProcs() {
::ifstream cpuinfo("/proc/cpuinfo");
int count=0;
char s[255];
if(!cpuinfo) {
DBG("Sorry, cannot open /proc/cpuinfo");
return 1;
}
while(!cpuinfo.eof()) {
cpuinfo>>s;
if(!strncmp("processor",s,9)) count++;
}
return count;
}
// This is just a quick hack.
// We should improve this!!
VOID GetSystemInfo(LPSYSTEM_INFO lpSystemInfo)
{
DSECTION("GetSystemInfo");
DSECTENTRYPOINT;
DWORD i = 0;
DWORD procset = 0;
lpSystemInfo->wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
// This should not be hardcoded:
lpSystemInfo->wProcessorLevel = 5;
lpSystemInfo->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
lpSystemInfo->dwNumberOfProcessors = calcNumProcs();
lpSystemInfo->dwActiveProcessorMask = 0xFFFF;
lpSystemInfo->dwPageSize =
lpSystemInfo->dwAllocationGranularity = 4096;
// We just use 1 GB above the maximum address on the heap.
// This implies that we now have only 1 GB for the process stack.
lpSystemInfo->lpMinimumApplicationAddress = (LPVOID)0x88000000;
lpSystemInfo->lpMaximumApplicationAddress = (LPVOID)0xa0000000;
DSECTLEAVE;
}
#else
#define SYSINFOBUFMAX 256
VOID GetSystemInfo(LPSYSTEM_INFO lpSystemInfo)
{
DSECTION("GetSystemInfo");
char buf[SYSINFOBUFMAX];
long buflen = 0;
DWORD i = 0;
DWORD procset = 0;
DSECTENTRYPOINT;
assert(lpSystemInfo);
memset(lpSystemInfo, 0, sizeof(SYSTEM_INFO));
buflen = sysinfo(SI_ARCHITECTURE, buf, SYSINFOBUFMAX);
if (strcmp(buf, "sparc") == 0) {
lpSystemInfo->wProcessorArchitecture = PROCESSOR_ARCHITECTURE_SPARC;
} else if (strcmp(buf, "i386") == 0) {
lpSystemInfo->wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
// This should not be hardcoded:
lpSystemInfo->wProcessorLevel = 5;
lpSystemInfo->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
} else
lpSystemInfo->wProcessorArchitecture = PROCESSOR_ARCHITECTURE_UNKNOWN;
lpSystemInfo->dwNumberOfProcessors = sysconf(_SC_NPROCESSORS_ONLN);
procset = sysconf(_SC_NPROCESSORS_CONF);
for (i = 0; i < procset; i++)
lpSystemInfo->dwActiveProcessorMask |= ((DWORD)1 << i);
lpSystemInfo->dwPageSize =
lpSystemInfo->dwAllocationGranularity = (DWORD)sysconf(_SC_PAGESIZE);
// A Solaris SPARC process has 4 GB of virtual address space.
// It is partioned as follows:
//
// +-------+ 0xFFFFFFFF
// | STACK |
// | | | Stack grows from top, max. 2 GB (RLIMIT_STACK) size
// | V | See getrlimit(2).
// | |
// | |
// | |
// | |
// | |
// +-------+ 0x80000000 (maximum brk(2) value, e.g. &_etext+RLIMIT_DATA)
// | ^ |
// | | | Heap grows from bottom after data segment to brk value.
// | HEAP |
// +-------+ &_end See end(3C)
// | | &_edata
// | DATA |
// +-------+ &_etext
// | TEXT |
// +-------+ 0x00000000
//
// We just use 1 GB above the maximum address on the heap.
// This implies that we now have only 1 GB for the process stack.
lpSystemInfo->lpMinimumApplicationAddress = (LPVOID)0x88000000;
lpSystemInfo->lpMaximumApplicationAddress = (LPVOID)0xc8000000;
DSECTLEAVE;
}
#endif
WINBASEAPI
BOOL
WINAPI
GetComputerName(LPTSTR lpBuffer, LPDWORD nSize)
{
if (gethostname(lpBuffer, *nSize))
return FALSE;
return TRUE;
}
//EndGeneralStuff-----------------------------------------------------------------------------------------------------
// WinSock API -------------------------------------------------------
int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData)
{
if(!lpWSAData)
return WSAEFAULT;
// pretend to support the WinSock 2.0 API.
lpWSAData->wVersion =
lpWSAData->wHighVersion = 0x0002;
strcpy(lpWSAData->szDescription, "This is WinFake 0.1\n");
strcpy(lpWSAData->szSystemStatus, "[still buggy]");
return 0;
}
int PASCAL FAR WSACleanup(void)
{
return 0;
}
int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp)
{
// This is untested.
if (ioctl(s, cmd, argp) == -1)
return SOCKET_ERROR;
return 0;
}
// Exception handling. ----------------------------------------------
static LPTOP_LEVEL_EXCEPTION_FILTER topFilter = 0;
#ifdef __POSIX_THREADS__
void posixResumeHandler(int sig) {
DSECTION("posixResumeHandler");
DSECTENTRYPOINT;
DBG("Entering posixSleepHandler");
ThreadInfoMap::iterator thisThreadInfo = ThreadInfos.find((HANDLE)pthread_self());
// We dn't need synchonization here because the list is locked
// in SuspendThread by the signal sender.
if (thisThreadInfo != ThreadInfos.end()) {
pthread_cond_t *cond=(*thisThreadInfo).second.cond;
pthread_mutex_t *mutex=(*thisThreadInfo).second.mutex;
// I will block here until Suspender has called cond_wait
pthread_mutex_lock(mutex);
DBG("Suspending thread");
(*thisThreadInfo).second.state=THREAD_SUSPENDED;
pthread_cond_signal(cond);
pthread_cond_wait(cond,mutex);
(*thisThreadInfo).second.state=THREAD_RUNNING;
pthread_cond_signal(cond);
pthread_mutex_unlock(mutex);
} else {
fprintf(stderr,"posixSleepHandler(): cannot find thread %x\n",pthread_self());
ThreadInfoLock.leave();
}
DBG("Leaving posixSleepHandler");
DSECTLEAVE
return;
}
#endif
#ifdef linux
inline void globalSignalHandler(int sig);
#else
inline void globalSignalHandler(int sig, siginfo_t *sip, void *uap);
#endif
#define MAX_SIGNALS (SIGUSR2+1)
// the maximum catchable signal number is defined by MAX_SIGNALS-1.
// The following class translates Solaris signal codes into
// Windows NT exception codes.
// Note that this is not possible for all codes.
// The following codes may be translated in a meaningful way:
//
// Unix signal code Windows NT exception code
// --------------------------------------------------------
// SIGSEGV EXCEPTION_ACCESS_VIOLATION
// SIGFPE EXCEPTION_FLT_INVALID_OPERATION
// SIGILL EXCEPTION_ILLEGAL_INSTRUCTION
// SIGBUS EXCEPTION_IN_PAGE_ERROR
// SIGTRAP EXCEPTION_SINGLE_STEP
struct _UnixException {
_UnixException::_UnixException() {
DBG("Entering ::_UnixException() ...");
globalSignalMask = (1 << SIGSEGV) |
(1 << SIGFPE) |
(1 << SIGILL) |
(1 << SIGTRAP)|
(1 << SIGINT) |
(1 << SIGBUS) |
(1 << SIGABRT);
;
if (MAX_SIGNALS > (sizeof(DWORD)*8)) {
fprintf(stderr, "_UnixException: MAX_SIGNALS to big.\n");
exit(1);
}
memset(oact, 0, sizeof(oact));
handlerInstalled = FALSE;
ExceptionInfo.ExceptionRecord =
(EXCEPTION_RECORD*)malloc(sizeof(EXCEPTION_RECORD));
ExceptionInfo.ContextRecord = 0;
// Create a ThreadInfo struct for the first thread.
ThreadInfo thisThreadInfo(THREAD_RUNNING);
// add it to the global Map of ThreadInfos with the handle as key.
ThreadInfos.insert(ThreadInfoMap::value_type((HANDLE)thr_self(), thisThreadInfo));
#ifdef __POSIX_THREADS__
struct sigaction act;
memset(&act,0,sizeof(act));
DBG("Installing Handler for SIGUNUSED");
act.sa_flags = SA_RESTART;
act.sa_handler = posixResumeHandler;
#ifdef linux
act.sa_restorer= NULL;
#endif
if (sigaction(SIGUNUSED, &act, 0)) {
perror("sigaction(): posixResumeHandler()");
}
#endif
DBG("Leaving ::_UnixException()");
}
_UnixException::~_UnixException() {
// The process is terminating.
if (handlerInstalled)
uninstallHandler();
free(ExceptionInfo.ExceptionRecord);
// we should clean up ThreadInfos and FileMappings ...
CleanUpMappings();
}
void _UnixException::installHandler() {
struct sigaction act;
DWORD i, bit;
DBG("Entering _UnixException::installHandler() ...");
// Install a global signal handler for all signals defined
// in globalSignalMask.
memset(&act,0,sizeof(act));
#ifdef linux
act.sa_flags = SA_RESTART;
act.sa_handler = globalSignalHandler;
act.sa_restorer= NULL;
#else
act.sa_flags = SA_RESTART | SA_SIGINFO;
act.sa_sigaction = globalSignalHandler;
#endif
for (i = 1; i < MAX_SIGNALS; i++) {
DBG("Trying bit i ==" << i << " globalSignalMask == "<<globalSignalMask);
bit = 1 << i;
if ((globalSignalMask & bit) == bit) {
DBG("::installHandler(): catching signal " << i);
if (sigaction(i, &act, &(oact[i]))) {
perror("sigaction()");
}
}
}
handlerInstalled = TRUE;
}
void _UnixException::uninstallHandler() {
DWORD i, bit;
for (i = 1; i < MAX_SIGNALS; i++) {
bit = 1 << i;
if ((globalSignalMask & bit) == bit) {
if (sigaction(i, &(oact[i]), 0)) {
perror("sigaction()");
}
}
}
handlerInstalled = FALSE;
}
#ifdef linux
inline void _UnixException::signalHandler(int sig,unsigned long * stack) {
#else
inline void _UnixException::signalHandler(int sig, siginfo_t *sip, void *uap) {
#endif
// The global signal handler method.
// It converts the UNIX-style siginfo_t and ucontext_t
// to a NT-Stye struct EXCEPTION_POINTERS. The result is stored
// in the ExceptionInfo instance variable.
LONG topFilterReturn = EXCEPTION_CONTINUE_SEARCH;
// default return value from the top level filter
switch (sig) {
case SIGSEGV:
// A segmentation violation.
ExceptionInfo.ExceptionRecord->ExceptionCode =
EXCEPTION_ACCESS_VIOLATION;
ExceptionInfo.ExceptionRecord->ExceptionInformation[0] =
#if defined(sparc)
(*(unsigned *)((ucontext_t*)uap)->uc_mcontext.gregs[REG_PC] & (1 << 21));
#elif defined(__X86)
(((ucontext_t*)uap)->uc_mcontext.gregs[ERR] & 2);
//for (DWORD i = 7; i < NGREG; i++)
//cerr << (DWORD)((ucontext_t*)uap)->uc_mcontext.gregs[i] << endl;
#elif defined(linux)
stack[14] & 2;
#endif
if (ExceptionInfo.ExceptionRecord->ExceptionInformation[0])
ExceptionInfo.ExceptionRecord->ExceptionInformation[0] = 1;
// 1 == write access
ExceptionInfo.ExceptionRecord->ExceptionInformation[1] =
#ifdef linux
stack[22];
#else
(DWORD)sip->si_addr;
#endif
topFilterReturn = topFilter(&ExceptionInfo);
break;
case SIGFPE:
// A floating-point exception.
fprintf(stderr, "SIGFPE ....\n");
ExceptionInfo.ExceptionRecord->ExceptionCode =
EXCEPTION_FLT_INVALID_OPERATION;
topFilterReturn = topFilter(&ExceptionInfo);
break;
case SIGILL:
// An illegal instruction.
ExceptionInfo.ExceptionRecord->ExceptionCode =
EXCEPTION_ILLEGAL_INSTRUCTION;
topFilterReturn = topFilter(&ExceptionInfo);
break;
case SIGBUS:
// A bus error.
ExceptionInfo.ExceptionRecord->ExceptionCode =
EXCEPTION_IN_PAGE_ERROR;
topFilterReturn = topFilter(&ExceptionInfo);
break;
case SIGTRAP:
// A trace trap.
ExceptionInfo.ExceptionRecord->ExceptionCode =
EXCEPTION_SINGLE_STEP;
topFilterReturn = topFilter(&ExceptionInfo);
break;
#ifdef __POSIX_THREADS__
case SIGUNUSED: topFilterReturn=EXCEPTION_CONTINUE_EXECUTION;
break;
#endif
default:
fprintf(stderr, "_UnixException::signalHandler(): unexpected signal: %d\n", sig);
break;
}
// We now have a valid topFilterReturn value (at least the default).
// If necessary, recall the old handler for the last signal:
if (topFilterReturn != EXCEPTION_CONTINUE_EXECUTION) {
fprintf(stderr, "_UnixException::signalHandler(): Unhandled signal %d. Trying old handler ...\n", sig);
CleanUpMappings();
#ifdef linux
if (oact[sig].sa_handler) {
oact[sig].sa_handler(sig);
#else
if (oact[sig].sa_sigaction) {
oact[sig].sa_sigaction(sig, sip, uap);
#endif
} else {
sigaction(sig, &(oact[sig]), 0);
kill(getpid(),sig);
}
}
return;
}
bool _UnixException::CleanUpMappings() { /*Si*/ /*bool added*/
vector<FileMapping>::iterator i;
i=FileMappings.begin();
while(i!=FileMappings.end()) {
if(i->type==SYSVSEGMENT) {
cerr<<"Removing SYSVSegment with id "<<i->hFileMappingObject<<endl;
shmctl((int)i->hFileMappingObject,IPC_RMID,0);
}
else close((int)i->hFileMappingObject);
i++;
}
}
// array of old signal handlers.
struct sigaction oact[MAX_SIGNALS];
EXCEPTION_POINTERS ExceptionInfo;
// for GetExceptionInformation().
BOOL handlerInstalled;
// is the handler for the signal(s) installed ?
DWORD globalSignalMask;
// When calling SetUnhandledExceptionFilter, a new signal handler
// for all signals i with ((1<<i) & globalSignalMask) == (1<<i) is
// installed.
// See /usr/include/sys/signal.h for the signal codes.
// For example, if you want to catch SIGSEGV's only, simply set
// globalSignalMask to (1 << SIGSEGV) above.
// See also MAX_SIGNALS above.
} UnixException;
#ifdef linux
inline void globalSignalHandler(int sig)
#else
inline void globalSignalHandler(int sig, siginfo_t *sip, void *uap)
#endif
{
// This function is installed as signal handler for all signals after
// the first call to SetUnhandledExceptionFilter() (see below) with a
// non-NULL argument.
if (topFilter)
#ifdef linux
UnixException.signalHandler(sig, (unsigned long *)&sig);
#else
UnixException.signalHandler(sig, sip, uap);
#endif
}
WINBASEAPI
LONG
WINAPI
UnhandledExceptionFilter(
struct _EXCEPTION_POINTERS *ExceptionInfo
)
{
return EXCEPTION_CONTINUE_SEARCH;
}
WINBASEAPI
LPTOP_LEVEL_EXCEPTION_FILTER
WINAPI
SetUnhandledExceptionFilter(
LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter
)
{
LPTOP_LEVEL_EXCEPTION_FILTER ret;
DBG("Entering SetUnhandledExceptionFilter() ...");
ret = topFilter;
// Set global filter:
topFilter = lpTopLevelExceptionFilter;
if (UnixException.handlerInstalled) {
// The handler is already installed. Is the new filter NULL ?
if (!topFilter)
// Yes -> deinstall handler.
UnixException.uninstallHandler();
// No -> ok.
} else {
// The handler is not (yet) installed. Is the new filter non-NULL ?
if (topFilter)
// Yes -> install the handler.
UnixException.installHandler();
// No -> ok.
}
return ret;
}
LPEXCEPTION_POINTERS GetExceptionInformation(VOID)
{
return &(UnixException.ExceptionInfo);
}
VOID QueryPerformanceCounter(LARGE_INTEGER *v)
{
timeval t;
gettimeofday(&t,0);
if (v)
v->QuadPart=(LONGLONG)t.tv_sec*1000000+(LONGLONG)t.tv_usec;
}
VOID QueryPerformanceFrequency(LARGE_INTEGER *f)
{
if (f)
f->QuadPart = 1000000;
}
#ifdef __cplusplus
}
#endif
| 25.655629 | 174 | 0.640811 | [
"object",
"vector"
] |
a17a00df5c999c28e65da37768da0f1d4cc93ae1 | 157 | hh | C++ | src/imu_offset_compensation-python.hh | nim65s/sot-torque-control | 0277baa065e6addf16df804676d47597cf1b4b06 | [
"BSD-2-Clause"
] | 6 | 2017-11-01T20:14:53.000Z | 2020-04-03T04:51:07.000Z | src/imu_offset_compensation-python.hh | nim65s/sot-torque-control | 0277baa065e6addf16df804676d47597cf1b4b06 | [
"BSD-2-Clause"
] | 52 | 2017-03-31T21:24:38.000Z | 2021-11-03T08:27:46.000Z | src/imu_offset_compensation-python.hh | nim65s/sot-torque-control | 0277baa065e6addf16df804676d47597cf1b4b06 | [
"BSD-2-Clause"
] | 14 | 2017-04-06T20:03:27.000Z | 2020-07-28T14:20:42.000Z | #include "sot/torque_control/imu_offset_compensation.hh"
typedef boost::mpl::vector< dynamicgraph::sot::torque_control::ImuOffsetCompensation > entities_t;
| 39.25 | 98 | 0.828025 | [
"vector"
] |
a18a40b24850ed614e3e8f1060076290797db891 | 2,452 | hpp | C++ | lib/cache/include/Response.hpp | astateful/dyplat | 37c37c7ee9f55cc2a3abaa0f8ebbde34588d2f44 | [
"BSD-3-Clause"
] | null | null | null | lib/cache/include/Response.hpp | astateful/dyplat | 37c37c7ee9f55cc2a3abaa0f8ebbde34588d2f44 | [
"BSD-3-Clause"
] | null | null | null | lib/cache/include/Response.hpp | astateful/dyplat | 37c37c7ee9f55cc2a3abaa0f8ebbde34588d2f44 | [
"BSD-3-Clause"
] | null | null | null | //! The MIT License (MIT)
//!
//! Copyright (c) 2014 Thomas Kovacs
//!
//! Permission is hereby granted, free of charge, to any person obtaining a
//! copy of this software and associated documentation files (the "Software"),
//! to deal in the Software without restriction, including without limitation
//! the rights to use, copy, modify, merge, publish, distribute, sublicense,
//! and / or sell copies of the Software, and to permit persons to whom the
//! Software is furnished to do so, subject to the following conditions :
//!
//! The above copyright notice and this permission notice shall be included in
//! all copies or substantial portions of the Software.
//!
//! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
//! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//! FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//! DEALINGS IN THE SOFTWARE.
#pragma once
#include "astateful/async/net/client/Response.hpp"
#include <string>
namespace astateful {
namespace cache {
//!
enum class result_e;
//!
struct Response : public async::net::client::Response {
protected:
//! Enumerate the various states the response can be in.
enum class state_e {
BODY,
END,
VALUE,
KEY,
FLAG,
CAS,
BYTES,
BYTES_STORED,
DATA
};
public:
//! Construct the response with the initial state used to parse the
//! response.
//!
//! @param state The initial state from which response parsing begins.
//!
Response( state_e state );
//! The default accept implementation will look for an \r\n to signal the
//! end of the raw response. The buffer could only be a portion of the\
//! actual request.
//!
//! @param data The data buffer containing the raw response.
//! @param length The length of the data buffer.
//! @return True if the response is finished, false otherwise.
//!
bool Accept( const char * data, int length ) override;
protected:
//! Store the current state of this response object.
state_e m_state;
//! A temporary buffer holding some data to be parsed.
std::string m_buffer = "";
};
}
} | 33.589041 | 78 | 0.687602 | [
"object"
] |
a18c0386597bc599f3cc5f691121e5619165fea0 | 632 | hpp | C++ | forms/creator.hpp | 5cript/minide | 0964ae51512eb7ba1ee44d828d27e5b73da32245 | [
"MIT"
] | null | null | null | forms/creator.hpp | 5cript/minide | 0964ae51512eb7ba1ee44d828d27e5b73da32245 | [
"MIT"
] | 1 | 2018-01-26T00:06:19.000Z | 2018-01-26T00:06:54.000Z | forms/creator.hpp | 5cript/minide | 0964ae51512eb7ba1ee44d828d27e5b73da32245 | [
"MIT"
] | null | null | null | #pragma once
#include "creator/createable.hpp"
#include <nana/gui/widgets/form.hpp>
#include <memory>
#include <vector>
#include <optional>
namespace MinIDE
{
struct CreatorImpl;
class Creator
{
public:
Creator(nana::window owner, std::unordered_map <std::string, std::vector <Creatable>> creatables);
Creator(nana::window owner, std::string const& creatableList);
~Creator();
std::optional <Creatable> show();
private:
void setupLayout();
void setupEvents();
private:
std::unique_ptr <CreatorImpl> impl_;
};
}
| 20.387097 | 107 | 0.607595 | [
"vector"
] |
a191039b6b875fe1e2b53f398773c30208363309 | 1,573 | cpp | C++ | languages/cxx/snip/pointer_this.cpp | amerlyq/aeternum-langs | 8424dd2ff1680cb82ea78a44a798a15fc87de103 | [
"MIT"
] | 4 | 2018-05-18T20:29:53.000Z | 2021-12-06T04:57:44.000Z | languages/cxx/snip/pointer_this.cpp | amerlyq/aeternum-langs | 8424dd2ff1680cb82ea78a44a798a15fc87de103 | [
"MIT"
] | null | null | null | languages/cxx/snip/pointer_this.cpp | amerlyq/aeternum-langs | 8424dd2ff1680cb82ea78a44a798a15fc87de103 | [
"MIT"
] | null | null | null | std::enable_shared_from_this
// Фича, которая позволяет возвращать shared_ptr на this, разделяя обязанности с уже имеющимися шарами,
// вместо создания ситуации, когда два разных шара отвечают за удаление одного объекта,
// не зная ничего друг о друге (и итого будет двойное удаление).
// A common implementation for enable_shared_from_this is to hold a weak
// reference (such as std::weak_ptr) to this. The constructors of
// std::shared_ptr can detect presence of a enable_shared_from_this base and
// share ownership with the existing std::shared_ptrs, instead of assuming the
// pointer is not managed by anyone else.
#include <memory>
#include <iostream>
struct Good: std::enable_shared_from_this<Good>
{
std::shared_ptr<Good> getptr() {
return shared_from_this();
}
};
struct Bad
{
std::shared_ptr<Bad> getptr() {
return std::shared_ptr<Bad>(this);
}
~Bad() { std::cout << "Bad::~Bad() called\n"; }
};
int main()
{
// Good: the two shared_ptr's share the same object
std::shared_ptr<Good> gp1(new Good);
std::shared_ptr<Good> gp2 = gp1->getptr();
std::cout << "gp2.use_count() = " << gp2.use_count() << '\n';
// Bad, each shared_ptr thinks it's the only owner of the object
std::shared_ptr<Bad> bp1(new Bad);
std::shared_ptr<Bad> bp2 = bp1->getptr();
std::cout << "bp2.use_count() = " << bp2.use_count() << '\n';
} // UB: double-delete of Bad
// Output:
gp2.use_count() = 2
bp2.use_count() = 1
Bad::~Bad() called
Bad::~Bad() called
*** glibc detected *** ./test: double free or corruption
| 30.843137 | 103 | 0.680865 | [
"object"
] |
0846e94d47b2fac7b4a909d217b457159657fa36 | 8,637 | cpp | C++ | dev/test/so_5/internal_stats/all_dispatchers/main.cpp | eao197/so-5-5 | fa0c31c84d2637dce04e13a155040150d505fbbd | [
"BSL-1.0"
] | 76 | 2016-03-25T15:22:03.000Z | 2022-02-03T15:11:43.000Z | test/so_5/internal_stats/all_dispatchers/main.cpp | sigman78/sobjectizer | d81c20a1264582e427a9a35d212361425fc34277 | [
"BSD-3-Clause"
] | 19 | 2017-03-09T19:21:53.000Z | 2021-02-24T13:02:18.000Z | test/so_5/internal_stats/all_dispatchers/main.cpp | sigman78/sobjectizer | d81c20a1264582e427a9a35d212361425fc34277 | [
"BSD-3-Clause"
] | 21 | 2016-09-23T10:01:09.000Z | 2020-08-31T12:01:10.000Z | /*
* Demo application to show run-time monitoring information
* from all types of standard dispatchers.
*/
#include <algorithm>
#include <iostream>
#include <map>
#include <exception>
#include <stdexcept>
#include <cstdlib>
#include <thread>
#include <chrono>
#include <random>
#include <so_5/all.hpp>
class a_worker_t : public so_5::agent_t
{
public :
static const std::size_t targets_count = 4;
struct hello : public so_5::signal_t {};
a_worker_t( context_t ctx )
: so_5::agent_t( ctx
+ limit_then_drop< hello >( targets_count ) )
{}
void
set_targets( const so_5::mbox_t targets[ targets_count ] )
{
std::copy( targets, targets + targets_count, m_targets );
}
virtual void
so_define_agent()
{
so_default_state().event< hello >( &a_worker_t::evt_hello );
}
private :
so_5::mbox_t m_targets[ targets_count ];
void
evt_hello()
{
using namespace std;
for_each( begin( m_targets ), end( m_targets ),
[]( const so_5::mbox_t & t ) {
so_5::send< hello >( t );
} );
}
};
class a_controller_t : public so_5::agent_t
{
public :
a_controller_t( context_t ctx )
: so_5::agent_t( ctx )
{}
virtual void
so_define_agent() override
{
so_subscribe( so_environment().stats_controller().mbox() )
.event( &a_controller_t::evt_monitor_quantity )
.event( &a_controller_t::evt_activity_tracking );
so_default_state().event< finish >(
[this] { so_deregister_agent_coop_normally(); } );
}
virtual void
so_evt_start() override
{
create_child_coops();
so_environment().stats_controller().set_distribution_period(
std::chrono::milliseconds(500) );
so_environment().stats_controller().turn_on();
so_5::send_delayed< finish >( *this,
std::chrono::seconds( 6 ) );
}
private :
struct finish : public so_5::signal_t {};
using workers_vector_t = std::vector< a_worker_t * >;
void
evt_monitor_quantity(
const so_5::stats::messages::quantity< std::size_t > & evt )
{
namespace stats = so_5::stats;
std::cout << evt.m_prefix.c_str()
<< evt.m_suffix.c_str()
<< ": " << evt.m_value << std::endl;
}
void
evt_activity_tracking(
const so_5::stats::messages::work_thread_activity & evt )
{
std::cout << evt.m_prefix << evt.m_suffix
<< " [" << evt.m_thread_id << "] ->\n "
<< evt.m_prefix << evt.m_suffix
<< evt.m_stats.m_working_stats
<< evt.m_stats.m_waiting_stats << std::endl;
}
void
create_child_coops()
{
auto coop = so_5::create_child_coop(
*this,
so_5::autoname );
workers_vector_t workers;
workers.reserve( 100 );
create_children_on_default_disp( *coop, workers );
create_children_on_one_thread_disp( *coop, workers );
create_children_on_active_obj_disp( *coop, workers );
create_children_on_active_group_disp( *coop, workers );
create_children_on_thread_pool_disp_1( *coop, workers );
create_children_on_thread_pool_disp_2( *coop, workers );
create_children_on_adv_thread_pool_disp_1( *coop, workers );
create_children_on_adv_thread_pool_disp_2( *coop, workers );
create_children_on_prio_ot_strictly_ordered_disp( *coop, workers );
create_children_on_prio_ot_quoted_round_robin_disp( *coop, workers );
create_children_on_prio_dt_one_per_prio_disp( *coop, workers );
connect_workers( workers );
so_environment().register_coop( std::move( coop ) );
send_initial_hello( workers );
}
void
create_children_on_default_disp(
so_5::coop_t & coop,
workers_vector_t & workers )
{
for( int i = 0; i != 5; ++i )
workers.push_back( coop.make_agent< a_worker_t >() );
}
void
create_children_on_one_thread_disp(
so_5::coop_t & coop,
workers_vector_t & workers )
{
auto disp = so_5::disp::one_thread::create_private_disp(
so_environment() );
create_children_on( coop, workers,
[disp] { return disp->binder(); } );
}
void
create_children_on_active_obj_disp(
so_5::coop_t & coop,
workers_vector_t & workers )
{
auto disp = so_5::disp::active_obj::create_private_disp(
so_environment() );
create_children_on( coop, workers,
[disp] { return disp->binder(); } );
}
void
create_children_on_active_group_disp(
so_5::coop_t & coop,
workers_vector_t & workers )
{
auto disp = so_5::disp::active_group::create_private_disp(
so_environment() );
unsigned int group_no = 0;
create_children_on( coop, workers,
[disp, &group_no] {
return disp->binder( "group#" +
std::to_string( ++group_no ) );
} );
}
void
create_children_on_thread_pool_disp_1(
so_5::coop_t & coop,
workers_vector_t & workers )
{
auto disp = so_5::disp::thread_pool::create_private_disp(
so_environment() );
create_children_on( coop, workers,
[disp] {
return disp->binder(
so_5::disp::thread_pool::bind_params_t{} );
} );
}
void
create_children_on_thread_pool_disp_2(
so_5::coop_t & coop,
workers_vector_t & workers )
{
using namespace so_5::disp::thread_pool;
auto disp = create_private_disp( so_environment() );
create_children_on( coop, workers,
[disp] {
return disp->binder(
bind_params_t{}.fifo( fifo_t::individual ) );
} );
}
void
create_children_on_adv_thread_pool_disp_1(
so_5::coop_t & coop,
workers_vector_t & workers )
{
using namespace so_5::disp::adv_thread_pool;
auto disp = create_private_disp( so_environment() );
create_children_on( coop, workers,
[disp] {
return disp->binder( bind_params_t{} );
} );
}
void
create_children_on_adv_thread_pool_disp_2(
so_5::coop_t & coop,
workers_vector_t & workers )
{
using namespace so_5::disp::adv_thread_pool;
auto disp = create_private_disp( so_environment() );
create_children_on( coop, workers,
[disp] {
return disp->binder(
bind_params_t{}.fifo( fifo_t::individual ) );
} );
}
void
create_children_on_prio_ot_strictly_ordered_disp(
so_5::coop_t & coop,
workers_vector_t & workers )
{
auto disp = so_5::disp::prio_one_thread::strictly_ordered::
create_private_disp( so_environment() );
create_children_on( coop, workers,
[disp] { return disp->binder(); } );
}
void
create_children_on_prio_ot_quoted_round_robin_disp(
so_5::coop_t & coop,
workers_vector_t & workers )
{
using namespace so_5::disp::prio_one_thread::quoted_round_robin;
auto disp = create_private_disp( so_environment(), quotes_t{ 20 } );
create_children_on( coop, workers,
[disp] { return disp->binder(); } );
}
void
create_children_on_prio_dt_one_per_prio_disp(
so_5::coop_t & coop,
workers_vector_t & workers )
{
using namespace so_5::disp::prio_dedicated_threads::one_per_prio;
auto disp = create_private_disp( so_environment() );
create_children_on( coop, workers,
[disp] { return disp->binder(); } );
}
template< typename LAMBDA >
void
create_children_on(
so_5::coop_t & coop,
workers_vector_t & workers,
LAMBDA binder )
{
for( int i = 0; i != 5; ++i )
workers.push_back(
coop.make_agent_with_binder< a_worker_t >( binder() ) );
}
void
connect_workers( const workers_vector_t & workers )
{
using namespace std;
for( auto w : workers )
{
so_5::mbox_t targets[ a_worker_t::targets_count ];
generate( begin( targets ), end( targets ),
[&workers] {
return workers[ random_index( workers.size() ) ]
->so_direct_mbox();
} );
w->set_targets( targets );
}
}
void
send_initial_hello( const workers_vector_t & workers )
{
so_5::send_to_agent< a_worker_t::hello >(
*( workers[ random_index( workers.size() ) ] ) );
}
static std::size_t
random_index( std::size_t max_size )
{
if( max_size > 0 )
{
std::random_device rd;
std::mt19937 gen{ rd() };
return std::uniform_int_distribution< std::size_t >{0, max_size-1}(gen);
}
else
return 0;
}
};
int
main()
{
try
{
so_5::launch( []( so_5::environment_t & env ) {
env.register_agent_as_coop( so_5::autoname,
env.make_agent< a_controller_t >() );
},
[]( so_5::environment_params_t & params ) {
params.turn_work_thread_activity_tracking_on();
} );
}
catch( const std::exception & ex )
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}
| 23.470109 | 77 | 0.648142 | [
"vector"
] |
08478ca3516fcea6c30c79930a53ab75115e42e0 | 8,986 | cc | C++ | backend/test/MongoTest.cc | EricJeffrey/TheCheatSheet | d3a9c91be10ad9179fdcbb25832d3235ea644115 | [
"MIT"
] | 2 | 2020-10-31T14:46:13.000Z | 2020-12-08T02:07:33.000Z | backend/test/MongoTest.cc | EricJeffrey/TheCheatSheet | d3a9c91be10ad9179fdcbb25832d3235ea644115 | [
"MIT"
] | 11 | 2020-10-20T08:14:04.000Z | 2020-11-17T01:52:29.000Z | backend/test/MongoTest.cc | EricJeffrey/TheCheatSheet | d3a9c91be10ad9179fdcbb25832d3235ea644115 | [
"MIT"
] | 1 | 2020-10-20T07:57:28.000Z | 2020-10-20T07:57:28.000Z | #include <gtest/gtest.h>
#include "../mongohelper/MongoHelper.hpp"
#include <bsoncxx/exception/exception.hpp>
#include <bsoncxx/json.hpp>
TEST(MongoTest, CRUDTest) {
/*
Execute before test start:
docker stop sjf_mongo_test && docker rm sjf_mongo_test
docker run -d --name sjf_mongo_test mongo:4.0 && docker inspect sjf_mongo_test |grep Addr
*/
using namespace mongohelper;
fprintf(stderr, "testing--mongoIndexInit\n");
EXPECT_TRUE(mongoIndexInit());
/* addUser */
fprintf(stderr, "testing--addUser\n");
vector<User> testUsers = {User("测试name", "sdfd@xcxxv.com", "passmMi密1"),
User("33试name", "slkjh@xcxxv.com", "?、密码?"),
User("2nam测e名", "sdfd@塑料.com", "1113323密码"),
User("--的name", "s是dfd#@¥.com", "——烧点饭密码")};
vector<string> testUserIds;
{
for (auto &&v : testUsers) {
auto addRes = addUser(v);
EXPECT_TRUE(addRes.has_value());
testUserIds.emplace_back(addRes.value());
}
EXPECT_FALSE(addUser(testUsers[0]).has_value());
}
/* addTag */
fprintf(stderr, "testing--addTag\n");
vector<Tag> testTags = {Tag("汉语"), Tag("mba"), Tag("windows"), Tag("Java"),
Tag("unix"), Tag("python"), Tag("linux"), Tag("测试zhong"),
Tag("rr"), Tag("algorithm")};
vector<string> testTagIds;
{
for (auto &&v : testTags) {
auto addRes = addTag(v.mValue);
EXPECT_TRUE(addRes.has_value());
testTagIds.emplace_back(addRes.value());
}
EXPECT_FALSE(addTag(testTags[0].mValue).has_value());
}
/* addCodeSegment */
fprintf(stderr, "testing--addCodeSegment\n");
vector<CodeSegment> testCodeSegments = {
CodeSegment{"te3stTi抬头tle",
"测试de5sc",
"内容测试2",
1617372607,
1617372607,
1,
{testTags[5].mValue, testTags[2].mValue, testTags[0].mValue}},
CodeSegment{"tes1tTi抬头tle",
"测试de4sc",
"内容测1试",
1617372607,
1617375233,
21,
{testTags[1].mValue, testTags[2].mValue, testTags[3].mValue}},
CodeSegment{"test2Ti抬头tle",
"测试de3sc",
"3内容测试",
1617372607,
1617378255,
23,
{testTags[8].mValue, testTags[4].mValue, testTags[5].mValue}},
CodeSegment{"testT4i抬头tle",
"测试de2sc",
"内44容测试",
1617372607,
1617372320,
40,
{testTags[9].mValue, testTags[6].mValue, testTags[8].mValue}},
CodeSegment{"testTi5抬头tle",
"测试desc1",
"内容5测试",
1617372607,
1617383550,
5,
{testTags[3].mValue, testTags[9].mValue, testTags[7].mValue}},
CodeSegment{"test中文title",
"test是描述",
"test好的content",
1617350753,
1617350753,
4,
{testTags[3].mValue, testTags[8].mValue, testTags[9].mValue}},
};
vector<string> testCodeSegmentIds;
{
for (auto &&v : testCodeSegments) {
auto addRes = addCodeSegment(v);
EXPECT_TRUE(addRes.has_value());
testCodeSegmentIds.emplace_back(addRes.value());
}
EXPECT_FALSE(addCodeSegment(testCodeSegments[0]).has_value());
}
/* getTags */
fprintf(stderr, "testing--getTags\n");
{
auto tags = getTags();
for (auto &&v : tags) {
auto index = std::find(testTagIds.begin(), testTagIds.end(), v.mId);
EXPECT_TRUE(index != testTagIds.end());
EXPECT_TRUE(v == testTags.at(index - testTagIds.begin()));
}
}
/* getCodeSegments */
{
int32_t page = 1;
int32_t pageSize = 3;
/* getCodeSegments-by favor number */
fprintf(stderr, "testing--getCodeSegments\n");
auto segmentsByFavorNumber = getCodeSegments(page, pageSize, SortOrder::favorNumber);
EXPECT_EQ(segmentsByFavorNumber.mData.size(), 3ul);
vector<int> expectIndexList = {3, 2, 1};
for (size_t i = 0; i < segmentsByFavorNumber.mData.size(); i++) {
EXPECT_EQ(segmentsByFavorNumber.mData[i], testCodeSegments[expectIndexList[i]]);
}
/* getCodeSegments-by lastModified and tag*/
fprintf(stderr, "testing--getCodeSegments\n");
auto segmentsByTagJava =
getCodeSegments(page, pageSize, SortOrder::lastModified, testTags[3].mValue);
EXPECT_EQ(segmentsByTagJava.mData.size(), 3ul);
expectIndexList = {4, 1, 5};
for (size_t i = 0; i < segmentsByTagJava.mData.size(); i++) {
EXPECT_EQ(segmentsByTagJava.mData[i], testCodeSegments[expectIndexList[i]]);
}
/* getCodeSegments-by lastModified and wrong tag */
fprintf(stderr, "testing--getCodeSegments\n");
vector<CodeSegment> segmentsByTagJAVA;
EXPECT_THROW(
segmentsByTagJAVA =
getCodeSegments(page, pageSize, SortOrder::lastModified, "ThisWillNotBeAnID").mData,
bsoncxx::exception);
}
/* removeTagOfCodeSegment */
// {
// fprintf(stderr, "removeTagOfCodeSegment\n");
// EXPECT_THROW(removeTagOfCodeSegment(testCodeSegmentIds[0], "ThisWillNotBeAnID"),
// bsoncxx::exception);
// EXPECT_TRUE(removeTagOfCodeSegment(testCodeSegmentIds[1], testTags[2].mValue));
// EXPECT_FALSE(removeTagOfCodeSegment(testCodeSegmentIds[2], testTags[0].mValue));
// EXPECT_EQ(findCodeSegmentByTitle(testCodeSegments[1].mTitle).value().mTagList.size(),
// 2u);
// }
/* findCodeSegmentByTitle */
fprintf(stderr, "testing--findCodeSegmentByTitle\n");
{
for (auto &&v : testCodeSegments) {
auto tmpRes = findCodeSegmentByTitle(v.mTitle);
EXPECT_TRUE(tmpRes.has_value());
EXPECT_TRUE(v == tmpRes.value());
}
EXPECT_FALSE(findCodeSegmentByTitle("xxxxxx").has_value());
}
/* countCodeSegment */
// fprintf(stderr, "testing--countCodeSegment\n");
// {
// EXPECT_EQ(countCodeSegment(), 6);
// EXPECT_EQ(countCodeSegment(testTags[3].mValue), 3);
// EXPECT_EQ(countCodeSegment(testTags[2].mValue), 2);
// EXPECT_NE(countCodeSegment(testTags[4].mValue), -222);
// }
/* updateCodeSegment */
fprintf(stderr, "testing--updateCodeSegment\n");
{
CodeSegment segment = testCodeSegments[0];
EXPECT_FALSE(updateCodeSegment(segment));
segment.setId("ThisWillNotBeAnID");
EXPECT_THROW(updateCodeSegment(segment), bsoncxx::exception);
segment.setId(testCodeSegmentIds[0]);
EXPECT_TRUE(updateCodeSegment(segment));
int64_t tmpLastModified = 3333333333;
segment.setLastModified(tmpLastModified);
EXPECT_TRUE(updateCodeSegment(segment));
auto findRes = findCodeSegmentByTitle(segment.mTitle);
EXPECT_TRUE(findRes.has_value());
EXPECT_EQ(findRes.value(), segment);
}
/* favor */
{
fprintf(stderr, "testing--favor\n");
EXPECT_THROW(favor("ThisWillNotBeAnID", testCodeSegmentIds[2]), bsoncxx::exception);
EXPECT_TRUE(favor(testUserIds[0], testCodeSegmentIds[1]));
EXPECT_FALSE(favor(testUserIds[0], testCodeSegmentIds[1]));
/* getUserFavors */
fprintf(stderr, "testing--getUserFavors\n");
auto userFavors = getUserFavors(testUserIds[0], 1, 3).mData;
EXPECT_EQ(userFavors.size(), 1u);
EXPECT_EQ(userFavors[0], testCodeSegments[1]);
EXPECT_EQ(getUserFavors(testUserIds[3], 2, 3).mData.size(), 0u);
EXPECT_THROW(getUserFavors("ThisWillNotBeAnIDToo", 1, 3).mData.size(), bsoncxx::exception);
/* getUserFavorsIds */
fprintf(stderr, "testing--getUserFavorsIds\n");
EXPECT_TRUE(favor(testUserIds[0], testCodeSegmentIds[0]));
auto userFavorsIds = getUserFavorsIds(testUserIds[0]);
EXPECT_EQ(userFavorsIds.size(), 2u);
EXPECT_EQ(getUserFavorsIds(testUserIds[1]).size(), 0u);
EXPECT_THROW(getUserFavorsIds("ThisWillNotBeAnIDToo").size(), bsoncxx::exception);
/* countUserFavors */
// fprintf(stderr, "testing--countUserFavors\n");
// EXPECT_EQ(countUserFavors(testUserIds[0]), 2);
// for (size_t i = 1; i < testUserIds.size(); i++) {
// EXPECT_EQ(countUserFavors(testUserIds[i]), 0);
// }
}
fprintf(stderr, "testing--done\n");
}
| 39.412281 | 100 | 0.570443 | [
"vector"
] |
084dd85ffa808ca791a453ea4f4845163e47dec3 | 8,824 | cpp | C++ | server/neuserver.cpp | Lahirutech/neutralinojs | 9a61a2f399ac9ddb5260578ffef4c60c337faf82 | [
"WTFPL"
] | null | null | null | server/neuserver.cpp | Lahirutech/neutralinojs | 9a61a2f399ac9ddb5260578ffef4c60c337faf82 | [
"WTFPL"
] | null | null | null | server/neuserver.cpp | Lahirutech/neutralinojs | 9a61a2f399ac9ddb5260578ffef4c60c337faf82 | [
"WTFPL"
] | null | null | null | #include <iostream>
#include <cstdlib>
#include <string>
#include <regex>
#include <map>
#include <thread>
#include <chrono>
#include <set>
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
#include "lib/json/json.hpp"
#include "settings.h"
#include "extensions_loader.h"
#include "server/neuserver.h"
#include "server/router.h"
#include "api/debug/debug.h"
#include "api/events/events.h"
#include "api/app/app.h"
using namespace std;
using json = nlohmann::json;
typedef websocketpp::server<websocketpp::config::asio> websocketserver;
typedef map<string, websocketpp::connection_hdl> wsclientsMap;
typedef set<websocketpp::connection_hdl, owner_less<websocketpp::connection_hdl>> wsclientsSet;
websocketserver *server;
wsclientsSet appConnections;
wsclientsMap extConnections;
namespace neuserver {
bool __isExtensionEndpoint(const string &url) {
return regex_match(url, regex(".*extensionId=.*"));
}
string __getExtensionIdFromUrl(const string &url) {
string id = "";
smatch matches;
if(regex_search(url, matches, regex("extensionId=([\\w.]+)"))) {
if(matches.size() >= 2) {
id = matches[1].str();
}
}
return id;
}
void __exitProcessIfIdle() {
thread exitCheckThread([=]() {
std::this_thread::sleep_for(10s);
if(appConnections.size() == 0) {
app::exit();
}
});
exitCheckThread.detach();
}
string init() {
int port = 0;
json jPort = settings::getOptionForCurrentMode("port");
if(!jPort.is_null()) {
port = jPort.get<int>();
}
server = new websocketserver();
server->set_message_handler([&](websocketpp::connection_hdl handler, websocketserver::message_ptr msg) {
neuserver::handleMessage(handler, msg);
});
server->set_http_handler([&](websocketpp::connection_hdl handler) {
neuserver::handleHTTP(handler);
});
server->set_open_handler([&](websocketpp::connection_hdl handler) {
neuserver::handleConnect(handler);
});
server->set_close_handler([&](websocketpp::connection_hdl handler) {
neuserver::handleDisconnect(handler);
});
server->set_validate_handler([&](websocketpp::connection_hdl handler) {
return neuserver::handleValidate(handler);
});
server->set_access_channels(websocketpp::log::alevel::none);
server->set_error_channels(websocketpp::log::elevel::none);
server->init_asio();
server->set_reuse_addr(true);
string hostAddress = "127.0.0.1";
if(settings::getMode() == "cloud") {
hostAddress = "0.0.0.0";
}
websocketpp::lib::asio::ip::tcp::endpoint
endpoint(websocketpp::lib::asio::ip::address::from_string(hostAddress), port);
server->listen(endpoint);
server->start_accept();
websocketpp::lib::asio::error_code error;
int actualPort = server->get_local_endpoint(error).port();
if(port != actualPort) {
port = actualPort;
settings::setPort(port);
}
string navigationUrl = "http://localhost:" + std::to_string(port);
json jUrl = settings::getOptionForCurrentMode("url");
if(!jUrl.is_null()) {
string url = jUrl.get<string>();
if (regex_match(url, regex("^/.*")))
navigationUrl += url;
else
navigationUrl = url;
}
return navigationUrl;
}
void startAsync() {
thread serverThread([&](){ server->run(); });
serverThread.detach();
}
void stop() {
server->stop_listening();
}
void handleMessage(websocketpp::connection_hdl handler, websocketserver::message_ptr msg) {
json nativeMessage;
try {
nativeMessage = json::parse(msg->get_payload());
router::NativeMessage nativeResponse = router::executeNativeMethod({
nativeMessage["id"].get<string>(),
nativeMessage["method"].get<string>(),
nativeMessage["accessToken"].get<string>(),
nativeMessage["data"]
});
try {
json nativeMessage;
nativeMessage["id"] = nativeResponse.id;
nativeMessage["method"] = nativeResponse.method;
nativeMessage["data"] = nativeResponse.data;
server->send(handler, nativeMessage.dump(), msg->get_opcode());
} catch (websocketpp::exception const & e) {
debug::log("ERROR",
"Unable to send native message: " + std::string(e.what()));
}
}
catch(exception e) {
debug::log("ERROR",
"Unable to parse native call payload: " + std::string(e.what()));
}
}
void handleHTTP(websocketpp::connection_hdl handler) {
websocketserver::connection_ptr con = server->get_con_from_hdl(handler);
string resource = con->get_resource();
json jDocumentRoot = settings::getOptionForCurrentMode("documentRoot");
if(!jDocumentRoot.is_null()) {
string documentRoot = jDocumentRoot.get<string>();
if(documentRoot.back() == '/') {
documentRoot.pop_back();
}
if(!documentRoot.empty()) {
resource = documentRoot + resource;
}
}
router::Response routerResponse = router::serve(resource);
con->set_status(routerResponse.status);
con->set_body(routerResponse.data);
con->replace_header("Content-Type", routerResponse.contentType);
}
void handleConnect(websocketpp::connection_hdl handler) {
websocketserver::connection_ptr con = server->get_con_from_hdl(handler);
string url = con->get_resource();
if(__isExtensionEndpoint(url)) {
string extensionId = __getExtensionIdFromUrl(url);
extConnections[extensionId] = handler;
events::dispatch("extClientConnect", extensionId);
}
else {
appConnections.insert(handler);
events::dispatch("appClientConnect", appConnections.size());
}
events::dispatch("clientConnect", appConnections.size() + extConnections.size());
}
void handleDisconnect(websocketpp::connection_hdl handler) {
websocketserver::connection_ptr con = server->get_con_from_hdl(handler);
string url = con->get_resource();
if(__isExtensionEndpoint(url)) {
string extensionId = __getExtensionIdFromUrl(url);
extConnections.erase(extensionId);
events::dispatch("extClientDisconnect", extensionId);
}
else {
appConnections.erase(handler);
if(settings::getMode() == "browser") {
__exitProcessIfIdle();
}
events::dispatch("appClientDisconnect", appConnections.size());
}
events::dispatch("clientDisconnect", appConnections.size() + extConnections.size());
}
bool handleValidate(websocketpp::connection_hdl handler) {
websocketserver::connection_ptr con = server->get_con_from_hdl(handler);
string url = con->get_resource();
if(__isExtensionEndpoint(url)) {
string extensionId = __getExtensionIdFromUrl(url);
return extensions::isLoaded(extensionId);
}
else {
return true;
}
}
void broadcast(const json &message) {
neuserver::broadcastToAllApps(message);
neuserver::broadcastToAllExtensions(message);
}
bool sendToExtension(const string &extensionId, const json &message) {
if(extConnections.find(extensionId) != extConnections.end()) {
server->send(extConnections[extensionId], message.dump(), websocketpp::frame::opcode::text);
return true;
}
return false;
}
void broadcastToAllExtensions(const json &message) {
for (const auto &[_, connection]: extConnections) {
server->send(connection, message.dump(), websocketpp::frame::opcode::text);
}
}
void broadcastToAllApps(const json &message) {
for (const auto &connection: appConnections) {
server->send(connection, message.dump(), websocketpp::frame::opcode::text);
}
}
vector<string> getConnectedExtensions() {
vector <string> extensions;
for (const auto &[extensionId, _]: extConnections) {
extensions.push_back(extensionId);
}
return extensions;
}
} // namespace neuserver
| 33.551331 | 112 | 0.600975 | [
"vector"
] |
084f328829c6b10bacd5f392bcd991181767e78c | 2,527 | hpp | C++ | rokko/eigenexa.hpp | t-sakashita/rokko | ebd49e1198c4ec9e7612ad4a9806d16a4ff0bdc9 | [
"BSL-1.0"
] | 16 | 2015-01-31T18:57:48.000Z | 2022-03-18T19:04:49.000Z | rokko/eigenexa.hpp | t-sakashita/rokko | ebd49e1198c4ec9e7612ad4a9806d16a4ff0bdc9 | [
"BSL-1.0"
] | 514 | 2015-02-05T14:56:54.000Z | 2021-06-25T09:29:52.000Z | rokko/eigenexa.hpp | t-sakashita/rokko | ebd49e1198c4ec9e7612ad4a9806d16a4ff0bdc9 | [
"BSL-1.0"
] | 2 | 2015-06-16T04:22:23.000Z | 2019-06-01T07:10:01.000Z | /*****************************************************************************
*
* Rokko: Integrated Interface for libraries of eigenvalue decomposition
*
* Copyright (C) 2017 by Rokko Developers https://github.com/t-sakashita/rokko
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*****************************************************************************/
#ifndef ROKKO_EIGENEXA_HPP
#define ROKKO_EIGENEXA_HPP
#include <rokko/config.h>
#include <rokko/ceigenexa.h>
namespace rokko {
namespace eigenexa {
inline void init() { ceigenexa_init(); }
inline void init(MPI_Comm comm) { ceigenexa_init1(comm); }
inline void init(MPI_Comm comm, char grid_major) { ceigenexa_init2(comm, grid_major); }
inline void free() { ceigenexa_free(); }
inline void free(int flag) { ceigenexa_free1(flag); }
template<typename GRID>
std::pair<int, int> get_matdims(const GRID& grid, int n) {
int nx, ny;
ceigenexa_get_matdims(grid.get_nprow(), grid.get_npcol(), n, &nx, &ny);
return std::make_pair(nx, ny);
}
template<typename MATRIX, typename VECTOR>
void eigen_s(MATRIX& a, VECTOR& w, MATRIX& z, int m_forward = 48, int m_backword = 128,
char mode = 'A') {
ceigenexa_eigen_s(a.get_m_global(), a.get_m_global(), a.get_array_pointer(), a.get_lld(),
storage(w), z.get_array_pointer(), z.get_lld(), m_forward, m_backword, mode);
}
template<typename MATRIX, typename VECTOR>
void eigen_s(MATRIX& a, VECTOR& w, int m_forward = 48, int m_backword = 128, char mode = 'N') {
ceigenexa_eigen_s(a.get_m_global(), a.get_m_global(), a.get_array_pointer(), a.get_lld(),
storage(w), 0, 0, m_forward, m_backword, mode);
}
template<typename MATRIX, typename VECTOR>
void eigen_sx(MATRIX& a, VECTOR& w, MATRIX& z, int m_forward = 48, int m_backword = 128,
char mode = 'A') {
ceigenexa_eigen_sx(a.get_m_global(), a.get_m_global(), a.get_array_pointer(), a.get_lld(),
storage(w), z.get_array_pointer(), z.get_lld(), m_forward, m_backword, mode);
}
template<typename MATRIX, typename VECTOR>
void eigen_sx(MATRIX& a, VECTOR& w, int m_forward = 48, int m_backword = 128, char mode = 'N') {
ceigenexa_eigen_sx(a.get_m_global(), a.get_m_global(), a.get_array_pointer(), a.get_lld(),
storage(w), 0, 0, m_forward, m_backword, mode);
}
} // end namespace eigenexa
} // end namespace rokko
#endif // ROKKO_EIGENEXA_HPP
| 38.876923 | 98 | 0.65097 | [
"vector"
] |
0862aac7997b273e4611cf9fabd4cc50c9ab1f5e | 3,022 | cpp | C++ | SimpleTests/MeshTests/MPI/NodePartitionedMeshTester.cpp | norihiro-w/ogs | ac990b1aa06a583dba3e32efa3009ef0c6f46ae4 | [
"BSD-4-Clause"
] | null | null | null | SimpleTests/MeshTests/MPI/NodePartitionedMeshTester.cpp | norihiro-w/ogs | ac990b1aa06a583dba3e32efa3009ef0c6f46ae4 | [
"BSD-4-Clause"
] | 25 | 2015-02-04T20:34:21.000Z | 2018-12-10T20:19:57.000Z | SimpleTests/MeshTests/MPI/NodePartitionedMeshTester.cpp | norihiro-w/ogs | ac990b1aa06a583dba3e32efa3009ef0c6f46ae4 | [
"BSD-4-Clause"
] | null | null | null | /*!
\file NodePartitionedMeshTester.cpp
\author Wenqing Wang
\date 2014.11
\brief Test class readNodePartitionedMesh to read node-wise partitioned mesh with MPI functions.
\copyright
Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
Distributed under a Modified BSD License.
See accompanying file LICENSE.txt or
http://www.opengeosys.org/project/license
*/
#include <iomanip>
#include <fstream>
#include <string>
#include <mpi.h>
#ifdef USE_PETSC
#include <petscksp.h>
#endif
#include "logog/include/logog.hpp"
#include "BaseLib/FileTools.h"
#include "BaseLib/LogogCustomCout.h"
#include "BaseLib/TemplateLogogFormatterSuppressedGCC.h"
#include "MeshLib/IO/MPI_IO/NodePartitionedMeshReader.h"
#include "MeshLib/Node.h"
#include "MeshLib/Elements/Element.h"
using namespace MeshLib;
int main(int argc, char *argv[])
{
LOGOG_INITIALIZE();
MPI_Init(&argc, &argv);
#ifdef USE_PETSC
char help[] = "ogs6 with PETSc \n";
PetscInitialize(&argc, &argv, nullptr, help);
#endif
BaseLib::LogogCustomCout* out = new BaseLib::LogogCustomCout(1);
using LogogFormatter = BaseLib::TemplateLogogFormatterSuppressedGCC
<TOPIC_LEVEL_FLAG | TOPIC_FILE_NAME_FLAG | TOPIC_LINE_NUMBER_FLAG>;
LogogFormatter* fmt = new LogogFormatter();
out->SetFormatter(*fmt);
const std::string file_name = argv[1];
std::string output_dir = "";
if (argc > 2)
output_dir = argv[2];
NodePartitionedMesh *mesh = nullptr;
{
MeshLib::IO::NodePartitionedMeshReader read_pmesh(MPI_COMM_WORLD);
mesh = read_pmesh.read(file_name);
}
if (!mesh)
{
ERR("Could not read mesh from files with prefix %s.", file_name.c_str());
return EXIT_FAILURE;
}
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
const std::string rank_str = std::to_string(rank);
const std::string ofile_name = file_name + "_partition_" + rank_str + ".msh";
std::ofstream os(BaseLib::joinPaths(output_dir, ofile_name), std::ios::trunc);
// Output nodes
os.setf(std::ios::scientific, std::ios::floatfield);
std::setprecision(10);
const std::size_t nn = mesh->getNumberOfNodes();
for(std::size_t i=0; i<nn; i++)
{
const double *x = mesh->getNode(i)->getCoords();
os << mesh->getNode(i)->getID() << " "
<< std::setw(14) << x[0] << " " << x[1] << " "<< x[2] << "\n";
}
os.flush();
// Output elements
const std::size_t ne = mesh->getNumberOfElements();
for(std::size_t i=0; i<ne; i++)
{
const Element *elem = mesh->getElement(i);
Node* const* ele_nodes = elem->getNodes();
for(unsigned j=0; j<elem->getNumberOfNodes(); j++)
{
os << ele_nodes[j]->getID() << " ";
}
os << "\n";
}
os.flush();
delete mesh;
delete out;
delete fmt;
#ifdef USE_PETSC
PetscFinalize();
#endif
MPI_Finalize();
LOGOG_SHUTDOWN();
}
| 25.82906 | 99 | 0.635672 | [
"mesh"
] |
08653b481906907ff1c785737b720f4a11656ab3 | 588 | cpp | C++ | Codes/success/Untitled Folder 2/album.cpp | hamedsteiner/Gerdabify_web | 78af9a38668b4026692fa6f44d459b253b305107 | [
"MIT"
] | null | null | null | Codes/success/Untitled Folder 2/album.cpp | hamedsteiner/Gerdabify_web | 78af9a38668b4026692fa6f44d459b253b305107 | [
"MIT"
] | null | null | null | Codes/success/Untitled Folder 2/album.cpp | hamedsteiner/Gerdabify_web | 78af9a38668b4026692fa6f44d459b253b305107 | [
"MIT"
] | null | null | null |
#include <cstdlib>
#include <vector>
#include <cmath>
#include <string>
#include <vector>
#include <cmath>
#include <sstream>
#include <iostream>
#include <algorithm>
#include "album.h"
#include "Artist.h"
using namespace std;
/*
Album::Album(Artist* creator,string _name)
{
author=creator;
name=_name;
}*/
void Album::set_name(string album_name)
{
name=album_name;
}
void Album::set_artist(Artist* artist)
{
author=artist;
}
string Album::get_name(){
return name;
}
void Album::validate()
{
validated=true;
}
vector<Music*> Album::get_musics()
{
return musics;
} | 12.510638 | 42 | 0.695578 | [
"vector"
] |
0867ce9ca4d48d26d695315e96a3275a3e0371e2 | 21,303 | cpp | C++ | src/pp.cpp | sunilnandihalli/pprestart | fc3cdea9d52ad16a0499301b5edb8b4e3f1213f7 | [
"MIT"
] | null | null | null | src/pp.cpp | sunilnandihalli/pprestart | fc3cdea9d52ad16a0499301b5edb8b4e3f1213f7 | [
"MIT"
] | null | null | null | src/pp.cpp | sunilnandihalli/pprestart | fc3cdea9d52ad16a0499301b5edb8b4e3f1213f7 | [
"MIT"
] | null | null | null | #include <cmath>
#include <functional>
#include <utility>
#include <vector>
#include <deque>
#include <map>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <chrono>
#include "spline.h"
#include "constants.h"
#include "jmt.h"
#include <string>
std::pair<double, double> toRefFrame(double x, double y, double theta,
double x0, double y0) {
double dx(x - x0);
double dy(y - y0);
double x1 = dx * cos(theta) + dy * sin(theta);
double y1 = -dx * sin(theta) + dy * cos(theta);
return std::make_pair(x1, y1);
}
std::pair<std::vector<double>, std::vector<double>> toRefFrame(
std::vector<double> xs, std::vector<double> ys, double theta, double x0,
double y0) {
std::vector<double> rx1s, ry1s;
for (int i = 0; i < xs.size(); i++) {
double x1, y1;
std::tie(x1, y1) = toRefFrame(xs[i], ys[i], theta, x0, y0);
rx1s.push_back(x1);
ry1s.push_back(y1);
}
return std::make_pair(rx1s, ry1s);
}
std::pair<double, double> fromRefFrame(double x1, double y1, double theta,
double x0, double y0) {
double dx = x1 * cos(theta) - y1 * sin(theta);
double dy = x1 * sin(theta) + y1 * cos(theta);
double x = dx + x0;
double y = dy + y0;
return std::make_pair(x, y);
}
std::pair<std::vector<double>, std::vector<double>> fromRefFrame(
std::vector<double> x1s, std::vector<double> y1s, double theta, double x0,
double y0) {
std::vector<double> rxs, rys;
for (int i = 0; i < x1s.size(); i++) {
double x, y;
std::tie(x, y) = fromRefFrame(x1s[i], y1s[i], theta, x0, y0);
rxs.push_back(x);
rys.push_back(y);
}
return std::make_pair(rxs, rys);
}
double length(tk::spline& s, double x0, double x1) {
const double tol = 0.1;
const double distPerTimeStep = 0.2;
std::function<double(double, double, double, double, double, double)> f =
[&s, &f, &distPerTimeStep](double x0, double y0, double x1, double y1,
double l, double tol) {
if (l < distPerTimeStep) return l;
double x = (x0 + x1) * 0.5;
double y = s(x);
double dx0(x - x0), dx1(x1 - x), dy0(y - y0), dy1(y1 - y);
double lf1 = sqrt(dx0 * dx0 + dy0 * dy0);
double lf2 = sqrt(dx1 * dx1 + dy1 * dy1);
double lf = lf1 + lf2;
if (fabs(l - lf) < tol)
return lf;
else
return f(x0, y0, x, y, lf1, tol * 0.5) +
f(x, y, x1, y1, lf2, tol * 0.5);
};
double y0(s(x0)), y1(s(x1));
double dx(x1 - x0), dy(y1 - y0);
double l = sqrt(dx * dx + dy * dy);
return f(x0, y0, x1, y1, l, tol);
}
double yaw(double x1, double y1, double x2, double y2) {
std::atan2(y2 - y1, x2 - x1);
}
std::tuple<std::vector<double>, std::vector<double>>
discretizeSpline(tk::spline& s, std::vector<double>& s_vals) {
std::vector<double> xs, ys;
double sp(0), x0(0), y0(s(x0));
for (int i = 0; i < s_vals.size(); i++) {
double ds = s_vals[i] - sp;
double x1p = x0 + ds;
double y1p = s(x1p);
double dx1p = x1p - x0;
double dy1p = y1p - y0;
double ds1p = sqrt(dx1p * dx1p + dy1p * dy1p);
double x1 = x0 + dx1p * ds / ds1p;
double y1 = s(x1);
xs.push_back(x1);
ys.push_back(y1);
sp = s_vals[i];
x0 = x1;
y0 = y1;
}
return std::make_tuple(xs, ys);
};
// assuming the car is oriented along the spline and wants to achieve a velocity
// of v1 and zero acceleration covering a distance of d in time t
// pts-x,pts-y,accs,vels
std::tuple<std::vector<double>,
std::vector<double>,
std::vector<double>,
std::vector<double>,
bool>
jerkFreePoints(
tk::spline& s, double a0, double v0, double v1, double d) {
bool goalAchieved;
std::vector<double> xs, ys;
double x0(0), y0(s(x0));
double s0 = 0;
std::vector<double> s_vals;
std::vector<double> v_vals, a_vals;
std::tie(s_vals, a_vals, v_vals, goalAchieved) = path(a0, v0, v1, d);
std::tie(xs, ys) = discretizeSpline(s, s_vals);
return std::make_tuple(xs, ys, a_vals, v_vals, goalAchieved);
}
// spline,refx,refy,theta,x of passed-in s_vals reference coordinates
std::tuple<tk::spline, double, double, double, double, std::vector<double>> getSpline(double x,
double y,
double px,
double py,
double yaw,
std::vector<double> sf,
std::vector<double> df,
std::function<
std::vector<
std::tuple<
double,
double>>(
std::vector<
double>,
std::vector<
double>)> xy) {
double theta; // transform angle
double r = 0.5;
auto pts = xy(sf, df);
std::vector<double> xs,
ys, x1s, y1s;
double refx,refy;
if(px!=sentinel && py!=sentinel) {
xs = {px,x};
ys = {py,y};
theta = atan2(y-py,x-px);
refx = px;
refy = py;
} else {
xs = {x, x + r * cos(yaw)};
ys = {y, y + r * sin(yaw)};
theta = yaw;
refx = x;
refy = y;
}
for(auto pt:pts) {
double x,y;
std::tie(x,y) = pt;
xs.push_back(x);
ys.push_back(y);
}
double startx;
std::tie(x1s, y1s) = toRefFrame(xs, ys, theta, refx, refy);
if(px!=sentinel && py!=sentinel) {
startx = x1s[1];
} else {
startx = x1s[0];
}
tk::spline spline;
spline.set_points(x1s, y1s);
return std::make_tuple(spline, refx, refy, theta, startx, std::vector<double>(x1s.begin()+2,x1s.end()));
}
struct car {
double s, d, v;
car(double _s, double _d, double _v) : s(_s), d(_d), v(_v) {}
};
// s , d , v
car transformCarData(const std::vector<double>& c/*carData*/, double delta_t) {
//id,x,y,vx,vy,s,d
double vx = c[3];
double vy = c[4];
double v = sqrt(vx * vx + vy * vy);
double s = c[5];
double d = c[6];
return car(s + v * delta_t, d, v);
};
//double s,double d,double sdot
std::vector<car>
transformCarsData(std::vector<std::vector<double>>& cars_data, double delta_t) {
std::vector<car> ret;
for (std::vector<double>& cdata:cars_data) {
ret.push_back(transformCarData(cdata, delta_t));
if (ret.back().d < 0 || ret.back().d > 12)
ret.pop_back();
}
return ret;
};
struct lane_car_data {
std::vector<int> lane_choices;
std::vector<car*> front;
std::vector<car*> back;
lane_car_data(std::vector<int> _lane_choices,
std::vector<car*> _front,
std::vector<car*> _back)
: lane_choices(_lane_choices), front(_front), back(_back) {}
};
double sdist(double from, double to) {
if (to >= from) {
double d1 = to - from;
double d2 = max_s - (to - from);
if (d1 < d2)
return d1;
else
return -d2;
} else
return -sdist(to, from);
}
int lane_id(double d) {
double lane_id;
modf(d / lane_width, &lane_id);
return int(lane_id);
};
lane_car_data possibleLanes(car ego, std::vector<car>& cardata) {
int ego_lane_id = lane_id(ego.d);
lane_car_data
lc({}, {nullptr, nullptr, nullptr}, {nullptr, nullptr, nullptr});
for (car& c:cardata) {
int lid = lane_id(c.d);
double ego_dist = sdist(ego.s, c.s);
if (ego_dist > 0 && (lc.front[lid] == nullptr
|| sdist(ego.s, lc.front[lid]->s) > ego_dist))
lc.front[lid] = &c;
if (ego_dist < 0
&& (lc.back[lid] == nullptr
|| sdist(ego.s, lc.back[lid]->s) < ego_dist))
lc.back[lid] = &c;
}
return lc;
}
struct lane_change_path {
std::vector<double> x;
std::vector<double> y;
std::vector<double> a;
std::vector<double> v;
double sf;
int lane_id;
};
lane_change_path get_path_h(int elid/*ego_lane_id*/,
lane_car_data& lc,
double a0,
double v0,
double x0,
double y0,
double px,
double py,
double yaw0,
double s0,
double d0,
double lane_yaw,
std::function<std::vector<std::tuple<double, double>>(
std::vector<double>,
std::vector<double>)> xy) {
car *ef(lc.front[elid]);
lane_change_path ret;
double lctime = 3.0;
double target_v, target_s;
bool goalAchieved;
// (spline,refx,refy,theta,jfn,total_time,total_distance,final_velocity,lane_change_time,target_lane_id,start_spline_x)
typedef std::tuple<tk::spline,double,double,double,std::function<double(double)>,double,double,double,double,int,double> option_type;
option_type best_option;
{
// vector of tuple of option_type
std::vector<option_type> options;
std::map<int,std::string> rejection_reason;
double max_time = 0;
for(int tlid : {elid-1,elid,elid+1}) {
if(tlid<0||tlid>2)
continue;
if(v0<5.0 && tlid!=elid) { // caution when removing this condition.
rejection_reason[tlid]="too slow to change lane";
continue;
}
double target_d = (tlid + 0.5) * lane_width;
car* b(lc.back[tlid]), * f(lc.front[tlid]);
std::vector<double> spline_s_vals;
std::vector<double> spline_d_vals;
int lane_change_marker = std::numeric_limits<int>::max();
{
double vspln = std::max(v0,10.0);
if(elid==tlid) {
//spline_s_vals.push_back(s0+vspln*0.25*lctime);
//spline_d_vals.push_back(target_d);
spline_s_vals.push_back(s0+vspln*0.5*lctime);
spline_d_vals.push_back(target_d);
spline_s_vals.push_back(s0+vspln*0.75*lctime);
spline_d_vals.push_back(target_d);
}
lane_change_marker = spline_s_vals.size();;
spline_s_vals.push_back(s0+vspln*lctime);
spline_d_vals.push_back(target_d);
spline_s_vals.push_back(s0+vspln*1.25*lctime);
spline_d_vals.push_back(target_d);
spline_s_vals.push_back(s0+vspln*1.5*lctime);
spline_d_vals.push_back(target_d);
}
tk::spline spln;
double refx,refy,theta,start_spline_x;
std::vector<double> spline_xs;
std::tie(spln,refx,refy,theta,start_spline_x,spline_xs) = getSpline(x0,y0,px,py,yaw0,spline_s_vals,spline_d_vals,xy);
std::vector<double> s_vals,a_vals,v_vals;
std::function<double(double)> jfn;
double total_time,total_dist,final_v,lane_change_time(0.0);
if(tlid!=elid) {
double lane_change_dist = length(spln,start_spline_x,spline_xs[lane_change_marker]);
double changed_lane_time;
double changed_lane_dist;
std::function<double(double)> jfn1,jfn2;
bool goalAchieved;
double target_v;
std::tie(jfn1,lane_change_time,goalAchieved) = achieveTargetVelocityAndDistanceInShortestTime
(a0,v0,v0,std::max(0.0,v0+a0*fabs(a0/(2*jmax))-0.1),std::min(max_speed,v0+a0*fabs(a0/(2*jmax))+0.1),lane_change_dist);
double lane_changed_s = spline_s_vals[lane_change_marker];
// should not collide with the vehicle in the back in the next lane
if(b==nullptr || sdist(b->s,lane_changed_s)>safe_dist+(lane_change_time*b->v)) {
if(f==nullptr || (sdist(lane_changed_s,f->s)>safe_dist+lane_change_time*f->v+150.0)) {
target_v = max_speed;
std::tie(changed_lane_dist,jfn2,changed_lane_time) = distDuringVelocityChange(0,v0,target_v);
} else if (sdist(s0,f->s)>safe_dist) {
double delta_d = sdist(lane_changed_s,f->s+lane_change_time*f->v)-safe_dist;
target_v = f->v;
std::tie(jfn2,changed_lane_time,goalAchieved) = achieveTargetVelocityAndDistanceInShortestTime
(0,v0-target_v,0,-target_v,max_speed-target_v,delta_d);
changed_lane_dist = delta_d+target_v*changed_lane_time;
} else {
rejection_reason[tlid] = "car in the front is too close";
continue;
}
} else {
rejection_reason[tlid]="car behind may hit you";
continue;
}
total_time = lane_change_time+changed_lane_time;
total_dist = sdist(s0,lane_changed_s)+changed_lane_dist;
jfn = [jfn1,jfn2,lane_change_time,total_time](double t) {
if(t<lane_change_time) return jfn1(t);
else if (t<total_time) return jfn2(t-lane_change_time);
else return 0.0;
};
final_v = target_v;
} else {
if(f) {
double delta_d = sdist(s0,f->s)-safe_dist;
bool goalAchieved;
std::tie(jfn,total_time,goalAchieved) = achieveTargetVelocityAndDistanceInShortestTime(a0,v0-f->v,0,-f->v,max_speed-f->v,delta_d);
final_v = f->v;
total_dist = delta_d+total_time*f->v;
} else {
std::tie(total_dist,jfn,total_time) = distDuringVelocityChange(a0,v0,max_speed);
final_v = max_speed;
}
}
if(total_time>max_time)
max_time = total_time;
options.push_back(std::make_tuple(spln,refx,refy,theta,jfn,total_time,total_dist,final_v,lane_change_time,tlid,start_spline_x));
}
double max_dist_at_max_time=0;
for(option_type& option:options) {
double t,d,v;
std::tie(std::ignore,std::ignore,std::ignore,std::ignore,std::ignore,t,d,v,std::ignore,std::ignore,std::ignore) = option;
double dist_at_max_time = d+(v*(max_time-t))+(std::get<9>(option)==elid?2*max_time:0.0);
if(dist_at_max_time>max_dist_at_max_time) {
max_dist_at_max_time = dist_at_max_time;
best_option = option;
}
}
{
std::cout<<"num options : "<<options.size()<<std::endl;
std::map<int,option_type*> option_map;
for(option_type& x:options) {
option_map[std::get<9>(x)] = &x;
}
for(int i=0;i<3;i++) {
auto f(lc.front[i]),b(lc.back[i]);
std::cout<<" "<<i;
std::cout<<" b : ";
if(b) {
std::cout<<"("<<std::setw(4)<<int(sdist(s0,b->s))<<","<<std::setw(4)<<int(b->v)<<") ";
} else {
std::cout<<"( , ) ";
}
std::cout<<" f : ";
if(f) {
std::cout<<"("<<std::setw(4)<<int(sdist(s0,f->s))<<","<<std::setw(4)<<int(f->v)<<") ";
} else {
std::cout<<"( , ) ";
}
std::cout<<(option_map[i]?"yes":" no")<<" "<<rejection_reason[i]<<" ";
if(elid==i)
std::cout<<"ego";
std::cout<<std::endl;
}
std::cout<<std::flush;
}
{
tk::spline s;
std::function<double(double)> jfn;
double total_time,total_distance,lane_change_time;
double refx,refy,theta,start_spline_x;
std::tie(s,refx,refy,theta,jfn,total_time,total_distance,std::ignore,lane_change_time,ret.lane_id,start_spline_x) = best_option;
std::vector<double> s_vals;
std::tie(s_vals,ret.a,ret.v) = genCompletePath(jfn,a0,v0,start_spline_x,std::max(lane_change_time,1.1));
std::vector<double> x1s,y1s;
std::tie(x1s,y1s) = discretizeSpline(s,s_vals);
std::tie(ret.x,ret.y) = fromRefFrame(x1s,y1s,theta,refx,refy);
}
}
return ret;
}
lane_change_path get_path(int elid/*ego_lane_id*/,
lane_car_data& lc,
double a0,
double v0,
double x0,
double y0,
double px,
double py,
double yaw0,
double s0,
double d0,
double lane_yaw,
std::function<std::vector<std::tuple<double, double>>(
std::vector<double>,
std::vector<double>)> xy) {
static int call_id = 0;
static bool first = true;
static char fname[100];
if(first) {
std::sprintf(fname,"get_path_calls_and_responses_%d.csv",std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count() );
first = false;
}
static std::ofstream fout(fname);
lane_change_path lcp = get_path_h(elid,lc,a0,v0,x0,y0,px,py,yaw0,s0,d0,lane_yaw,xy);
return lcp;
}
void update(double& s,double v) {
if(s!=sentinel) {
s+=v*dt;
}
}
std::pair<std::vector<double>, std::vector<double>> path_plan(double car_x,
double car_y,
double car_s,
double car_d,
double car_yaw,
double car_speed,
double lane_yaw,
std::vector<double>& prev_x,
std::vector<double>& prev_y,
double end_path_s,
double end_path_d,
std::vector<std::vector<
double>> cars_data,
std::function<std::vector<
std::tuple<
double,
double>>(
std::vector<
double>,
std::vector<
double>)> xy,
std::function<std::vector<
double>(double,
double,
double)> sd) {
static int call_id(0);
static int point_id(0);
static double ego_v, ego_a;
static bool first_call(true);
static int target_lane_id;
static std::ofstream fout("rundata.csv");
const char* header = "id,callid,end_path_s,end_path_d,x,y,v,a,np,f0s,f0v,b0s,b0v,f1s,f1v,b1s,b1v,f2s,f2v,b2s,b2v,target_lane_id";
call_id++;
std::vector<double> xs, ys;
unsigned long np = prev_x.size();
assert(prev_x.size() == prev_y.size());
double ego_x(np ? prev_x.back() : car_x), ego_y(np ? prev_y.back() : car_y);
double ego_px(np>1?prev_x[np-2]:sentinel),ego_py(np>1?prev_y[np-2]:sentinel);
double ego_s(np ? end_path_s : car_s), ego_d(np ? end_path_d : car_d);
double ego_yaw(np > 1 ? yaw(prev_x[np - 2],
prev_y[np - 2],
prev_x[np - 1],
prev_y[np - 1]) : car_yaw);
int ego_lane_id = lane_id(ego_d);
std::cout<<"ego_v : "<<ego_v<<" ego_a : "<<ego_a<<std::endl;
if (first_call) {
ego_v = car_speed;
ego_a = 0.0;
target_lane_id = ego_lane_id;
fout<<header<<std::endl;
}
xs = prev_x;
ys = prev_y;
if(np<50) {
std::vector<car> transformedCarsData =
transformCarsData(cars_data, np * dt);
lane_car_data
lcdata = possibleLanes(car(ego_s, ego_d, ego_v), transformedCarsData);
lane_change_path change_path;
change_path = get_path(ego_lane_id,
lcdata,
ego_a,
ego_v,
ego_x,
ego_y,
ego_px,
ego_py,
ego_yaw,
ego_s,
ego_d,
lane_yaw,
xy);
auto f0(lcdata.front[0]),f1(lcdata.front[1]),f2(lcdata.front[2]);
auto b0(lcdata.back[0]),b1(lcdata.back[1]),b2(lcdata.back[2]);
double f0s(f0?f0->s:sentinel),f0v(f0?f0->v:sentinel),b0s(b0?b0->s:sentinel),b0v(b0?b0->v:sentinel),
f1s(f1?f1->s:sentinel),f1v(f1?f1->v:sentinel),b1s(b1?b1->s:sentinel),b1v(b1?b1->v:sentinel),
f2s(f2?f2->s:sentinel),f2v(f2?f2->v:sentinel),b2s(b2?b2->s:sentinel),b2v(b2?b2->v:sentinel);
for (int i = 0;i<change_path.x.size(); i++) {
xs.push_back(change_path.x[i]);
ys.push_back(change_path.y[i]);
ego_a = change_path.a[i];
ego_v = change_path.v[i];
point_id++;
fout<<point_id<<","<<call_id<<","<<end_path_s<<","<<end_path_d<<","<<xs.back()<<","<<ys.back()<<","<<ego_v<<","<<ego_a<<","<<np;
update(f0s,f0v);
update(b0s,b0v);
update(f1s,f1v);
update(b1s,b1v);
update(f2s,f2v);
update(b2s,b2v);
for(double x : {f0s,f0v,b0s,b0v,f1s,f1v,b1s,b1v,f2s,f2v,b2s,b2v}) {
fout<<",";
if(x!=sentinel)
fout<<x;
}
fout <<","<<change_path.lane_id<<std::endl;
}
fout<<std::flush;
}
if(fabs(ego_a)>amax*1.05 || fabs(ego_v)>max_speed*1.05) {
std::cout<<"error : ego_a : "<<ego_a<<" ego_v : "<<ego_v<<std::endl<<" num_points : "<<xs.size()<<" prev_size : "<<np<<std::endl ;
}
first_call = false;
return std::make_pair(xs, ys);
}
| 36.353242 | 173 | 0.53861 | [
"vector",
"transform"
] |
086e7c0fbd5c50db0404af4b7618985c5d652be8 | 2,222 | cpp | C++ | test/cppsim/test_noisesimulator.cpp | kamakiri01/qulacs | 1e3e6ac26390abdfe5abe7f4d52349bcfd68e20c | [
"MIT"
] | 260 | 2018-10-13T15:58:26.000Z | 2022-03-17T11:03:58.000Z | test/cppsim/test_noisesimulator.cpp | kamakiri01/qulacs | 1e3e6ac26390abdfe5abe7f4d52349bcfd68e20c | [
"MIT"
] | 182 | 2018-10-14T02:29:27.000Z | 2022-03-06T20:23:18.000Z | test/cppsim/test_noisesimulator.cpp | kamakiri01/qulacs | 1e3e6ac26390abdfe5abe7f4d52349bcfd68e20c | [
"MIT"
] | 88 | 2018-10-10T03:46:29.000Z | 2022-02-27T21:56:05.000Z | #include <gtest/gtest.h>
#include "../util/util.h"
#include <cppsim/state.hpp>
#include <cppsim/gate_factory.hpp>
#include <cppsim/gate_merge.hpp>
#include <cppsim/circuit.hpp>
#include <cppsim/noisesimulator.hpp>
TEST(NoiseSimulatorTest, Random_with_State_Test) {
int n = 10,depth = 10;
QuantumState state(n);
state.set_Haar_random_state();
QuantumCircuit circuit(n);
Random random;
for (UINT d = 0; d < depth; ++d) {
for (UINT i = 0; i < n; ++i) {
UINT r = (UINT)(random.int32()) % 5;
if (r == 0) circuit.add_sqrtX_gate(i);
else if (r == 1) circuit.add_sqrtY_gate(i);
else if (r == 2) circuit.add_T_gate(i);
else if (r == 3) {
if (i + 1 < n) circuit.add_CNOT_gate(i, i + 1);
}
else if (r == 4) {
if (i + 1 < n) circuit.add_CZ_gate(i, i + 1);
}
}
}
NoiseSimulator hoge(&circuit,0.02,&state);
std::vector<unsigned int> result = hoge.execute(100);
return;
}
TEST(NoiseSimulatorTest, Random_without_State_Test) {
int n = 10,depth = 10;
QuantumCircuit circuit(n);
Random random;
for (UINT d = 0; d < depth; ++d) {
for (UINT i = 0; i < n; ++i) {
UINT r = (UINT)(random.int32()) % 5;
if (r == 0) circuit.add_sqrtX_gate(i);
else if (r == 1) circuit.add_sqrtY_gate(i);
else if (r == 2) circuit.add_T_gate(i);
else if (r == 3) {
if (i + 1 < n) circuit.add_CNOT_gate(i, i + 1);
}
else if (r == 4) {
if (i + 1 < n) circuit.add_CZ_gate(i, i + 1);
}
}
}
NoiseSimulator hoge(&circuit,0.02);
std::vector<unsigned int> result = hoge.execute(100);
return;
}
TEST(NoiseSimulatorTest, H_gate_twice_test) {
int n = 4;
QuantumCircuit circuit(n);
circuit.add_H_gate(0);
circuit.add_H_gate(0);
NoiseSimulator hoge(&circuit,0.02);
std::vector<unsigned int> result = hoge.execute(10000);
int cnts[2] = {};
for(int i = 0;i < result.size();++i){
cnts[result[i]]++;
}
ASSERT_NE(cnts[0],0);
ASSERT_NE(cnts[1],0);
ASSERT_GT(cnts[0],cnts[1]);
} | 30.861111 | 63 | 0.542754 | [
"vector"
] |
087878952fa18be008ea11a41c916c5326cc8768 | 12,906 | cc | C++ | dylocxx/src/hwinfo.cc | fuchsto/dyloc | 87a5a203406d09b0fb446a4bb3237ce34100651a | [
"BSD-3-Clause"
] | 4 | 2017-05-16T11:50:05.000Z | 2020-08-12T16:47:28.000Z | dylocxx/src/hwinfo.cc | jakubo87/dyloc | a10c7da2c0e49597aad62ddda95b6ca8840d4ea9 | [
"BSD-3-Clause"
] | null | null | null | dylocxx/src/hwinfo.cc | jakubo87/dyloc | a10c7da2c0e49597aad62ddda95b6ca8840d4ea9 | [
"BSD-3-Clause"
] | 3 | 2017-04-27T02:01:44.000Z | 2018-11-27T11:21:57.000Z |
#include <dyloc/common/config.h>
#ifdef DYLOC__PLATFORM__LINUX
/* _GNU_SOURCE required for sched_getcpu() */
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif
# include <sched.h>
#endif
#include <dylocxx/hwinfo.h>
#include <dylocxx/exception.h>
#include <dyloc/common/types.h>
#include <dyloc/common/internal/hwloc.h>
#include <dyloc/common/internal/papi.h>
#include <dylocxx/internal/logging.h>
#ifdef DYLOC_ENABLE_LIKWID
# include <likwid.h>
#endif
#ifdef DYLOC_ENABLE_HWLOC
# include <hwloc.h>
# include <hwloc/helper.h>
#endif
#ifdef DYLOC_ENABLE_PAPI
# include <papi.h>
#endif
#ifdef DYLOC_ENABLE_NUMA
# include <utmpx.h>
# include <numa.h>
#endif
#include <iostream>
#include <sstream>
namespace dyloc {
std::ostream & operator<<(
std::ostream & os,
const dyloc_locality_scope_t & scope) {
std::ostringstream ss;
switch (scope) {
case DYLOC_LOCALITY_SCOPE_GLOBAL: ss << "GLOBAL"; break;
case DYLOC_LOCALITY_SCOPE_GROUP: ss << "GROUP"; break;
case DYLOC_LOCALITY_SCOPE_UNIT: ss << "UNIT"; break;
case DYLOC_LOCALITY_SCOPE_MODULE: ss << "MODULE"; break;
case DYLOC_LOCALITY_SCOPE_NETWORK: ss << "NETWORK"; break;
case DYLOC_LOCALITY_SCOPE_NODE: ss << "NODE"; break;
case DYLOC_LOCALITY_SCOPE_PACKAGE: ss << "PACKAGE"; break;
case DYLOC_LOCALITY_SCOPE_NUMA: ss << "NUMA"; break;
case DYLOC_LOCALITY_SCOPE_UNCORE: ss << "UNCORE"; break;
case DYLOC_LOCALITY_SCOPE_CORE: ss << "CORE"; break;
case DYLOC_LOCALITY_SCOPE_CPU: ss << "CPU"; break;
case DYLOC_LOCALITY_SCOPE_CACHE: ss << "CACHE"; break;
default: ss << "UNDEFINED"; break;
}
return operator<<(os, ss.str());
}
std::ostream & operator<<(
std::ostream & os,
const dyloc_locality_scope_pos_t & scope) {
std::ostringstream ss;
ss << scope.scope << ":" << scope.index;
return operator<<(os, ss.str());
}
std::ostream & operator<<(
std::ostream & os,
const dyloc_hwinfo_t & hwinfo) {
std::ostringstream ss;
ss << "dyloc_hwinfo_t { "
<< "host:" << hwinfo.host << " "
<< "cpu:" << hwinfo.cpu_id << " "
<< "core:" << hwinfo.core_id << " "
<< "numa:" << hwinfo.numa_id << " "
<< "scope:" << "( ";
for (int s = 0; s < hwinfo.num_scopes; ++s) {
ss << hwinfo.scopes[s] << " ";
}
ss << ") }";
return operator<<(os, ss.str());
}
hwinfo::hwinfo() {
_hw.num_numa = -1;
_hw.numa_id = -1;
_hw.num_cores = -1;
_hw.core_id = -1;
_hw.cpu_id = -1;
_hw.min_cpu_mhz = -1;
_hw.max_cpu_mhz = -1;
_hw.min_threads = -1;
_hw.max_threads = -1;
_hw.cache_ids[0] = -1;
_hw.cache_ids[1] = -1;
_hw.cache_ids[2] = -1;
_hw.cache_sizes[0] = -1;
_hw.cache_sizes[1] = -1;
_hw.cache_sizes[2] = -1;
_hw.cache_line_sizes[0] = -1;
_hw.cache_line_sizes[1] = -1;
_hw.cache_line_sizes[2] = -1;
_hw.max_shmem_mbps = -1;
_hw.system_memory_bytes = -1;
_hw.numa_memory_bytes = -1;
_hw.num_scopes = -1;
dyloc_locality_scope_pos_t undef_scope;
undef_scope.scope = DYLOC_LOCALITY_SCOPE_UNDEFINED;
undef_scope.index = -1;
for (int s = 0; s < DYLOC_LOCALITY_MAX_DOMAIN_SCOPES; s++) {
_hw.scopes[s] = undef_scope;
}
}
void hwinfo::collect() {
DYLOC_LOG_TRACE("dylocxx::hwinfo.collect", "()");
gethostname(_hw.host, DYLOC_LOCALITY_HOST_MAX_SIZE);
DYLOC_LOG_TRACE("dylocxx::hwinfo.collect", "hostname:", _hw.host);
#ifdef DYLOC_ENABLE_HWLOC
DYLOC_LOG_TRACE("dylocxx::hwinfo.collect", "using hwloc");
hwloc_topology_t topology;
hwloc_topology_init(&topology);
hwloc_topology_set_flags(topology,
#if HWLOC_API_VERSION < 0x00020000
HWLOC_TOPOLOGY_FLAG_IO_DEVICES
| HWLOC_TOPOLOGY_FLAG_IO_BRIDGES
/* | HWLOC_TOPOLOGY_FLAG_WHOLE_IO */
#else
HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM
#endif
);
hwloc_topology_load(topology);
/* hwloc can resolve the physical index (os_index) of the active unit,
* not the logical index.
* Queries in the topology hierarchy require the logical index, however.
* As a workaround, units scan the topology for the logical index of the
* CPU object that has a matching physical index.
*/
/* Get PU of active thread: */
hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
int flags = 0; // HWLOC_CPUBIND_PROCESS;
int cpu_os_id = -1;
int ret = hwloc_get_last_cpu_location(topology, cpuset, flags);
if (!ret) {
cpu_os_id = hwloc_bitmap_first(cpuset);
}
hwloc_bitmap_free(cpuset);
hwloc_obj_t cpu_obj;
for (cpu_obj =
hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0);
cpu_obj;
cpu_obj = cpu_obj->next_cousin) {
if ((int)cpu_obj->os_index == cpu_os_id) {
_hw.cpu_id = cpu_obj->logical_index;
break;
}
}
DYLOC_LOG_TRACE("dylocxx::hwinfo.collect", "hwloc: CPU id",
"physical:", cpu_os_id,
"logical:", _hw.cpu_id);
/* PU (cpu_id) to CORE (core_id) object: */
hwloc_obj_t core_obj;
for (core_obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, _hw.cpu_id);
core_obj;
core_obj = core_obj->parent) {
if (core_obj->type == HWLOC_OBJ_CORE) { break; }
}
if (core_obj) {
_hw.core_id = core_obj->logical_index;
DYLOC_LOG_TRACE("dylocxx::hwinfo.collect",
"hwloc: core logical index:", _hw.core_id);
_hw.num_scopes = 0;
int cache_level = 0;
/* Use CORE object to resolve caches: */
hwloc_obj_t obj;
for (obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, _hw.core_id);
obj;
obj = obj->parent) {
if (obj->type == HWLOC_OBJ_MACHINE) { break; }
_hw.scopes[_hw.num_scopes].scope =
dyloc__hwloc_obj_type_to_scope(obj->type);
_hw.scopes[_hw.num_scopes].index = obj->logical_index;
DYLOC_LOG_TRACE("dylocxx::hwinfo.collect",
"hwloc: parent[", _hw.num_scopes, "](",
"scope:", _hw.scopes[_hw.num_scopes].scope,
"index:", _hw.scopes[_hw.num_scopes].index,
")");
_hw.num_scopes++;
#if HWLOC_API_VERSION < 0x00020000
if (obj->type == HWLOC_OBJ_CACHE) {
_hw.cache_sizes[cache_level] = obj->attr->cache.size;
_hw.cache_line_sizes[cache_level] = obj->attr->cache.linesize;
_hw.cache_ids[cache_level] = obj->logical_index;
cache_level++;
}
#else
if (obj->type == HWLOC_OBJ_L1CACHE) {
_hw.cache_sizes[0] = obj->attr->cache.size;
_hw.cache_line_sizes[0] = obj->attr->cache.linesize;
_hw.cache_ids[0] = obj->logical_index;
cache_level++;
}
else if (obj->type == HWLOC_OBJ_L2CACHE) {
_hw.cache_sizes[1] = obj->attr->cache.size;
_hw.cache_line_sizes[1] = obj->attr->cache.linesize;
_hw.cache_ids[1] = obj->logical_index;
cache_level++;
}
else if (obj->type == HWLOC_OBJ_L3CACHE) {
_hw.cache_sizes[2] = obj->attr->cache.size;
_hw.cache_line_sizes[2] = obj->attr->cache.linesize;
_hw.cache_ids[2] = obj->logical_index;
cache_level++;
}
#endif
else if (obj->type == HWLOC_OBJ_NODE) {
_hw.numa_id = obj->logical_index;
} else if (obj->type ==
#if HWLOC_API_VERSION > 0x00011000
HWLOC_OBJ_PACKAGE
#else
HWLOC_OBJ_SOCKET
#endif
) {
}
}
}
if (_hw.numa_id < 0) {
hwloc_obj_t numa_obj;
for (numa_obj =
hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, _hw.cpu_id);
numa_obj;
numa_obj = numa_obj->parent) {
if (numa_obj->type == HWLOC_OBJ_NODE) {
_hw.numa_id = numa_obj->logical_index;
break;
}
}
}
if (_hw.num_numa < 0) {
int n_numa_nodes = hwloc_get_nbobjs_by_type(
topology, DYLOC__HWLOC_OBJ_NUMANODE);
if (n_numa_nodes > 0) {
_hw.num_numa = n_numa_nodes;
}
}
if (_hw.num_cores < 0) {
int n_cores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
if (n_cores > 0) {
_hw.num_cores = n_cores;
}
}
if (_hw.min_threads < 0 && _hw.max_threads < 0 &&
_hw.num_cores > 0 && _hw.max_threads < 0) {
int n_cpus = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_PU);
_hw.min_threads = 1;
_hw.max_threads = n_cpus / _hw.num_cores;
}
if (_hw.system_memory_bytes < 0) {
hwloc_obj_t obj;
obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_MACHINE, 0);
_hw.system_memory_bytes = obj->memory.total_memory / MBYTES;
}
if (_hw.numa_memory_bytes < 0) {
hwloc_obj_t obj;
obj = hwloc_get_obj_by_type(topology, DYLOC__HWLOC_OBJ_NUMANODE, 0);
if(obj != NULL) {
_hw.numa_memory_bytes = obj->memory.total_memory / MBYTES;
} else {
/* No NUMA domain: */
_hw.numa_memory_bytes = _hw.system_memory_bytes;
}
}
hwloc_topology_destroy(topology);
DYLOC_LOG_TRACE("dylocxx::hwinfo.collect", "hwloc:",
"num_numa:", _hw.num_numa,
"numa_id:", _hw.numa_id,
"num_cores:", _hw.num_cores,
"min.threads:", _hw.min_threads,
"max.threads:", _hw.max_threads,
"core_id:", _hw.core_id,
"cpu_id:", _hw.cpu_id);
#endif /* DYLOC_ENABLE_HWLOC */
#ifdef DYLOC_ENABLE_PAPI
DYLOC_LOG_TRACE("dylocxx::hwinfo: using PAPI");
const PAPI_hw_info_t * papi_hwinfo = NULL;
if (dyloc__papi_init(&papi_hwinfo) == DYLOC_OK) {
if (_hw.num_numa < 0) {
_hw.num_numa = papi_hwinfo->nnodes;
}
if (_hw.num_cores < 0) {
int num_sockets = papi_hwinfo->sockets;
int cores_per_socket = papi_hwinfo->cores;
_hw.num_cores = num_sockets * cores_per_socket;
}
if (_hw.min_cpu_mhz < 0 || _hw.max_cpu_mhz < 0) {
_hw.min_cpu_mhz = papi_hwinfo->cpu_min_mhz;
_hw.max_cpu_mhz = papi_hwinfo->cpu_max_mhz;
}
DYLOC_LOG_TRACE("dylocxx::hwinfo.collect", "PAPI:",
"num_numa:", _hw.num_numa,
"num_cores:", _hw.num_cores);
}
#endif /* DYLOC_ENABLE_PAPI */
#ifdef DYLOC__PLATFORM__LINUX
if (_hw.cpu_id < 0) {
_hw.cpu_id = sched_getcpu();
}
#else
DYLOC_THROW(
dyloc::exception::runtime_config_error,
"dylocxx::hwinfo: hwloc or PAPI required if not running on Linux");
#endif
#ifdef DYLOC__ARCH__IS_MIC
/*
* Hardware information for Intel MIC can be hard-coded as hardware
* specs of MIC model variants are invariant:
*/
DYLOC_LOG_TRACE("dylocxx::hwinfo: MIC architecture");
if (_hw.num_numa < 0) { _hw.num_numa = 1; }
if (_hw.num_cores < 0) { _hw.num_cores = 60; }
if (_hw.min_cpu_mhz < 0 || _hw.max_cpu_mhz < 0) {
_hw.min_cpu_mhz = 1100;
_hw.max_cpu_mhz = 1100;
}
if (_hw.min_threads < 0 || _hw.max_threads < 0) {
_hw.min_threads = 4;
_hw.max_threads = 4;
}
if (_hw.numa_id < 0) {
_hw.numa_id = 0;
}
#endif
#ifdef DYLOC__PLATFORM__POSIX
if (_hw.num_cores < 0) {
/*
* NOTE: includes hyperthreading
*/
int posix_ret = sysconf(_SC_NPROCESSORS_ONLN);
_hw.num_cores = (posix_ret > 0) ? posix_ret : _hw.num_cores;
DYLOC_LOG_TRACE(
"dylocxx::hwinfo.collect", "POSIX: _hw.num_cores:", _hw.num_cores);
}
if (_hw.system_memory_bytes < 0) {
long pages = sysconf(_SC_AVPHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
if (pages > 0 && page_size > 0) {
_hw.system_memory_bytes = (int) ((pages * page_size) / MBYTES);
}
}
#endif
#ifdef DYLOC_ENABLE_NUMA
DYLOC_LOG_TRACE("dylocxx::hwinfo: using numalib");
if (_hw.num_numa < 0) {
_hw.num_numa = numa_max_node() + 1;
}
if (_hw.numa_id < 0 && _hw.cpu_id >= 0) {
_hw.numa_id = numa_node_of_cpu(_hw.cpu_id);
}
#endif
if (_hw.num_scopes < 1) {
/* No domain hierarchy could be resolved.
* Use flat topology, with all units assigned to domains in CORE scope: */
_hw.num_scopes = 1;
_hw.scopes[0].scope = DYLOC_LOCALITY_SCOPE_CORE;
_hw.scopes[0].index = (_hw.core_id >= 0) ? _hw.core_id : _hw.cpu_id;
}
DYLOC_LOG_DEBUG("dylocxx::hwinfo.collect", "finished:",
"hostname:", _hw.host,
"num_numa:", _hw.num_numa,
"numa_id:", _hw.numa_id,
"cpu_id:", _hw.cpu_id,
"num_cores:", _hw.num_cores,
"min_threads:", _hw.min_threads,
"max_threads:", _hw.max_threads);
DYLOC_LOG_TRACE("dylocxx::hwinfo.collect", ">");
}
} // namespace dyloc
| 31.024038 | 78 | 0.605842 | [
"object",
"model"
] |
087c20341401431b5a8ce5145d139fec5ae774eb | 115,946 | cpp | C++ | Source/HeliumRain/UI/Menus/FlareHelpMenu.cpp | SirWanabe/HeliumRain | 7614c09f068dcaa065a642083c7dc78e8f3b1c97 | [
"BSD-3-Clause"
] | 6 | 2020-03-29T00:55:50.000Z | 2021-07-05T06:49:10.000Z | Source/HeliumRain/UI/Menus/FlareHelpMenu.cpp | SirWanabe/HeliumRain | 7614c09f068dcaa065a642083c7dc78e8f3b1c97 | [
"BSD-3-Clause"
] | null | null | null | Source/HeliumRain/UI/Menus/FlareHelpMenu.cpp | SirWanabe/HeliumRain | 7614c09f068dcaa065a642083c7dc78e8f3b1c97 | [
"BSD-3-Clause"
] | null | null | null |
#include "FlareHelpMenu.h"
#include "../../Flare.h"
#include "../Components/FlareButton.h"
#include "../Components/FlareTabView.h"
#include "../../Player/FlareMenuPawn.h"
#include "../../Player/FlareMenuManager.h"
#include "../../Game/FlareGame.h"
//#include "../../Player/FlarePlayerController.h"
#include "../Components/FlareTechnologyInfo.h"
#include "../../Data/FlareTechnologyCatalog.h"
#include "../../Data/FlareSpacecraftComponentsCatalog.h"
#include "../../Data/FlareCompanyCatalog.h"
#include "../../Data/FlareCustomizationCatalog.h"
#include "../Components/FlarePartInfo.h"
#include "../Components/FlareCompanyHelpInfo.h"
#include "../Components/FlareSpacecraftOrderOverlayInfo.h"
#define LOCTEXT_NAMESPACE "FlareHelpMenu"
/*----------------------------------------------------
Construct
----------------------------------------------------*/
void SFlareHelpMenu::Construct(const FArguments& InArgs)
{
// Data
MenuManager = InArgs._MenuManager;
const FFlareStyleCatalog& Theme = FFlareStyleSet::GetDefaultTheme();
// AFlarePlayerController* PC = MenuManager->GetPC();
Game = MenuManager->GetGame();
double TextWrappingBig = 1.75 * Theme.ContentWidth;
// Build structure
ChildSlot
.HAlign(HAlign_Fill)
.VAlign(VAlign_Fill)
.Padding(FMargin(0, AFlareMenuManager::GetMainOverlayHeight(), 0, 0))
[
SNew(SFlareTabView)
+ SFlareTabView::Slot()
.Header(LOCTEXT("GameplayTab", "Gameplay Information"))
.HeaderHelp(LOCTEXT("GameplayInfo", "View general gameplay information within Helium Rain"))
[
SNew(SFlareTabView)
+ SFlareTabView::Slot()
.Header(LOCTEXT("OverviewTab", "Overview"))
.HeaderHelp(LOCTEXT("Overviewinfo", "View overview of Helium Rain"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("OverviewTitle", "Helium Rain"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("OverviewMain", "\
Inside the giant planets, deep under the surface, helium from the atmosphere can condense due to the pression: there is an helium rain over the metallic ocean. As our Giant planet Nema is the hearth of the world, the game is named after this phenomenon.\n\n\
Helium Rain is a realistic space simulation game."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("OverviewTopTitle", "\nA space sim that doesn't cheat"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("OverviewTopMain", "\
The massive gas giant Nema is your new home. Surrounded by rings of metal and rock, the planet is a near-infinite source of fuel. Helium Rain gives you an empire to build and defend against your competitors. It's up to you to decide if you will trade resources, avoid trouble, or start wars.\n\n\
\u2022Fly any ship of your fleet, including fighters, freighters or capital ships.\n\
\u2022Build stations, colonize asteroids, explore new areas.\n\
\u2022Customize your ship, change your equipment, buy new gear.\n\
\u2022Do as you please, whether you want to become a wealthy merchant or a fierce pilot.\n\n\
Helium Rain is a game where everything is tied together. Ships and stations are built with resources that need to be mined, transported and traded. The steel you sell to a company will become a ship or a gun. The cargo you're blowing up will create a shortage. The blockade you're imposing will raise the prices. Helium Rain simulates a complex economy where all actions have consequences."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("OverviewSpaceshipsTitle", "\nSpaceships"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("OverviewSpaceshipsMain", "\
All ships have generators, radiators, weapons, engines, cargo bays or life support systems - they all work together. Every thruster on your ship plays a role. Aim for engines to pin down your enemies, or send them spinning around by destroying power stations. Most of the ships have more than thirty individual parts to target. You can customize the most important components - your main engines, attitude control thrusters and weapons. You can choose your colors, emblem, and of course, you can fly every ship in the game.\n\n\
The physics of the game are highly detailed. Power-hungry components will glow red hot when cooling fails, ships and stations can be pushed or thrown out of place, and gun shells have complex trajectories."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("OverviewComputerSpecsTitle", "\nAbout your computer"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("OverviewComputerSpecsMain", "\
Helium Rain is built for high-end Windows and Linux computers. We recommend the following:\n\n\
\u2022A high-end video card such as the nVidia GTX970 or the AMD R290;\n\
\u2022A quad - core processor;\n\
\u20228GB of RAM;\n\
\u2022A modern 64 - bits operating system(Windows 7 or Ubuntu 14.04).\n\n\
Helium Rain does not support Mac OS X or other platforms."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("OverviewOpenDevelopmentTitle", "\nOpen-source development"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("OverviewOpenDevelopmentMain", "The game's full source code is available on Github under the MIT license, found at https://github.com/arbonagw/HeliumRain. Feel free to read the code to look for interesting stuff for your own game."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("OverviewAboutTeamTitle", "\nAbout the team"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("OverviewAboutTeamMain", "\
Helium Rain was made by:\n\n\
\u2022Gwennaël ARBONA 'Stranger' - Art, UI & Game design\n\
\u2022Frédéric BERTOLUS 'Niavok' - Gameplay & Game design\n\
\u2022Daisy HERBAUT - Music\n\n\
We'd also like to thank Jérôme MILLION-ROUSSEAU for the game logo.\n\
Some of us are employed by another company on top of their work in this project. This game is our own personal work and is not supported by any of our employers in any way."))
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("HowtoplayTab", "How To Play"))
.HeaderHelp(LOCTEXT("Howtoplaynfo", "View basic information about playing Helium Rain"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HowToPlayMainTitle", "How To Play Helium Rain"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HowToPlayTopMain", "\
This is a basic guide on how to How To Play Helium Rain.\n\n\
In Helium Rain you play a new company in a small colony living around a giant planet Nema.\n\n\
Your goal is to extend your company and make it an empire. For this, you will need to use a smart combination of commercial and military options. You can achieve the goal you gave yourself(be the richest, the most powerful... or the only one) just by fighting, or without ever fighting, but in some cases both will be required.\n\n\
In any case you will need to make money. The simplest method to make money is trading."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HowToPlayShipsTitle", "\nShips"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HowToPlayShipsMain", "\
\u2022You begin with one ship and you can buy or build other ships during the game.\n\
\u2022You can manage ships with fleets, with as many fleets as you want, and as many ships per fleet (it's possible to mix military and trading ships)\n\
\u2022There is a special fleet, the personal fleet: it contains the ship you control. It's possible to switch the control to other ships in your personal fleet at any time.\n\
\u2022It's possible to give orders to other fleets, to travel or to trade, but they will manage their battles alone.\n\
\u2022Military ships left in a sector will defend that sector against every threat.\n\
\u2022You can automate remote fleets with a powerful trade route system. This trade route system is flexible and can be used to organize patrols."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HowToPlayStationsTitle", "\nStations"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HowToPlayStationsMain", "\
The most lucrative and safe way to make money is to build stations. Stations are very expensive but can ensure continued and secure revenues. Be careful, your neighbors can be friendly as long as you are small and peaceful, but being more aggressive or ambitious can lead to your fall.\n\n\
\u2022Stations and ships are built from resources.Resources are gathered from mines or pumps or produced in other stations from primary resources.\n\
\u2022In the early game, other already existing companies will own stations to allow the economy to work.\n\
\u2022During the game, you will build or capture stations / mines / pumps to produce and sell resources and ships yourself.\n\
\u2022In end game, you can become partially or totally autonomous for resources and ships production."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HowToPlayPiracyTitle", "\nPiracy"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HowToPlayPiracyMain", "You can also try piracy, but a good ending is not a guarantee."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HowToPlayDiplomacyTitle", "\nDiplomacy"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HowToPlayDiplomacyMain", "\
If your dare it, war can be a very good way to make good deals. The Helium Rain economy is responsive to your action, so destroying a competitor can make you the sole provider of a resource.\n\
To wage war, you can build various military ships to destroy enemy stations or ships."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HowToPlayPurchasingspaceshipsTitle", "\nPurchasing spaceships"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HowToPlayPurchasingspaceshipsMain", "\
Spaceships can be found at the shipyard, a huge station encountered in some busy sectors. Players must be at peace with the shipyard's owner to do any purchases. To do the purchase, one must go to the \"Details\" menu and click one of the buttons to order either small or large ships. Once the production price has been paid, the player must wait for their construction to end. The progress can be seen through the same menu.\n\
If there is currently a ship of the same production line in production, one must wait for that task to end before their ship's production begins.\n\
There are two other reasons a ship production might not start:\n\n\
\u2022If the company owning the shipyard has not enough money (this happens only to ships it builds for itself, not ships ordered by a third party)\n\
\u2022If the shipyard doesn't have the resources needed to build the ship in its cargo bay (one can help it to get them by selling missing resources to the station)\n\n\
Building ships becomes more straightforward once the player aquires their own shipyard."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HowToPlayPiratesHarassTitle", "\nPirates harass me, what can I do?"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HowToPlayPiratesHarassMain", "\
\u2022Increase your military power: they won't attack you if you are stronger than them\n\
\u2022Increase your military power : you will win battles if you are stronger than them\n\
\u2022Pay tribute : you can always pay Pirates for peace"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HowToPlayMoveRemoteShipTitle", "\nHow can I move a remote ship without trade route?"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HowToPlayMoveRemoteShipMain", "First your ship must be ready to travel: not stranded or uncontrollable, not trading, not intercepted Then to the sector menu of your destination sector. Next to the Travel button, you have a drop down to select your remote fleet (you can split the fleet if your want to move only one ship). Then click on the travel button."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HowToPlayRedIconsTitle", "\nWhat are the meaning of the 3 red icons over ships?"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HowToPlayRedIconsMain", "\
The icons indicate the status of the 3 main system on a ship: \n\n\
\u2022The red big engine indicate the orbital engine are too damaged to travel, the ship is stranded\n\
\u2022The red small engine indicate the RCS system is broken, the ship is uncontrollable\n\
\u2022The red bullet indicate the ship's weapon system is broken or out of ammo: the ship is out of combat"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HowToPlayShipDamagedTitle", "\nMy ship are damaged, what can I do?"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HowToPlayShipDamagedMain", "\
Open the sector menu of the sector were your damaged ships are. You will find a repair button on the top right part of the menu. To repair: \n\n\
\u2022Make sure your are not in battle\n\
\u2022It must be fleet supply in the sector. If not:\n\n\
1. wait of another company to bring fleet supply\n\
2. buy fleet supply in another sector and bring it where your damaged ship is\n\n\
\u2022If you don't own the fleet supply, be sure:\n\n\
1. to have enough money to buy it\n\
2. that you are not at war with the owner"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HowToPlayFindOrderedShipTitle", "\nI ordered a ship but I can't find it"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HowToPlayFindOrderedShipMain", "\
It may be long to build a ship. You can follow the construction progress in the right part of the orbital map.\n\
Some events may delay the completion:\n\n\
\u2022The shipyard have to finish the construction of the previous ship in the production line\n\
\u2022The shipyard can be in outage of a resource.In this case, you can bring the missing resource or wait someone else do that\n\n\
If you don't see build ship status in orbital map, it can mean: \n\n\
\u2022Your ship is ready : look at the sector menu of the shipyard, or in your company menu (there should of been a notification)\n\
\u2022Your have been at war the owner of the shipyard, your order is lost\n\
\u2022The shipyard has been captured by a company in war with you, your order is lost\n\
\u2022Your ship has been destroyed(there should of been a notification)"))
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("TradingTab", "Trading"))
.HeaderHelp(LOCTEXT("TradingInfo", "View information about trading"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("TradingTopMainTitle", "Trading"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("TradingTopMain", "Trading in Helium Rain allows companies to exchange resources between each other in a living world. Resources are produced and consumed by stations and can be transported with cargos."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("ManualTradingTitle", "\nManual trading"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("ManualTradingMain", "\
Manual trading goes as follows:\n\n\
\u2022Travel to a sector\n\
\u2022Dock with a station using a cargo\n\
\u2022Buy resources (or load them if the station is owned)\n\
\u2022Optionally travel to another sector\n\
\u2022Dock with another station with the cargo\n\
\u2022Sell resources (or unload, if the station is owned)\n\n\
Note that in most cases, a station will only sell resources it produces and buy resources it consumes. One exception to this is the Supply outpost that buys and sells fleet supply. When selling supply, the outpost will apply a significant margin to any ship or station that used it to refill or repair.\n\
Distant fleets do not need to dock with stations, but each trade (each single exchange) will take them a full day to complete."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("TradeRoutesTitle", "\nTrade routes"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("TradeRoutesMain", "\
One may automatize this process using trade routes.\n\n\
1.Trade routes are created by clicking the \"Add new trade route\" button on the right side of the Orbital Menu.\n\n\
2.Once in the trade route creation menu, one may first draw a list of up to 4 sectors by selecting them in the drop-down menu in the center of the screen and clicking on \"Add (X / 4)\", to the right of the drop-down menu (where X is the current number of sectors in the trade route).\n\n\
3.Once all desired sectors have been selected this way, a small diagram appears underneath, showing each sector in order, with arrows depicting which direction the trade route will take. Sectors can be rearranged using the \"Move\" buttons under each sector's column.\n\n\
4.Each column includes a list of Operations to be performed in that sector. Initially, only one default operation is listed per sector. Operations are added by clicking the \" * Add\" button. Each operation can be modified by clicking the \"Edit\" button; the operation's edition tab is then shown on the left side of the screen, where the type of operation, the resource involved, and the cargos' behavior can all be set. Typically the first operation of the first sector is to Buy (first drop-down menu) a Resource A (second drop-down menu). A limit in max quantity and time can both be set as well, by clicking the corresponding buttons and setting the slider that appears under each of them upon clicking. The max quantity limit will prevent cargos from loading more than a specified amount of resources. The time limit will force the cargos to start the next operation after a specified amount of days, even if they didn't fill their cargo bays.\n\n\
5.If one sector has more than one operation, they can be ordered using the \"Move up\" and \"Move down\" buttons in each operation's setting panel. Their current order is shown in the sector's column in the form of a numbered list; that order is essential, as each operation will be performed one after the other.\n\n\
6.\"Load\" and \"Unload\" stand for operations made with one's own stations. One may set a trade route that will buy Fuel somewhere and unload it in a sector where they have an Iron Mine; and then a second trade route that will load the Iron Mine's production, and sell it to a foreign Steelworks Station. The \"Load/Buy\" operation stands for \"Load every resources available in owned stations, and if there's still room in the cargo, buy that resource to a foreign station, if there is one selling it\". Same reasoning applies for \"Unload/Sell\".\n\n\
7.Once an operation is set, clicking the \"Done\" button brings up options to rename the trade route, assign a fleet to it, skip the current operation manually, pause it, and reset its stats. Stats are shown there as well once a fleet has been assigned to this route. They only become informative after several cycles.\n\n\
Assigned fleets may include military vessels for defense."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("TradeGoodDealsTitle", "\nFinding good deals"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("TradeGoodDealsMain", "\
There are several ways to find worthwhile deals or trade routes.\n\n\
\u2022Clicking on a station (from your current sector, or from a sector previously selected through the Orbital Map) shows their current stocks, and what resources they buy/sell (Input/Output).\n\
\u2022The Economy menu (accessed from the Orbital Map) displays a given resource's supply and demand in each (already visited) sector. Typically, setting a trade route that will buy a resource where it's heavily produced and then selling it in a sector where it's heavily consumed is the way to go.\n\
\u2022Contracts arise from real needs. If the same delivery contracts keep coming from the same sector, a trade route may work well there as well."))
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("ResourcesTab", "Resources"))
.HeaderHelp(LOCTEXT("Resourcesnfo", "View information about resources"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("ResourcesTopTitle", "Resources"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("ResourcesTopMain", "There are 14 resources in Helium Rain. They all have different uses but they are all produced and consumed in stations, except for fleet supply."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("ResourcesRawMaterialsTitle", "\nRaw Materials"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("ResourcesRawMaterialsMain", "\
These resources are produced directly from the environment.\n\n\
\u2022Water\n\
\u2022Iron Oxyde\n\
\u2022Silica\n\
\u2022Methane\n\
\u2022Hydrogen\n\
\u2022Helium - 3"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("ResourcesManufacturingTitle", "\nManufacturing Resources"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("ResourcesManufacturingMain", "\
These resources are produced from raw materials and can be used as construction resources or to build consumer resources. \n\n\
\u2022Steel\n\
\u2022Plastics\n\
\u2022Carbon"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("ResourcesConsumerTitle", "\nConsumer Resources"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("ResourcesConsumerMain", "\
These resources can be bought by the population, but they may have other uses. \n\n\
\u2022Food\n\
\u2022Fuel\n\
\u2022Tools\n\
\u2022Electronics"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("ResourcesFleetSupplyTitle", "\nFleet Supply"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("ResourcesFleetSupplyMain", "The fleet supply is a very special resource used to repair or refill spacecrafts."))
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("TechnologyTab", "Technology"))
.HeaderHelp(LOCTEXT("Technologyinfo", "View information about technology"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("TechnologiesTopTitle", "Technologies"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("TechnologiesTopMain", "You can improve your company by researching technologies."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("TechnologiesUnlockTitle", "\nUnlock technology"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("TechnologiesUnlockMain", "\
Technologies can be unlocked permanently in the technology menu. To unlock a technology, you need to pay the displayed cost. You can only unlock technology with a level inferior or equal to your current technology level.\n\n\
The cost of a technology depends on its level and your technology inflation ratio.\n\n\
Cost = BaseCost * Level * InflationRatio\n\n\
The base cost is 20 research points.\n\n\
The inflation ratio is 1 and is multiplied by 1.3 each time your technology level increase (or 1.22 if you have the instruments technology)\n\n\
Example:\n\n\
\u2022Mining is a technology level 1. At the start of the game its cost is 20 ( 20 * 1 * 1). Unlock it multiply the inflation ratio by 1.3 to 1.3\n\
\u2022Quick repair is a technology level 2. After buying a technology, its cost is 52 (20 * 2 * 1.3).The inflation ratio is increase to 1.69 (1.3 * 1.3)\n\
\u2022I now unlock Metallurgy(level 2).Its cost is 67 (20 * 2 * 1.69).The inflation ratio is increase to 2.197\n\
\u2022To purchase the level 4 technology Bombing, I need 175 research points(20 * 4 * 2.197)"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("TechnologiesLevelTitle", "\nTechnology level"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(1.50 * Theme.ContentWidth)
.Text(LOCTEXT("TechnologiesLevelMain", "Your technology level increase by one each time you buy a technology.When your technology level increases, your Inflation Ratio is also increased. "))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("TechnologiesRPTitle", "\nResearch points"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("TechnologiesRPMain", "\
The research points needed to unlock technology can be gained in multiple ways:\n\n\
\u2022Contract Reward\n\
\u2022Research Station\n\
\u2022Capture ships and stations"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("TechnologiesListTitle", "\nTechnologies list"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("TechnologieGeneralTitle", "\n General"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("TechnologiesGeneralMain", "\
\n\
\u2022Instruments\n\
\u2022Effect: 0.08 lower research multiplier\n\
\u2022Quick Repair\n\
\u2022Effect: 50% faster repairs\n\
\u2022Diplomacy\n\
\u2022Effect: 50% lower reputation penalties\n\
\u2022Fast Travel\n\
\u2022Effect: 50 % faster travel speed"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("TechnologieEconomicTitle", "\n Economic"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("TechnologiesEconomicMain", "\
\n\
\u2022Science\n\
\u2022Unlock: Research Station, Orbital Telescope\n\
\u2022Logistics\n\
\u2022Unlock: Solar Power Plant, Habitation Center, Repair Outpost\n\
\u2022Mining\n\
\u2022Unlock: Ice Mine, Iron Mine, Silica Mine\n\
\u2022Chemicals\n\
\u2022Unlock: Plasic Production Plant, Carbon Refinery, Farm\n\
\u2022Metallurgy\n\
\u2022Unlock: Arsenal, Steelworks, Tool Factory\n\
\u2022Shipyard\n\
\u2022Unlock: Shipyard\n\
\u2022Orbital Pumps\n\
\u2022Unlock: Methane Pumping Station, Hydrogen Pump Station, Helium Pump Station\n\
\u2022 Advanced stations\n\
\u2022Unlock: Station Complex, Trading Hub, Foundry, Fusion Power Plant"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("TechnologieMilitaryTitle", "\n Military"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("TechnologiesMilitaryMain", "\
\n\
\u2022Early warning\n\
\u2022Effect: Enable notifications of incoming dangers\n\
\u2022Advanced radar\n\
\u2022Effect: Upgraded Early warning with more specific information\n\
\u2022Pirate Tech\n\
\u2022Effect: Unlock ship capture harpoons and increase station capture speed by up to 100%\n\
\u2022Negotiations\n\
\u2022Effect: 50% faster enemy station capture speed, 50% slower owned station capture speed\n\
\u2022Flak\n\
\u2022Effect: Unlock proximity-detonation weapons for use against fighters\n\
\u2022Bombing\n\
\u2022Effect: Unlock high-explosive bombs"))
]
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("StatisticalTab", "Statistical Information"))
.HeaderHelp(LOCTEXT("StatisticalInfo", "View various statistical information within Helium Rain"))
[
SNew(SFlareTabView)
+ SFlareTabView::Slot()
.Header(LOCTEXT("SpaceshipsTab", "Spaceships"))
.HeaderHelp(LOCTEXT("SpaceshipsInfo", "View information about spaceships"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("SpaceshipsTabTitle", "Spaceships"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("SpaceshipsTopMain", "\
Spaceships are the vessels piloted by the players in Helium Rain. Ships have generators, radiators, weapons, engines, cargo bays or life support systems - they all work together. Every thruster on a ship plays a role. Most of the ships have more than thirty individual parts to target. Players can customize their ship to enhance their performance or change their visual look.\n\
There are 2 categories of spaceships: the class S (for small) ships like fighter or bomber and the class L (for large) ships like cruiser or destroyer. Each category have a distinct list of upgrade (engine, weapons, etc), a separate production line in shipyards and different controls.\n\
Spaceships may be civilian or military. Civilian spaceships have a cargo bay and military spaceship have weapon slot (for S) or turret slot (for L)."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("SpaceshipsListTitle", "Spaceship Statistics"))
.TextStyle(&Theme.TitleFont)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SAssignNew(ShipSelector, SListView<TSharedPtr<FInterfaceContainer>>)
.ListItemsSource(&ShipList)
.SelectionMode(ESelectionMode::None)
.OnGenerateRow(this, &SFlareHelpMenu::OnGenerateSpacecraftLine, true)
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("StationsTab", "Stations"))
.HeaderHelp(LOCTEXT("StationsInfo", "View information about stations"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("StationsTabTitle", "Stations"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("StationsTopMain", "Stations in Helium Rain are places where players may trade resources, upgrade their ships and get contracts."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("StationsListTitle", "Station Statistics"))
.TextStyle(&Theme.TitleFont)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SAssignNew(StationSelector, SListView<TSharedPtr<FInterfaceContainer>>)
.ListItemsSource(&StationList)
.SelectionMode(ESelectionMode::None)
.OnGenerateRow(this, &SFlareHelpMenu::OnGenerateSpacecraftLine,false)
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("ComponentsTab", "Components"))
.HeaderHelp(LOCTEXT("ComponentsInfo", "View information about ship components"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
// Upgrades
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("ComponentsListTitle", "Component Statistics"))
.TextStyle(&Theme.TitleFont)
]
+ SVerticalBox::Slot()
.AutoHeight()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.Padding(Theme.TitlePadding)
[
SNew(SHorizontalBox)
// Engine
+ SHorizontalBox::Slot()
.AutoWidth()
[
SNew(SBox)
.WidthOverride(0.50 * Theme.ContentWidth)
[
SNew(SVerticalBox)
// Section title
+ SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.TitlePadding)
[
SNew(STextBlock)
.Text(LOCTEXT("EngineUpgradeTitle", "Orbital engines"))
.TextStyle(&Theme.SubTitleFont)
]
// Ship part picker
+ SVerticalBox::Slot()
.AutoHeight()
[
SAssignNew(EngineList, SListView< TSharedPtr<FInterfaceContainer> >)
.ListItemsSource(&EngineListData)
.SelectionMode(ESelectionMode::None)
.OnGenerateRow(this, &SFlareHelpMenu::GeneratePartInfo,5)
]
+ SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.TitlePadding)
[
SNew(STextBlock)
.Text(LOCTEXT("RCSUpgradeTitle", "RCS"))
.TextStyle(&Theme.SubTitleFont)
]
// Ship part picker
+ SVerticalBox::Slot()
.AutoHeight()
[
SAssignNew(RCSList, SListView< TSharedPtr<FInterfaceContainer> >)
.ListItemsSource(&RCSListData)
.SelectionMode(ESelectionMode::None)
.OnGenerateRow(this, &SFlareHelpMenu::GeneratePartInfo,5)
]
]
]
// Weapons
+ SHorizontalBox::Slot()
.AutoWidth()
.VAlign(VAlign_Top)
.HAlign(HAlign_Left)
[
SNew(SBox)
.HAlign(HAlign_Center)
.WidthOverride(1.25 * Theme.ContentWidth)
[
SNew(SVerticalBox)
// Section title
+ SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.TitlePadding)
[
SNew(STextBlock)
.Text(LOCTEXT("WeaponsUpgradeTitle", "Weapons"))
.TextStyle(&Theme.SubTitleFont)
]
// Ship part picker
+ SVerticalBox::Slot()
.AutoHeight()
[
SAssignNew(WeaponList, SListView< TSharedPtr<FInterfaceContainer> >)
.ListItemsSource(&WeaponListData)
.SelectionMode(ESelectionMode::None)
.OnGenerateRow(this, &SFlareHelpMenu::GeneratePartInfo,16)
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("CompaniesTab", "Companies"))
.HeaderHelp(LOCTEXT("CompaniesInfo", "View information about the various companies"))
/*
*/
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("CompaniesTabTitle", "Companies"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("CompaniesTopMain", "\
Companies are the factions which control the entire environment in Helium Rain. All stations and spaceships are controlled and constructed by individual companies. Companies all start the game with a differing amount of stations and ships but will expand the size of their empires. Each company has unique behaviors which effect what resources they prefer to trade and stations they prefer to build as well as how they distribute their efforts. Companies also each have a relationship with the player which effects diplomatic interactions with the company."))
]
// Ship part picker
+ SVerticalBox::Slot()
.AutoHeight()
[
SAssignNew(CompanyList, SListView< TSharedPtr<FInterfaceContainer> >)
.ListItemsSource(&CompanyListData)
.SelectionMode(ESelectionMode::None)
.OnGenerateRow(this, &SFlareHelpMenu::OnGenerateCompanyLine)
]
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("LoreTab", "Universe Lore"))
.HeaderHelp(LOCTEXT("LoreTabInfo", "View the Helium Rain background lore"))
[
SNew(SFlareTabView)
+ SFlareTabView::Slot()
.Header(LOCTEXT("HeliumRainSolarObjects", "Solar Objects"))
.HeaderHelp(LOCTEXT("HeliumRainSolarObjectsInfo", "View information about the Solar Objects in Helium Rain"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("BhydriTitle", "\u2022Bhydri"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("BhydriMain", "\
The star B Hydri is visible as the sun of Helium Rain.\n\n\
Physical characteristics\n\n\
\u2022Mass : 2.472 - 10 ^ 30 kg\n\
\u2022Radius: 739 886 km\n\
\u2022Surface : 6.879 - 10 ^ 12 km²\n\
\u2022Surface temperature : 5916 K\n\
\u2022Solar surface power : 69 MW / m²\n\
\u2022Solar power : 4.777 - 10 ^ 26 W"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("NemaTitle", "\n\u2022Nema"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("NemaMain", "\
Nema is the heart of the planetary system in Helium Rain. It is a gas giant orbiting B Hydri.\n\n\
Physical characteristics\n\n\
\u2022Mass : 8.421 - 10 ^ 26 kg(141 Earths)\n\
\u2022Radius : 69 586 km\n\
\u2022Flattening : 0.0316\n\
\u2022Equatorial radius : 70 706 km\n\
\u2022Polar radius : 68 465 km\n\
\u2022Surface gravity : 11.60 m / s²(1.18 g)\n\
\u2022Axial tilt : 3.886 °\n\
\u2022Sidereal rotation period : 26 h 50 min 33 s\n\
\u2022Volume : 1.411 - 10 ^ 24 m³\n\
\u2022Mean density : 596.635 kg / m³\n\
\u2022Albedo : 0.313\n\
\u2022Solar constant : 3.094 KW / m²\n\n\
Orbital characteristics\n\n\
\u2022Orbital period : 207.95 days\n\
\u2022Semi - major axis : 110 491 584 km\n\
\u2022Geostationary altitude : 167304 km(236890 km radius)"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("AnkaTitle", "\n\u2022Anka"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("AnkaMain", "\
Anka is one of the moons orbiting Nema. \n\n\
"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("HelaTitle", "\n\u2022Hela"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("HelaMain", "\
Hela is one of the moons orbiting Nema. \n\n\
"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("AstaTitle", "\n\u2022Asta"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("AstaMain", "\
Asta is one of the moons orbiting Nema. \n\n\
"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("AdenaTitle", "\u2022Adena"))
.TextStyle(&Theme.NameFontBold)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("AdenaMain", "\
Asta is one of the moons orbiting Nema. \n\n\
"))
]
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("TechnicalTab", "Technical"))
.HeaderHelp(LOCTEXT("TechnicalTabInfo", "Technical Information"))
[
SNew(SFlareTabView)
+ SFlareTabView::Slot()
.Header(LOCTEXT("VersionTab", "Version history"))
.HeaderHelp(LOCTEXT("VersionTabInfo", "Helium Rain version history"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("VersionHistory", "Release version history:"))
.TextStyle(&Theme.SubTitleFont)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.WrapTextAt(TextWrappingBig)
.TextStyle(&Theme.TextFont)
.Text(LOCTEXT("VersionHistoryMain", "\
1.3.7\n\n\
\u2022Fix mod launcher failing to load with Steam in Linux\n\n\
1.3.6\n\n\
Bugs Fixed\n\
\u2022Fix research points increasing too quickly with Instruments tech\n\
\u2022Fix people consuming resource during construction\n\n\
1.3.5\n\
\u2022GOG support\n\n\
1.3.4\n\n\
\u2022Fix OpenGL3 support\n\n\
1.3.3\n\n\
Bugs fixed\n\
\u2022Fix station scrapping not detecting all cargos\n\
\u2022Fix free money exploit on contracts\n\
\u2022Cleanup unwanted files from client\n\n\
1.3.2\n\n\
Bugs fixed\n\
\u2022Fix crash when clicking end-of-construction notification for complexes\n\n\
1.3.1\n\n\
Bugs fixed\n\
\u2022Fix Linux support\n\
\u2022Fix failure to launch mod launcher offline\n\n\
1.3.0\n\n\
Gameplay\n\
\u2022Add new military contracts\n\
\u2022Add technical support for modding, including a new launcher tool\n\n\
UI\n\
\u2022Add Russian localization\n\
\u2022Add mod list to the main menu\n\n\
Bugs fixed\n\
\u2022Fix contract locking only working for trade contract\n\
\u2022Fix ships trading in empty sectors\n\n\
1.2.1\n\n\
UI\n\
\u2022HUD is now kept at a unique scale from 1080p and higher resolutions so that it's still readable\n\n\
Bugs Fixed\n\
\u2022Fix autopilot not disengaged with joystick inputs\n\
\u2022Fix joystick throttle leading to extreme thrust values\n\n\
1.2.0\n\n\
Gameplay\n\
\u2022New flight control model that allows for concurrent inputs\n\
\u2022Meteorite contracts have reduced meteor counts, higher intercept time, lower probability of spawning\n\
\u2022Queued spacecraft orders are now cancelled when disabling external shipyard orders\n\
\u2022Player-fleet ships escort the player around the sector\n\
\u2022Add sound effect on docking\n\
\u2022Trading quests are more worthwile\n\n\
UI\n\
\u2022Improve docking HUD to make it easier to understand\n\
\u2022HUD is slightly sharper across the board\n\
\u2022Add option to disable mouse input\n\
\u2022Add option to show lateral velocity on the HUD\n\
\u2022Artifact scanner now blinks to attract player attention\n\n\
Bugs Fixed\n\
\u2022Fix auto-trading ships ignoring the \"trade\" flag of cargo bays\n\
\u2022Fix ships appearing in the trade menu as possible trading targets (ship-to-ship trading isn't supported)\n\
\u2022Fix joystick throttle cancelling autopilot\n\
\u2022Fix jerky motion of joystick controls\n\
\u2022Fix inverted credit and debit columns\n\
\u2022Fix speed indicator not scaling with resolution\n\
\u2022Fix complex stations showing unusable upgrade button\n\
\u2022Fix electronics requested at contracts while none is produced\n\
\u2022Fix useless and confusing fleet filter appearing on the spacecraft list in the fleet menu\n\
\u2022Fix some cases of game crashes while simulating many days quickly\n\
\u2022Fix game crash on hotkey press in some conditions\n\
\u2022Fix some collision issues at Blue Heart\n\n\
1.1.5\n\n\
Bugs Fixed\n\
\u2022Attempt to fix some crashes\n\n\
1.1.4\n\n\
Bugs Fixed\n\
\u2022Fix collision issues in Night's Home\n\
\u2022Fix complex cargo bays not allowing more than half hold for trade routes\n\n\
1.1.3\n\n\
Bugs Fixed\n\
\u2022Fix complex stations not allowing construction of shipyards\n\n\
1.1.2\n\n\
Gameplay\n\
\u2022Reduce migrations of populations between sectors\n\n\
Bugs Fixed\n\
\u2022Fix complex cargo bays locking up\n\
\u2022Fix miscellaneous trading issues\n\
\u2022Fix notifications of scrapping by AI companies\n\
\u2022Fix auto-trading fleets not handling fleet supplies\n\
\u2022Fix auto-trading fleets not selling\n\
\u2022Fix auto-trading still enabled after assigning a fleet to a trade route\n\
\u2022Fix blocked quest step on the Pendulum contract\n\
\u2022Fix station construction limits in sector blocking substation construction\n\
\u2022Fix contract generation while a fleet is stranded at the end of the travel\n\
\u2022Fix trade route sliders acting up\n\
\u2022Fix typos, contracts wording, bad tooltips\n\n\
1.1.1\n\n\
Gameplay\n\
\u2022Trade routes don't default to trading with hubs anymore\n\
\u2022Balance Fusion Power Plant\n\n\
Graphics & UI\n\
\u2022Add \"Trade with Hubs\" options to trading steps in the Trade Route menu\n\
\u2022Add arrow icons on \"Move Up\" & \"Move Down\" buttons in the Trade Route menu\n\
\u2022Add \"Include Hubs\" option to the World Economy menu\n\
\u2022Add sorting buttons to the World Economy & Resource Prices menu\n\
\u2022F4 now the default key binding for the World Economy menu, moving other menus to higher function keys (main menu is F10, settings F12, etc)\n\
\u2022Improve performance in Night's Home\n\n\
Bugs fixed\n\
\u2022Fix automated trading not evaluating sales correctly\n\
\u2022Fix automated trading stopping sector search on the first hostile sector\n\n\
1.0.2\n\n\
Gameplay\n\
\u2022Make artifacts more rewarding in end-game\n\
\u2022Remove time limits on VIP contracts\n\n\
Bugs Fixed\n\
\u2022Fix fleet controls available on AI fleets\n\
\u2022Fix auto-trade not actually requiring the matching technology\n\
\u2022Fix high memory usage and performance issues in company log\n\
\u2022Fix typos in texts\n\
\u2022Fix \"buying\" transactions not defaulting to the contract-bound amount\n\
\u2022Fix crash on sector reload\n\n\
1.0.1\n\n\
Gameplay\n\
\u2022Reduce artifact research gain from 100 to 40\n\n\
Bugs fixed\n\
\u2022Rename \"Travels\" title to \"Events\" for clarity\n\n\
1.0.0\n\n\
Gameplay\n\
\u2022Add artifact system to earn research points through exploration\n\
\u2022Add Anomaly & Pharos sectors\n\
\u2022Rework Trading Hub that now act as a resource buffer, renamed to Storage Hub, can no longer be built at complexes\n\
\u2022Rework economy model\n\
\u2022Day simulations are faster to process\n\
\u2022Trade routes now skip inactive sectors\n\
\u2022Trade routes now have two additional trade limit types\n\
\u2022Ambient spacecraft power sound updated to be less annoying\n\
\u2022Lighthouse is now a known sector on new games\n\n\
Balancing\n\
\u2022AI factions now produce less smaller ships in end-game\n\
\u2022Hammer gun deals less damage and has reduced accuracy\n\
\u2022Mjolnir gun deals more damage\n\n\
Graphics & UI\n\
\u2022Upgrade the side panel in the orbital menu\n\
\u2022Upgrade menu background animation\n\
\u2022Remove Early Access branding\n\n\
Bugs fixed\n\
\u2022Fix impossible contracts\n\
\u2022Fix global AI nerf system\n\
\u2022Fix shipyard tutorial not explaining the potential requirement of resource gathering\n\
\u2022Fix unclear trade route menu when no fleet is assigned\n\
\u2022Fix collision issues in some sectors\n\
\u2022Fix crash when entering the skirmish setup menu too quickly\n\
\u2022Fix crashes caused by back key operation after game unload\n\
\u2022Fix crash on game load when nickname of a ship is empty\n\
\u2022Remove dead achievement"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("VersionEAHistory", "\nEarly Access version history:"))
.TextStyle(&Theme.SubTitleFont)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.WrapTextAt(TextWrappingBig)
.TextStyle(&Theme.TextFont)
.Text(LOCTEXT("VersionHistoryEAMain", "\
Early Access 10/06/08\n\n\
Bugs fixed\n\
\u2022Fix crash on game load in some cases\n\n\
Early Access 21/05/08\n\n\
Graphics & UI\n\
\u2022Add transaction log menu\n\
\u2022Add accounting menu\n\
\u2022Split tutorials from contracts in the contract menu\n\
\u2022Make blur effects nicer-looking\n\n\
Bugs Fixed\n\
\u2022Fix crash on trade route edition\n\
\u2022Fix unusable UI on some Linux devices\n\
\u2022Fix autopilot stuck on the Farm\n\n\
Early Access 25/03/18\n\n\
Gameplay Changes\n\
\u2022Add new sector \"The Farm\" with capital station\n\
\u2022Add retry feature to the skirmish score menu\n\
\u2022Remove collision damage from ships to stations\n\n\
Graphics & UI\n\
\u2022Add backlighting from planets\n\
\u2022Fix lighting artifacts on Nema's rings\n\
\u2022Upgrade Nema with a nicer texture\n\
\u2022Upgrade rendering quality in various places\n\n\
Bugs fixed\n\
\u2022Fix crash on travel\n\
\u2022Fix notification freeze at the end of a travel\n\
\u2022Fix some skirmishes not counted as a win despite victory\n\
\u2022Fix incorrect additional binding for thrust input\n\
\u2022Fix AI stations upgrading stations beyond max level\n\
\u2022Fix company logo covering some contract descriptions\n\
\u2022Fix useless cargo bays in complexes\n\
\u2022Fix cargo bay lock system\n\
\u2022Fix complex's shipyard not always starting production\n\
\u2022Fix random crash on opening the sector menu\n\
\u2022Fix some cases of scrapping not going back from the menu\n\n\
Other changes\n\
\u2022New Unreal Engine version 4.19\n\
\u2022Save files are now compressed for smaller size\n\n\
Early Access 26/01/18\n\n\
Gameplay Changes\n\
\u2022Reduce Hammer gun damage by 33%\n\
\u2022Reduce Artemis accuracy by 30%\n\n\
Bugs fixed\n\
\u2022Fix crash on combat toggle\n\n\
Early Access 25/01/18\n\n\
Gameplay Changes\n\
\u2022Add Skirmish mode to create custom battles against AI opponents\n\
\u2022Rework gun controls on capital ships\n\
\u2022Reduce diplomatic penalties on station capture\n\
\u2022Turrets and AI ships now target missiles and meteorites\n\
\u2022Tweak overall balance for all weapons and ships\n\
\u2022Increase turret coverage on Anubis cruiser\n\
\u2022Increase turret coverage on Dragon corvette\n\
\u2022Move Leviathan camera to the front turret\n\n\
Graphics & UI\n\
\u2022New Dragon model\n\
\u2022Upgrade farm model\n\
\u2022Upgrade Blue Heart, Night's Home stations models\n\
\u2022Upgrade weapon sounds\n\
\u2022Upgrade alarm sounds\n\
\u2022Add new fleet icon for military fleets\n\n\
Bugs Fixed\n\
\u2022Fix flak shells not working on missiles and meteorites\n\
\u2022Fix flak shells fired with incorrect fuse setting from player ships\n\
\u2022Fix AI ships not correctly using multiple weapon slots\n\
\u2022Fix missiles braking away from high-velocity ships\n\
\u2022Fix shipyard queue not transferred on capture\n\
\u2022Fix ability to fly ships from a different fleet when using the context menu\n\
\u2022Fix crash on hitting the \"4\" key while in menus\n\
\u2022Fix sound cuts while switching ships\n\
\u2022Fix effect sounds fading away while moving\n\n\
Other Changes\n\
\u2022New Unreal Engine version with Vulkan support\n\
\u2022Remove APEX physics for meteorites\n\
\u2022Add Steam trading cards\n\n\
Early Access 02/12/17\n\n\
Graphics & UI\n\
\u2022Add an option to list spacecrafts as fleets in object lists\n\
\u2022Add pause button on trade routes\n\
\u2022Add clean black bars to the story pages\n\
\u2022Sort resource slots by input/output status\n\
\u2022Reduce cockpit blur\n\n\
Bugs fixed\n\
\u2022Fix Pendulum quest not taking resources\n\
\u2022Fix fleet tutorial\n\
\u2022Fix docking at complexes with large ships\n\
\u2022Fix crash on fast forward with high numbers of stations\n\
\u2022Fix crash in the trade route menu\n\
\u2022Fix complexes not listed in the trade menu\n\
\u2022Fix display issues on the orbital map\n\
\u2022Fix fleets not ordered in a sane way\n\
\u2022Fix spacecraft hotkeys not ignored while typing\n\
\u2022Fix cracks in RCS audio\n\n\
Early Access 23/11/17\n\n\
Bugs fixed\n\
\u2022Fixed ships stuck waiting on a station that doesn't trade\n\
\u2022Fixed cargo bay locked by incorrect resources when upgrading stations\n\
\u2022Fixed complex shipyard not offering production options on slot 8\n\
\u2022Fixed aspect ratio of trade route menu\n\
\u2022[tentative] Fixed crashes in the trade route menu\n\n\
Early Access 09/11/17\n\n\
Gameplay changes\n\
\u2022New station complex system, allowing multiple stations to work together and share resources\n\
\u2022New station cost & limitation system, making stations more affordable\n\
\u2022Station capture is now a manual process to avoid batch capture of unwanted stations\n\
\u2022Stations can now be scrapped for their resources\n\
\u2022Increase station spawn distance to avoid collisions\n\
\u2022Add very small guidance on harpoons\n\
\u2022Automatically fill the construction cargo bay with the production cargo bay if possible\n\
\u2022Add a new gamepad profile for left-handed players\n\n\
Graphics & UI\n\
\u2022New Unreal Engine version, adding Linux support to AMD users with LLVM5\n\
\u2022UI is now 15% denser overall to allow for more information on screen\n\
\u2022New company menu with company renaming, emblem selection\n\
\u2022New orbital map menu with prettier graphics & fleet locations\n\
\u2022New sector menu layout\n\
\u2022New technology menu layout\n\
\u2022Rendering is now slightly sharper overall\n\
\u2022Add button to unbind joystick axis mappings\n\
\u2022Add sector selector to the local economy menu\n\n\
Bugs fixed\n\
\u2022Fix teleportation on docked ship upgrade\n\
\u2022Fix crash when rebinding keys\n\
\u2022Fix military tactics control unavailable outside battles\n\
\u2022Fix arrow keys being un-rebindable\n\
\u2022Fix manual docking failing with joysticks\n\
\u2022Fix manual docking near Blue Heart\n\n\
Early Access 05/09/17\n\n\
Gameplay changes\n\
\u2022Allow manual docking with anticollision enabled\n\
\u2022Add colinearity test on manual docking\n\
Bugs fixed\n\
\u2022Fix cut text on cockpit screens\n\
\u2022Fix anticollision while docking\n\
\u2022Fix UI cut in square or vertical resolutions\n\n\
Early Access 03/09/17\n\n\
Graphics & UI\n\
\u2022All stations now feature a larger, improved design\n\
\u2022Improve cockpit fonts\n\
\u2022Improve rendering quality to minimize aliasing\n\
\u2022Improve rendering quality of the sun\n\n\
Gameplay changes\n\
\u2022Reduce turn rate of heavy AI ships to avoid to disturbing turret aiming\n\
\u2022Make Miner's home visible at game start to allow access to steel\n\
\u2022Make the player start with one free technology\n\
\u2022Allow order of one heavy ship and one light ship at shipyards\n\
\u2022Clarify contract expirations\n\
\u2022AI player ships now only attack stations with the \"attack stations\" tactic\n\
\u2022Telescopes now warn when no sector is left to be found\n\n\
Bugs fixed\n\
\u2022Fix many cases of indirect reputation loss\n\
\u2022Fix trade route loading operation using only one ship\n\
\u2022Fix contract buyer unable to buy the contracted resources\n\
\u2022Fix anticollision issues in Blue Heart\n\
\u2022Fix menu deadlock when building a station in the current sector with ship in reserve\n\
\u2022Fix weapon swap unauthorized for barely damaged ships\n\
\u2022Fix attack notification with 0 fleet\n\
\u2022Fix AI upgrading stations during contracts on these stations\n\
\u2022Fix building rate of habitations by AI\n\
\u2022Fix resource consumption estimate of shipyards\n\
\u2022Fix reputation shame mechanism\n\
\u2022Fix company combat value acting up\n\
\u2022Fix bad Thera thrust value\n\
\u2022Fix immediate sector exit when flying a repaired ship\n\
\u2022Fix incorrect construction values for Tokamaks\n\
\u2022Fix crash when researching sectors with a telescope\n\
\u2022Fix negative population\n\
\u2022Fix AI trade bug leading to economy freeze\n\n\
"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
//splitting text, at string limit
SNew(STextBlock)
.WrapTextAt(TextWrappingBig)
.TextStyle(&Theme.TextFont)
.Text(LOCTEXT("VersionHistoryEASecondary", "\
Early Access 27/08/17\n\n\
Gameplay changes\n\
\u2022Complete overhaul of shipyards to add a production queue. Spacecrafts are now built in the order they arrive so that expensive ships can be built.\n\
\u2022Prevent end - game alliances against the player.Building up a large military force is still subject to slow loss of reputation, but AIs are no longer compelled to attack the player with no provocation.AI companies can still ally against another AI company that places itself in a dominant position.\n\
\u2022Manual docking has much more speed control, more accurate docking computer, lower grabbing threshold on L ships\n\
\u2022Trade route deals will now only offer actual deals that make some amount of sense\n\
\u2022Prevent generation of trade quests if the player has zero cargo space\n\
\u2022Make meteorites spawn closer to reduce chance of being outside sector\n\
\u2022Reduce combat points of weapons to better reflect the impact of upgrades\n\
\u2022Reduce nerf ratio of companies so that they handle more of the economy\n\n\
Bugs fixed\n\
\u2022Fix crash when AI docks early in the loading with no player ship spawned\n\
\u2022Fix Tokamak station not producing fuel\n\
\u2022Fix \"max quantity\" slider acting up in the trade route menu\n\
\u2022Fix research level appearing as more than what exists\n\
\u2022Fix joystick keys not appearing for the bindings they've been set to\n\
\u2022Fix color picker resetting to \"round\" colors\n\
\u2022Fix docking helpers on L ships\n\
\u2022Fix meteorite quests displaying empty when the station is destroyed\n\
\u2022Fix out - of - screen in some resolutions\n\
\u2022Fix stations pushing bank account to negative values\n\
\u2022Fix a collection of trade bugs\n\
\u2022Fix cut text on technology menu, trade route menu\n\
\u2022Fix bad station count in the sector menu\n\
\u2022Fix fighting tutorial\n\
\u2022Fix research station tutorial\n\n\
Graphics & UI\n\
\u2022Headlights now more powerful\n\
\u2022Fix heat artifacts on Anubis FP view\n\
\u2022Make debris densities slightly higher\n\
\u2022Make some menus work better in very wide apect ratios\n\
\u2022Make speed reticles more visible on HUD\n\
\u2022Make stations show up as stations in the spacecraft menu\n\
\u2022Make nose icons a bit larger\n\
\u2022Better confirm travel text\n\
\u2022Fix lots of typos and translation issues\n\n\
Early Access 25/08/17\n\n\
Gameplay changes\n\
\u2022Nerf meteorite damage to stations\n\
\u2022Make autopilot dock at target if a station is selected\n\
Bugs fixed\n\
\u2022Fix water not in drop list in the trade route menu\n\
\u2022Fix fleet selection in the sector menu\n\
\u2022Fix joystick buttons unusable as bindings\n\
\u2022Fix joystick bindings not saved\n\
\u2022Fix horizontal hat of joystick ignored\n\
\u2022Fix virtual scroll registering as a real key in settings menu\n\
\u2022Fix docking guides disappearing\n\
\u2022Fix spread between Solen and docks\n\
\u2022Fix Orca cockpit cut at high FOV\n\
\u2022Fix Atlas freighter having damaged cooling at full health\n\
\u2022Fix French translation\n\
\u2022Fix wrong tech for research stations in tutorial\n\
\u2022Fix vertical artifacts in drop lists in the color panel\n\
\u2022[tentative] Fix rare crash when selecting docking option\n\n\
Graphics & UI\n\
\u2022Rework sector exiting to clarify what happens\n\
\u2022Better resource & economy menus\n\
\u2022Show where ships are built on the orbital map\n\
\u2022Add station, ship count to trade routes\n\
\u2022Add gamma settings, input sensitivity setting\n\
\u2022Make RCS effects more agressive in reaction times\n\
\u2022Make the sky slightly dynamic\n\
\u2022Make Hela slightly better - looking\n\n\
Early Access 22/08/17\n\n\
New features & content\n\
\u2022Special characteristics of stations are now shown in UI & HUD : shipyard, station in construction, contract objective, and so on.\n\
\u2022New trade route menu that features hints on where to buy or sell resources\n\
\u2022New alternative gamepad bindings to turn with the left stick and move with the right one\n\n\
Gameplay changes\n\
\u2022Change gamepad bindings : shoulder pads now mapped to speed, left stick to lateral movement, thumbsticks to roll.\n\
\u2022Don't show the docking computer if the dock isn't on screen\n\
\u2022Remove research level 3 technology from technology tutorial\n\
\u2022Enable fleet orders from the wheel menu on all military ships\n\
\u2022Add BH habitations to target objective during pendulum contract\n\
\u2022Highlight the mine to dock at during the navigation tutorial\n\n\
Bugs fixed\n\
\u2022Fix crash on shipyard building\n\
\u2022Fix trade route not perfoming operations correctly when there is more than one ship in the assigned fleet\n\
\u2022Fix some drop lists always showing the first item\n\
\u2022Fix a number of typo errors\n\
\u2022Fix Blue Heart collision boxes\n\n\
Graphics & UI\n\
\u2022Upgrade company icons & colors\n\
\u2022Tweak lighting to reduce artifacts on large stations\n\
\u2022Remove atifacts at night on Hela\n\
\u2022Add tabs to the settings menu\n\
\u2022Show reduction of production in spacecraft info\n\
\u2022Center mines in the inspect menu\n\
\u2022Remove resource price list from the trade menu as it was confusing\n\
\u2022Hide notification counter while flying\n\n\
Early Access 20/08/17\n\n\
New features & content\n\
\u2022Full support for gamepad & joystick\n\
\u2022UI scaling at high resolutions\n\
\u2022Field - of - view setting\n\
\u2022Key bindings to cut speed, start a trade\n\n\
Gameplay changes\n\
\u2022Nerf the collision alarm to a more aggressive threshold\n\
\u2022Show scanning screen instead of docking computer when both are active\n\
\u2022Reduce the number of waypoints in tutorial\n\
\u2022Undocking now gives the player control much faster\n\n\
Bugs fixed\n\
\u2022Fix blinding effects on the Solen freighter\n\
\u2022Fix notification counter\n\
\u2022Fix conflict with Steam VR\n\
\u2022Fix some conflicting inputs\n\
\u2022Fix collision risk when AI ships undock\n\
\u2022Fix trade route quantity limit\n\
\u2022[tentative] Fix multiple joysticks merged as one\n\
\u2022[tentative] Fix some crashes\n\n\
Graphics & UI\n\
\u2022The rings of Nema are now slightly bluer\n\
\u2022Make company icon selection easier to understand\n\
\u2022Add gamepad input map to the settings menu\n\n\
Early Access 18/08/17\n\
This is the first public release in Early Access. Enjoy the game !\n\n\
Gameplay changes\n\
\u2022Add notification if a trade route is locked by a danger in the destination sector\n\n\
Bugs fixed\n\
\u2022Fix recovery to avoid being stranded\n\
\u2022Fix missing step in tutorial\n\n\
Graphics & UI\n\
\u2022New design for the Atlas freighter\n\
\u2022Upgrade rendering quality for the Solen freighter & Orca bomber\n\
\u2022Upgrade hull detail with a nicer pattern\n\
\u2022Change Fleet Supply icon to remove non - localized text"))
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("VersionBetaTab", "Version history (beta)"))
.HeaderHelp(LOCTEXT("VersionBetaTabInfo", "Helium Rain version history(beta)"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("VersionHistoryBeta", "Beta version history:"))
.TextStyle(&Theme.SubTitleFont)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.WrapTextAt(TextWrappingBig)
.TextStyle(&Theme.TextFont)
.Text(LOCTEXT("VersionHistoryBetaMain", "\
Early Access 17/08/17\n\n\
New features & content\n\
\u2022The player fleet can now be renamed\n\
\u2022Add basic mouse emulation for joysticks\n\
\u2022Add option to invert Y - axis\n\n\
Gameplay changes\n\
\u2022Add reputation penalty when shooting incapacited ships\n\
\u2022Balance pirates\n\
\u2022Balance station cost\n\
\u2022Reduce ship construction time\n\n\
Bugs fixed\n\
\u2022Fix 'Request peace' button wording if other company want peace\n\
\u2022Fix docking bug where the docking state seemed corrupted\n\
\u2022Fix z - fighting on Outpost stations\n\
\u2022Fix strange dock layout on farms\n\
\u2022Fix artifacts on Fuji exhaust\n\n\
Graphics & UI\n\
\u2022Upgrade design of the Anubis cruiser\n\
\u2022Upgrade metal rendering\n\
\u2022Add 'move' buttons to sectors in the trade route editor\n\
\u2022Add warning when abandoning a contract\n\
\u2022Add info that military contracts require military ships\n\n\
Early Access 03 / 08 / 17\n\
Gameplay changes\n\
\u2022Make light cockpits more resistant to have a chance to survive Hammer hits\n\
\u2022Balance trade contracts to allow multiple contracts\n\
\u2022Make AI take prisoners after battle and guard them\n\n\
Bugs fixed\n\
\u2022Fix auto - docking technology not unlocking auto - docking option in menus\n\
\u2022Fix crash and game state corruption on game over while docked\n\
\u2022Remove debugging shortcut\n\
\u2022Wording and translation fixes\n\n\
Early Access 30 / 07 / 17\n\
New features & content\n\
\u2022New manual docking gameplay and tutorial\n\
\u2022New music for some sectors\n\
\u2022New high - resolution screenshots shortcut on R key\n\n\
Gameplay changes\n\
\u2022Move Hub station to end - game because it's a common mistake to buy one early\n\
\u2022Remove support for \"no-cockpit\" HUD because it's too much work to maintain\n\n\
Graphics & UI\n\
\u2022Improve farming stations\n\
\u2022Improve manual docking HUD\n\
\u2022Make docking rings blink every second\n\
\u2022New hotkeys for spacecraft actions\n\
\u2022Input bindings duplicates can be automatically replaced\n\
\u2022Scrapping of ships is now confirmed\n\
\u2022Disable button to add trade routes if no fleet is available\n\
\u2022Remove default binding for \"face backward\"\n\n\
Bugs fixed\n\
\u2022Fix fast forward button state when canceling confirmation popup\n\
\u2022Fix transaction quantity limited by its money even for trade with its ours stations\n\
\u2022Fix station destruction bug leading to corrupted save\n\n\
Beta - 230717\n\
New features & content\n\
\u2022Add Steam achievements\n\
\u2022Add new scanner mini - game for inspection in Pendulum contract\n\n\
Gameplay changes\n\
\u2022No more enable pilot in fire director mode for heavy ships\n\
\u2022Allow docking with menu during navigation tutorial\n\n\
Graphics & UI\n\
\u2022Improve all planet and moon render\n\
\u2022Use progress bar instead of percentages in cockpits\n\
\u2022Make fleet to travel selection more persistent\n\
\u2022Update game icon\n\
\u2022Rework ship info buttons layout\n\
\u2022Disable no - cockpit mode\n\
\u2022Use company customization pattern as background pattern in UI\n\
\u2022Improve quality of weapon impacts\n\
\u2022Make the sky slightly brighter\n\
\u2022A lot of small UI and wording improvements\n\n\
Bugs fixed\n\
\u2022UI : fix too long joystick button and names\n\
\u2022UI : fix dragging issues in menus causing unexpected rotation on background assets\n\
\u2022UI : fix HUD distance rounding issue\n\
\u2022UI : fix selection of ships with light during piloting\n\
\u2022UI : fix wrong warning when targeting the tracked station\n\
\u2022General : a lot of french translation fixes\n\n\
Beta - 100717\n\
New features & content\n\
\u2022Add a meteorites intercept contract\n\
\u2022Add trade route statistics\n\
\u2022Add experimental French translation(some layout issues)\n\n\
Gameplay changes\n\
\u2022Don't generate military contracts if the player doesn't have military ships\n\
\u2022Use interception time instead of distance to show aim indicators at a more accurate range\n\n\
Graphics\n\
\u2022Upgrade shadowing quality to reduce artifacts\n\
\u2022Upgrade resolution of shadows on Nema's rings\n\
\u2022Reduce performance cost of Eradicator impact effects\n\
\u2022Update splash screen\n\n\
Bugs fixed\n\
\u2022General : fix ships ejected from trade route if not all ship were trading\n\
\u2022General : fix research station upgrade effect\n\
\u2022General : fix telescope station upgrade effect\n\
\u2022General : make the player ship not fully destructible instead of the last alive ship to avoir recovery bug\n\
\u2022UI : fix funny key change warning when removing a key assignment\n\
\u2022UI : fix trade slider init with sell to a station for a contract\n\
\u2022UI : fix lock trade checkbox that stop the production\n\
Beta - 300617\n\
General\n\
\u2022pass the game to qwerty by default\n\
\u2022move default binding of 'lock direction' to capslock and 'combat zoom' to space\n\n\
Gameplay\n\
\u2022no more allow station construction in a sector in danger\n\n\
AI\n\
\u2022make AI able to declare join war againt enemy more powerful than every company induvidialy\n\
\u2022make AI able to setup attack from multiple company to allow multiple company to win against one powerful ennemy\n\n\
UI\n\
\u2022rename \"Travel and Order\" in \"Incoming Events\"\n\
\u2022enable notification masking\n\
\u2022show again trade routes in orbital map\n\
\u2022add current battle in incoming events list\n\
\u2022show warning in settings menu when trying to assign an already assigned key\n\
\u2022set default quantity for trade to the right value when the tracked contract have a sell condition\n\n\
Graphics\n\
\u2022add iridescence effect to metals\n\
\u2022improve reflection quality\n\n\
Balance\n\
\u2022move default ship count in sector to 30\n\n\
Bugs\n\
\u2022general : fix Boneyard collision mode\n\
\u2022general : fix crash if trying to upgrade a ship with weapon that are not unlock by technology(after ship capture)\n\
\u2022ui : fix external camera and menu camera for Windows\n\
\u2022ui : fix trading status text\n\
\u2022ui : fix fly interdiction text\n\
\u2022contract : fix duplicate fail condition when a trade contract have 2 stations owned by the same company\n\
\u2022contract : various contract text fixes\n\n\
Beta - 190617\n\
General\n\
\u2022switch to Unreal Engine 4.16\n\
\u2022add Deimos Games logo and info\n\n\
Gameplay\n\
\u2022new more understandable recovery system : you don't have a new free ship but the old one is partially repair and you have a fine.\n\
\u2022don't generate trade contracts with stations being captured\n\n\
Tutorials\n\
\u2022add fleet management tutorials\n\
\u2022add remote fleet tutorial\n\
\u2022add trade route tutorial\n\
\u2022force to buy a freigther in \"buy ship\" tutorial\n\n\
UI\n\
\u2022rework EULA and credit menu\n\
\u2022auto track the last contract(instead of the first) by defaut when a contract is finished to allow chained quest to be smooth\n\n\
Graphics\n\
\u2022assure that planet texture quality is always good\n\
\u2022add boneyard icons to its substations\n\n\
Balance\n\
\u2022make stations a lot more affordable for the player in early game\n\
\u2022the price now depend only of the player station count in its company and in the sector\n\
\u2022Increase trade contract reward :\n\
\u2022trade contracts :\n\
\u2022from 1000 + 500 sqrt(travel_duration) + 50 sqrt(resource_quantity)\n\
\u2022to 1000 + 1000 sqrt(travel_duration) + 100 sqrt(resource_quantity)\n\
\u2022buy and sell contracts :\n\
\u2022from 500 + 50 * sqrt(resource_quantity)\n\
\u2022to 500 + 100 * sqrt(resource_quantity)\n\
\u2022make trade contract volume more variable if capacity transport of the player vary\n\
\u2022make axis reputation very stable as they are neutral\n\n\
Bugfix\n\
\u2022ui : multiple wording fixes\n\
\u2022contracts : fix contract unicity\n\
\u2022contracts : avoid contract to fail at acceptation making them not available as soon as the failed conditions are reached\n\n\
Beta - 120617\n\
Gameplay\n\
\u2022Quick patch to fix risk of economy collapse that a lock a game, with others fixes and improvements.\n\
\u2022increase anticollision system precision and make it adaptative to ships breaking capabilities\n\n\
UI\n\
\u2022show repair and refill deadline in travel sector\n\
\u2022make player confirm fast forward if the is no incoming events\n\
\u2022make notification slower to disappear(7s -> 10s)\n\n\
Balance\n\
\u2022tutorial : reduce research needs for technology tutorial from 50 to 30, to match with the new technology base price\n\n\
Bugs\n\
\u2022economy : avoid economy collapse due to people not spending enough money\n\
\u2022autopilot : fix exit avoidance system using incoherent center of sector\n\
\u2022ui : fix sector menu for travel sectors\n\
\u2022graphics : fix planetarium for travel sectors after sector exit"))
]
// splitting up the string...too many characters
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.WrapTextAt(TextWrappingBig)
.TextStyle(&Theme.TextFont)
.Text(LOCTEXT("VersionHistoryBetaSecondary", "\
\nBeta - 090617\n\
General\n\
\u2022Update legals informations\n\n\
Gameplay\n\
\u2022make bombs and missiles destructible by the player\n\
\u2022no more make ships assigned to a trade route travel automatically to a dangerous sector\n\n\
UI\n\
\u2022move trade route selection to company menu to make more space to incoming events\n\
\u2022refactor incoming attack list and notifications\n\
\u2022make new contracts notifications no more stop fast forward\n\
\u2022add more details about shipyard state in the shipyard details\n\
\u2022make harder to accidentally dump precious resources\n\
\u2022better texts when trade operation is not possible\n\
\u2022add notification when fleet repair or refill end\n\
\u2022add information about station under construction in trade menu\n\
\u2022rename \"World prices\" menu to \"Economy\"\n\n\
Graphics\n\
\u2022move planetarium to follow travel progress\n\
\u2022improve engine render\n\
\u2022improve flight effects\n\
\u2022improve asteroid rendering quality\n\n\
Balance\n\
\u2022reduce technology base cost from 50 to 30\n\
\u2022refactor station technologies : the new level 1 \"science\" technology allow to build research station and telescope, the pumping technology move from level 1 to level 3, the foundry is now unlock with advanced stations\n\
\u2022change the Solen to give it a cargo bay of 2x50 instead of 1x100\n\
\u2022make Hammer gun more precise but a lot more expensive\n\
\u2022reduce Omen mass from 32t to 16t\n\
\u2022force the player to manually make peace after an AI declare war to him\n\
\u2022make pacifism move more slowly : pacifism increase base rate : 2.0 -> 0.8, pacifism decrease base rate : 1.0 -> 0.6, give reputation when ordering a ship to a company(ship price / 1000)\n\
\u2022increase inter company UBI contribution from 0.001 to 0.002\n\n\
Bugs\n\
\u2022ui : fix crash when editing a trade route operation if no fleet was assigned\n\
\u2022ui : fix tool - tip for when the \"Remove ship\" button in edit fleet menu was disabled\n\
\u2022ui : make failed contracts due to expiration date not display \"1 day left\"\n\
\u2022ui : fix minor interface glitch in not visited sectors\n\
\u2022ui : fix rotation of HR logo in menus\n\
\u2022ui : fix The Forge sector description\n\
\u2022graphics : fix AA settings bug\n\
\u2022graphics : adapt resolution when enabling full screen\n\
\u2022graphics : remove tesselation from Colossus to ensure Linux support\n\
\u2022general : fix repair not correctly ending bug\n\
\u2022general : check recovery at the end of each day and not only at the end of fast forward\n\n\
Beta - 020617\n\
General\n\
\u2022add support of unidirectional joystick thrust\n\
\u2022add support for joystick dead zones\n\n\
UI\n\
\u2022show \"missing resources\" when a ship construction is lock because of a resource outage\n\
\u2022show incoming threats in red in the travel list\n\
\u2022ensure long joystick names can be shown\n\
\u2022hide precise light ratio as it's not used for now\n\
\u2022make transport fee a lot more visible\n\
\u2022allow to set trade route quantity limit precisely\n\n\
Graphics\n\
\u2022reduce sun intensity\n\
\u2022minor change on dust effects\n\n\
Balance\n\
\u2022allow shipyard owners to be in dept to build ships order by others companies\n\n\
Bugs\n\
\u2022contract : fix combat tutorial\n\
\u2022ui : fix menu looping bug\n\
\u2022ui : fix multiple typo in contracts\n\
\u2022ui : fix highlight box not updated in HUD\n\
\u2022graphics : fix Nema rings LOD\n\
\u2022economy : fix crash when canceling ship construction\n\
\u2022general : fix bad file name Windows firewall\n\n\
Beta - 290517\n\
Gameplay\n\
\u2022never destroy a ship completely because of a collision\n\
\u2022allow control of ship rotation in addition to ship translation from the external camera(space bar by default)\n\
\u2022make large ships unafraid of hostile small ships to avoid destabilizing turrets\n\n\
Contracts\n\
\u2022add lots of VIP names and avoid reusing the same names for multiple contracts\n\
\u2022add a 30 days delay in the Pendulum contract after the pirate step\n\
\u2022improve wording in contract tutorial\n\n\
Tutorials\n\
\u2022add combat tutorial\n\
\u2022add ships repair tutorial\n\
\u2022add ships refilling tutorial\n\n\
UI\n\
\u2022aggregate all secondary contract notifications in one\n\
\u2022hide expiration conditions : they were misleading and taken as failed conditions\n\
\u2022show more details about ship state in ship lists\n\
\u2022don't notify pointless \"battle lost\" notification, and don't lock fast forward in these cases\n\
\u2022give detailed infos about abandoned ships when traveling\n\
\u2022treat ships in paused trade route as regular ships\n\
\u2022show trade routes status everywhere\n\
\u2022forbid abandon of tutorial and story contracts\n\n\
Graphics\n\
\u2022change the look of pumping stations, research stations and outposts to differentiate them\n\
\u2022improve dust effects\n\
\u2022improve firing effects\n\
\u2022improve visualization of damage on destroyed ship parts\n\
\u2022move Orca camera\n\
\u2022add very small chromatic aberration\n\
\u2022fix planetary texture LOD\n\n\
Balance\n\
\u2022technology : increase research point reward by 60 %\n\
\u2022diplomacy : divide rank based reputation loose by 30\n\
\u2022military : divide large ship reparation speed by 5\n\
\u2022military : slightly improve Artemis\n\n\
Bugs\n\
\u2022ui : fix trade quantity when the company has debt\n\
\u2022ui : fix line wrapping bug in trade menu\n\
\u2022ui : fix \"No objects\" misleading in sector menu\n\
\u2022combat : fix AI ship and turret pilot aim precision\n\
\u2022combat : fix Kami turret angles and collision mesh\n\
\u2022combat : fix collision issue in The Spire\n\
\u2022general : fix AA quality settings not modifiable\n\
\u2022general : fix sector defense contract not loaded correctly\n\
\u2022general : fix crash if a station collide something different from a ship\n\n\
Beta - 220517\n\
Gameplay\n\
\u2022revamp diplomacy system\n\n\
Contracts\n\
\u2022add Pendulum history contract\n\n\
Tutorials\n\
\u2022add technology and research station tutorial\n\
\u2022add buy ship tutorial\n\
\u2022add station construction and upgrade tutorial\n\
\u2022add targeting tutorial\n\n\
UI\n\
\u2022allow T key to select the contract objectif if not in battle\n\
\u2022show contract fail conditions in contracts menu\n\
\u2022add needs columns in ecomomy menu\n\
\u2022show sector population\n\n\
Graphics\n\
\u2022redesign boneyard sector\n\
\u2022better metal, exhaust and bloom effects\n\n\
Balance\n\
\u2022economy : increase the \"nerf ratio\" but apply it only to level 1 cargo bay size of station\n\
\u2022economy : increase arsenal production\n\
\u2022economy : increase plastic factory production\n\
\u2022economy : increase station cargo bay size\n\
\u2022economy : balance Kami ship cost\n\
\u2022economy : limit high end consumer resource consumption if they are expensive\n\
\u2022contracts : generate hunt contract only on travel end\n\
\u2022contracts : add duration fail condition for VIP contracts\n\
\u2022technology : move shipyard construction unlock in a specific technology\n\
\u2022technology : now, only one technology is need to increase its technology level(2 before)\n\
\u2022technology : reduce research point production cost\n\
\u2022world : a lot of balance in the game creation setup\n\n\
Bugs\n\
\u2022flying : fix station bad placement if they are capture before being in an active sector\n\
\u2022flying : fix ship disappearing randomly if stopped\n\
\u2022flying : fix weapon firing empty weapon first on load game\n\
\u2022economy : fix fleet supply consumption bug\n\
\u2022economy : fix shipyard consumption estimation\n\
\u2022contract : fix missing diplomatic fail and expiration conditions in generated quests\n\
\u2022ui : fix trading permission display\n\
\u2022ui : fix external and menu camera control\n\
\u2022ui : station list order in sector menu\n\
\u2022ai : fix a lot of AI bug\n\
\u2022general : various performance improvements"))
]
]
]
]
]
]
]
+ SFlareTabView::Slot()
.Header(LOCTEXT("ModdingTab", "Modding"))
.HeaderHelp(LOCTEXT("ModdingTabInfo", "Help for modding Helium Rain"))
[
SNew(SBox)
.WidthOverride(2.2 * Theme.ContentWidth)
.HAlign(HAlign_Left)
.VAlign(VAlign_Fill)
[
SNew(SHorizontalBox)
// Info block
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
.AutoWidth()
[
// Data
SNew(SVerticalBox)
+SVerticalBox::Slot()
.AutoHeight()
.Padding(Theme.ContentPadding)
[
SNew(SScrollBox)
.Style(&Theme.ScrollBoxStyle)
.ScrollBarStyle(&Theme.ScrollBarStyle)
+ SScrollBox::Slot()
.Padding(Theme.ContentPadding)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.Padding(Theme.ContentPadding)
.AutoWidth()
.HAlign(HAlign_Left)
.VAlign(VAlign_Top)
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("ModToolsOverviewHelp", "Modding Helium Rain - overview"))
.TextStyle(&Theme.SubTitleFont)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("ModToolsOverviewMain", "\
Modding support in Helium Rain can enable new ships, stations, resources, sectors, or ship upgrades. They cannot add new quests, story, or new C++ functionality - if you want to modify the game sources, please follow the instructions on our public Git repository, found at https://github.com/arbonagw/HeliumRain. Source mods can't be distributed through Steamworks, and by design, a source code mod would behave as an entirely separate game - two source mods can't be combined.\n\n\
Creating mods will require the Helium Rain Mod Kit, available through the Epic Games Launcher for free. No other software is required. The Helium Rain Mod Kit doesn't provide all game assets, though about half of them are provided for reference. Helium Rain mods can then be distributed through Steamworks and applied automatically to users, but developers can make them available elsewhere to be applied manually on GOG & itch.io releases."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("SourcesCreating", "\nCreating a mod"))
.TextStyle(&Theme.SubTitleFont)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("SourcesCreatingMain", "\
To start the modding process, you will need to download the Epic Games Launcher, register, and find the Helium Rain Mod Kit at the bottom of the Store tab. Install it and make sure to remember where the mod kit is installed on your computer, as you will be working from there to set it up. Once installed, the modding SDK should have a few folders - one named \"UE_4.20\", which is the engine, and one named \"HeliumRainModKit\" - everything will happen in that second folder.\n\n\
Modding will work by creating a plugin for the game. We'll create a mod named ExampleMod for reference - make sure to always use the same name everywhere, without spaces or special characters. This mod should already exist - make sure to adapt this tutorial to your own mod, or try first with the example.\n\
A plugin has to be created in the /HeliumRainModKit/Mods folder of the SDK, and has three mandatory components : \n\n\
\u2022A plugin file, ExampleMod.uplugin, created manually\n\
\u2022A preview image for Steamworks, Preview.png, created manually\n\
\u2022A content directory, that will be created through the editor\n\n\
The syntax of the plugin file is quite easy. Here is an example.\n\n\
{\n\
\"FileVersion\" : 3,\n\
\"FriendlyName\" : \"Example Mod\",\n\
\"Version\" : 1,\n\
\"VersionName\" : \"1.0\",\n\
\"CreatedBy\" : \"Deimos Games\",\n\
\"CreatedByURL\" : \"http://helium-rain.com\",\n\
\"EngineVersion\" : \"4.20.0\",\n\
\"Description\" : \"Example mod for the Helium Rain Mod Kit\",\n\
\"Category\" : \"User Mod\",\n\
\"EnabledByDefault\" : true,\n\
\"Modules\" :\n\
[\n\
],\n\
\"CanContainContent\" : true\n\
}\n\n\
Once this is done, you can launch the Unreal Engine editor right away. You don't need to decide on a great description or a kick-ass preview - you can edit both later and update the mod on Steam."))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("SourcesContentHelp", "\nCreating content"))
.TextStyle(&Theme.SubTitleFont)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("SourcesContentHelpMain", "\
This part assumes you are familiar with Unreal Engine 4. We won't provide our own guide, or detailed guides on how the game assets are structured.\n\
You will work a lot with the Content Browser window. Make sure a folder list panel is visible on the left side of that window - toggle it with the small button below \"Add New\" on the top left. Your mod folder should appear at this point, this is where you will work from ! You can only add content here - changes elsewhere will not be applied. You can't remove existing content or update a material - you can however copy a material to the mod folder, change it, and use it for your content.\n\
Here are some details on Helium Rain's architecture.\n\n\
\u2022All of our gameplay data is created through what we call DataAssets. You can find many of them in the /Gameplay/Catalog folder of the Content Browser as examples - look at how they're built, and learn from that.\n\
\u2022Ships or stations have an additional Templatefile, built with UE4's Blueprint tool. Templates let us actually design the ship and place parts. These are found in /Ships/Templates and /Stations/Templates, and are referenced from the DataAssets.\n\
\u2022A new ship would require both a new data asset and a new template.A modified ship could only use a new data asset, and keep the base template.\n\
\u2022A new weapon or engine would require a data asset and a StaticMesh.\n\
\u2022New sectors only require a data asset, but can also feature an entire new level, if you add a sub - level to the Space map, and provide its name in the data asset.\n\n\
Talk with other modders on the Steam forums, or our Reddit forum, to get answers ! The source code for the game is also available if you've got questions. "))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("SourcesBuildingHelp", "\nBuilding a mod"))
.TextStyle(&Theme.SubTitleFont)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("SourcesBuildingMain", "\
To build a mod, you will need to open the Project Launcher window in Unreal Engine. Add a new profile using the small \"plus\" sign on the bottom right, or use the provided \"Mod\" profile.\n\
We will create a profile that \"cooks\" a \"Shipping\" \"DLC\", using a \"PAK file\" with compression, based on a previous release of the game. Let's explain all of this.\n\n\
\u2022Cooking is the process to create a usable mod file for a packaged game. This file will be a .pak file, a compressed archive of your mod.\n\
\u2022Make sure you pick the \"HeliumRain\" project by browsing for the HeliumRainModKit / HeliumRain.uproject file.\n\
\u2022Make sure to set how you would like to cook to \"By the book\"\n\
\u2022We will cook for WindowsNoEditor, and LinuxNoEditor. Please cook for the \"en\" culture.\n\
\u2022What is called DLC here is your mod - use the name of your own mod.\n\
\u2022The release is the name of the folder inside / Releases / -currently \"1.3.4-modkit\".\n\
\u2022Make sure Build DLC and Include Engine Content is enabled\n\
\u2022\"Compress Content\", \"Save packages without versions\", \"Store all content in a single file (UnrealPak)\" and \"Don't include editor content in build\" should be selected"))
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(LOCTEXT("SourcesUploadingHelp", "\nUploading a mod"))
.TextStyle(&Theme.SubTitleFont)
]
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.TextStyle(&Theme.TextFont)
.WrapTextAt(TextWrappingBig)
.Text(LOCTEXT("SourcesUploadingHelpMain", "\
This is the easy part. Open a console command (cmd), go to the mod kit folder (\"cd / D \"C:\\...\\HeliumRainModKit\\\"), and run the following command : \n\n\
\u2022Boiler --game HeliumRain --mod ExampleMod\n\n\
Your mod will be uploaded as a hidden new project on the Steamworks page for Helium Rain. Look for a menu near your user name to find your uploaded mods, complete the settings, and make it visible. Players can now subscribe to the mod, enabling them next time the game runs. Enabled mods are listed on the bottom of the main menu."))
]
]
]
]
]
]
]
]
];
// Init arrays
StationList.Empty();
ShipList.Empty();
CompanyListData.Empty();
CompanyList->RequestListRefresh();
EngineListData.Empty();
EngineList->RequestListRefresh();
RCSListData.Empty();
RCSList->RequestListRefresh();
WeaponListData.Empty();
WeaponList->RequestListRefresh();
}
/*----------------------------------------------------
Interaction
----------------------------------------------------*/
void SFlareHelpMenu::Setup()
{
SetEnabled(false);
SetVisibility(EVisibility::Collapsed);
}
void SFlareHelpMenu::Enter()
{
FLOG("SFlareHelpMenu::Enter");
SetEnabled(true);
SetVisibility(EVisibility::Visible);
const FFlareStyleCatalog& Theme = FFlareStyleSet::GetDefaultTheme();
UFlareSpacecraftComponentsCatalog* Catalog = MenuManager->GetGame()->GetShipPartsCatalog();
UFlareSpacecraftCatalog* SpacecraftCatalog = MenuManager->GetGame()->GetSpacecraftCatalog();
UFlareCompanyCatalog* CompanyCatalog = MenuManager->GetGame()->GetCompanyCatalog();
if (!StationList.Num())
{
for (int SpacecraftIndex = 0; SpacecraftIndex < SpacecraftCatalog->StationCatalog.Num(); SpacecraftIndex++)
{
// Candidate have to be not a substation and available in tech
FFlareSpacecraftDescription* Description = &SpacecraftCatalog->StationCatalog[SpacecraftIndex]->Data;
if (!Description->IsSubstation)
{
UFlareSpacecraftCatalogEntry* Entry = SpacecraftCatalog->StationCatalog[SpacecraftIndex];
StationList.AddUnique(FInterfaceContainer::New(&Entry->Data));
}
}
}
if (!ShipList.Num())
{
for (int SpacecraftIndex = 0; SpacecraftIndex < SpacecraftCatalog->ShipCatalog.Num(); SpacecraftIndex++)
{
// Candidate have to be not a substation and available in tech
UFlareSpacecraftCatalogEntry* Entry = SpacecraftCatalog->ShipCatalog[SpacecraftIndex];
ShipList.AddUnique(FInterfaceContainer::New(&Entry->Data));
}
}
if (!CompanyListData.Num())
{
/*
for (int CompanyIndex = 0; CompanyIndex < CompanyCatalog->Companies.Num(); CompanyIndex++)
{
FFlareCompanyDescription* Entry = CompanyCatalog->Companies[CompanyIndex];
CompanyList.AddUnique(FInterfaceContainer::New(Entry));
}
*/
TArray<FFlareCompanyDescription*> CompanyWorkingList;
MenuManager->GetGame()->GetCompanyCatalog()->GetCompanyList(CompanyWorkingList);
for (FFlareCompanyDescription* Company : CompanyWorkingList)
{
CompanyListData.AddUnique(FInterfaceContainer::New(Company));
}
CompanyList->RequestListRefresh();
}
if (!EngineListData.Num())
{
TArray<FFlareSpacecraftComponentDescription*> PartList;
// Engines
PartList.Empty();
Catalog->GetEngineList(PartList, EFlarePartSize::S, NULL, NULL);
Catalog->GetEngineList(PartList, EFlarePartSize::L, NULL, NULL);
for (FFlareSpacecraftComponentDescription* Part : PartList)
{
EngineListData.AddUnique(FInterfaceContainer::New(Part));
}
EngineList->RequestListRefresh();
}
if (!RCSListData.Num())
{
TArray<FFlareSpacecraftComponentDescription*> PartList;
// Engines
PartList.Empty();
Catalog->GetRCSList(PartList, EFlarePartSize::S, NULL, NULL);
Catalog->GetRCSList(PartList, EFlarePartSize::L, NULL, NULL);
for (FFlareSpacecraftComponentDescription* Part : PartList)
{
RCSListData.AddUnique(FInterfaceContainer::New(Part));
}
RCSList->RequestListRefresh();
}
if (!WeaponListData.Num())
{
TArray<FFlareSpacecraftComponentDescription*> PartList;
// Engines
PartList.Empty();
Catalog->GetWeaponList(PartList, EFlarePartSize::S, NULL, NULL);
Catalog->GetWeaponList(PartList, EFlarePartSize::L, NULL, NULL);
for (FFlareSpacecraftComponentDescription* Part : PartList)
{
WeaponListData.AddUnique(FInterfaceContainer::New(Part));
}
WeaponList->RequestListRefresh();
}
}
TSharedRef<ITableRow> SFlareHelpMenu::OnGenerateSpacecraftLine(TSharedPtr<FInterfaceContainer> Item, const TSharedRef<STableViewBase>& OwnerTable, bool OrderIsShipValue)
{
const FFlareStyleCatalog& Theme = FFlareStyleSet::GetDefaultTheme();
FFlareSpacecraftDescription* Desc = Item->SpacecraftDescriptionPtr;
uint32 Width = 32;
// Structure
return SNew(SFlareListItem, OwnerTable)
.Width(Width)
.Height(2)
.Content()
[
SNew(SFlareSpaceCraftOverlayInfo)
.MenuManager(MenuManager)
.Desc(Desc)
.VerboseInformation(true)
.OrderIsShip(OrderIsShipValue)
.TargetShipyard(NULL)
.TargetSkirmish(NULL)
.TargetSector(NULL)
];
}
TSharedRef<ITableRow> SFlareHelpMenu::OnGenerateCompanyLine(TSharedPtr<FInterfaceContainer> Item, const TSharedRef<STableViewBase>& OwnerTable)
{
const FFlareStyleCatalog& Theme = FFlareStyleSet::GetDefaultTheme();
FFlareCompanyDescription* Desc = Item->CompanyDescriptionPtr;
uint32 Width = 32;
// Structure
return SNew(SFlareListItem, OwnerTable)
.Width(Width)
.Height(2)
.Content()
[
SNew(SFlareCompanyHelpInfo)
.CompanyDescription(Desc)
.MenuManager(MenuManager)
];
}
TSharedRef<ITableRow> SFlareHelpMenu::GeneratePartInfo(TSharedPtr<FInterfaceContainer> Item, const TSharedRef<STableViewBase>& OwnerTable, int32 Width)
{
TSharedPtr<SFlarePartInfo> Temp;
TSharedPtr<SFlareListItem> TempWidget;
// Create the row
TSharedRef<ITableRow> res = SAssignNew(TempWidget, SFlareListItem, OwnerTable)
.Width(Width)
.Height(2)
.Content()
[
SAssignNew(Temp, SFlarePartInfo)
.Description(Item->PartDescription)
.Verbose(true)
.ShowOwnershipInfo(true)
];
return res;
}
void SFlareHelpMenu::Exit()
{
SetEnabled(false);
SetVisibility(EVisibility::Collapsed);
//garbage collector doesn't like reusing the company list. garbage collector likes to have its way with it.
// CompanyListData.Empty();
// CompanyList->RequestListRefresh();
}
/*----------------------------------------------------
Callbacks
----------------------------------------------------*/
#undef LOCTEXT_NAMESPACE | 41.101028 | 959 | 0.671382 | [
"mesh",
"render",
"object",
"model"
] |
08809bdb856c23b2c9bcc5315ca4affcbd26ff18 | 1,774 | cc | C++ | lib/sk/rt/unix/macosx/ProcessInfo.cc | stemkit-collection/stemkit-cpp | dfa77d831f49916ba6d134f407a4dcd0983328f6 | [
"MIT"
] | 4 | 2019-02-19T16:48:41.000Z | 2022-01-31T07:57:54.000Z | lib/sk/rt/unix/macosx/ProcessInfo.cc | stemkit-collection/stemkit-cpp | dfa77d831f49916ba6d134f407a4dcd0983328f6 | [
"MIT"
] | 1 | 2019-01-30T04:48:35.000Z | 2019-01-30T04:48:35.000Z | lib/sk/rt/unix/macosx/ProcessInfo.cc | stemkit-collection/stemkit-cpp | dfa77d831f49916ba6d134f407a4dcd0983328f6 | [
"MIT"
] | null | null | null | /* vim: set sw=2:
* Copyright (c) 2009, Gennady Bystritsky <bystr@mac.com>
*
* Distributed under the MIT Licence.
* This is free software. See 'LICENSE' for details.
* You must read and accept the license prior to use.
*
* Author: Gennady Bystritsky (gennady.bystritsky@quest.com)
*/
#include <sk/util/Holder.cxx>
#include <sk/rt/ProcessInfo.h>
#include <sk/util/IllegalStateException.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/task.h>
#include <mach/mach_init.h>
// The actual solution is borrowed from here:
// http://miknight.blogspot.com/2005/11/resident-set-size-in-mac-os-x.html
//
// Thanks to Michael Knight for posting it.
//
struct sk::rt::ProcessInfo::Data
: public virtual sk::util::Object
{
Data(pid_t pid) : _task(MACH_PORT_NULL) {
if (task_for_pid(current_task(), pid, &_task) != KERN_SUCCESS) {
throw sk::util::IllegalStateException("Mac OS X task");
}
}
const struct task_basic_info info() const
{
struct task_basic_info t_info;
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
task_info(_task, TASK_BASIC_INFO, task_info_t(&t_info), &t_info_count);
return t_info;
}
private:
task_t _task;
};
void
sk::rt::ProcessInfo::
init()
{
_dataHolder.set(new Data(_pid));
}
uint64_t
sk::rt::ProcessInfo::
virtualMemory(sk::rt::Lock& /*lock*/) const
{
return virtualMemory();
}
uint64_t
sk::rt::ProcessInfo::
virtualMemory() const
{
return _dataHolder.get().info().virtual_size;
}
uint64_t
sk::rt::ProcessInfo::
residentMemory(sk::rt::Lock& /*lock*/) const
{
return residentMemory();
}
uint64_t
sk::rt::ProcessInfo::
residentMemory() const
{
return _dataHolder.get().info().resident_size;
}
| 21.119048 | 76 | 0.701804 | [
"object"
] |
088634af11837552eedfc61e8722eba17aeb0308 | 27,243 | cc | C++ | src/ray/common/test/ray_syncer_test.cc | andenrx/ray | 0ad4113e22aa4ec40f87d4a16e474a452f9c8af7 | [
"Apache-2.0"
] | null | null | null | src/ray/common/test/ray_syncer_test.cc | andenrx/ray | 0ad4113e22aa4ec40f87d4a16e474a452f9c8af7 | [
"Apache-2.0"
] | null | null | null | src/ray/common/test/ray_syncer_test.cc | andenrx/ray | 0ad4113e22aa4ec40f87d4a16e474a452f9c8af7 | [
"Apache-2.0"
] | null | null | null | // Copyright 2022 The Ray Authors.
//
// 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.
// clang-format off
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <chrono>
#include <sstream>
#include <grpc/grpc.h>
#include <grpcpp/create_channel.h>
#include <google/protobuf/util/message_differencer.h>
#include <google/protobuf/util/json_util.h>
#include <grpcpp/security/credentials.h>
#include <grpcpp/security/server_credentials.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include "ray/common/ray_syncer/ray_syncer.h"
#include "mock/ray/common/ray_syncer/ray_syncer.h"
// clang-format on
using namespace std::chrono;
using namespace ray::syncer;
using ray::NodeID;
using ::testing::_;
using ::testing::Eq;
using ::testing::Invoke;
using ::testing::Return;
using ::testing::WithArg;
namespace ray {
namespace syncer {
RaySyncMessage MakeMessage(RayComponentId cid, int64_t version, const NodeID &id) {
auto msg = RaySyncMessage();
msg.set_version(version);
msg.set_component_id(cid);
msg.set_node_id(id.Binary());
return msg;
}
class RaySyncerTest : public ::testing::Test {
protected:
void SetUp() override {
local_versions_.fill(0);
for (size_t cid = 0; cid < reporters_.size(); ++cid) {
receivers_[cid] = std::make_unique<MockReceiverInterface>();
auto &reporter = reporters_[cid];
reporter = std::make_unique<MockReporterInterface>();
auto take_snapshot =
[this, cid](int64_t curr_version) mutable -> std::optional<RaySyncMessage> {
if (curr_version >= local_versions_[cid]) {
return std::nullopt;
} else {
auto msg = RaySyncMessage();
msg.set_component_id(static_cast<RayComponentId>(cid));
msg.set_version(++local_versions_[cid]);
return std::make_optional(std::move(msg));
}
};
ON_CALL(*reporter, Snapshot(_, _)).WillByDefault(WithArg<0>(Invoke(take_snapshot)));
}
thread_ = std::make_unique<std::thread>([this]() {
boost::asio::io_context::work work(io_context_);
io_context_.run();
});
local_id_ = NodeID::FromRandom();
syncer_ = std::make_unique<RaySyncer>(io_context_, local_id_.Binary());
}
MockReporterInterface *GetReporter(RayComponentId cid) {
return reporters_[static_cast<size_t>(cid)].get();
}
MockReceiverInterface *GetReceiver(RayComponentId cid) {
return receivers_[static_cast<size_t>(cid)].get();
}
int64_t &LocalVersion(RayComponentId cid) {
return local_versions_[static_cast<size_t>(cid)];
}
void TearDown() override {
io_context_.stop();
thread_->join();
}
std::array<int64_t, kComponentArraySize> local_versions_;
std::array<std::unique_ptr<MockReporterInterface>, kComponentArraySize> reporters_ = {
nullptr};
std::array<std::unique_ptr<MockReceiverInterface>, kComponentArraySize> receivers_ = {
nullptr};
instrumented_io_context io_context_;
std::unique_ptr<std::thread> thread_;
std::unique_ptr<RaySyncer> syncer_;
NodeID local_id_;
};
TEST_F(RaySyncerTest, NodeStateGetSnapshot) {
auto node_status = std::make_unique<NodeState>();
node_status->SetComponent(RayComponentId::RESOURCE_MANAGER, nullptr, nullptr);
ASSERT_EQ(std::nullopt, node_status->GetSnapshot(RayComponentId::RESOURCE_MANAGER));
ASSERT_EQ(std::nullopt, node_status->GetSnapshot(RayComponentId::SCHEDULER));
auto reporter = std::make_unique<MockReporterInterface>();
ASSERT_TRUE(node_status->SetComponent(RayComponentId::RESOURCE_MANAGER,
GetReporter(RayComponentId::RESOURCE_MANAGER),
nullptr));
// Take a snapshot
ASSERT_EQ(std::nullopt, node_status->GetSnapshot(RayComponentId::SCHEDULER));
auto msg = node_status->GetSnapshot(RayComponentId::RESOURCE_MANAGER);
ASSERT_EQ(LocalVersion(RayComponentId::RESOURCE_MANAGER), msg->version());
// Revert one version back.
LocalVersion(RayComponentId::RESOURCE_MANAGER) -= 1;
msg = node_status->GetSnapshot(RayComponentId::RESOURCE_MANAGER);
ASSERT_EQ(std::nullopt, msg);
}
TEST_F(RaySyncerTest, NodeStateConsume) {
auto node_status = std::make_unique<NodeState>();
node_status->SetComponent(RayComponentId::RESOURCE_MANAGER,
nullptr,
GetReceiver(RayComponentId::RESOURCE_MANAGER));
auto from_node_id = NodeID::FromRandom();
// The first time receiver the message
auto msg = MakeMessage(RayComponentId::RESOURCE_MANAGER, 0, from_node_id);
ASSERT_TRUE(node_status->ConsumeMessage(std::make_shared<RaySyncMessage>(msg)));
ASSERT_FALSE(node_status->ConsumeMessage(std::make_shared<RaySyncMessage>(msg)));
msg.set_version(1);
ASSERT_TRUE(node_status->ConsumeMessage(std::make_shared<RaySyncMessage>(msg)));
ASSERT_FALSE(node_status->ConsumeMessage(std::make_shared<RaySyncMessage>(msg)));
}
TEST_F(RaySyncerTest, NodeSyncConnection) {
auto node_id = NodeID::FromRandom();
MockNodeSyncConnection sync_connection(
io_context_,
node_id.Binary(),
[](std::shared_ptr<ray::rpc::syncer::RaySyncMessage>) {});
auto from_node_id = NodeID::FromRandom();
auto msg = MakeMessage(RayComponentId::RESOURCE_MANAGER, 0, from_node_id);
// First push will succeed and the second one will be deduplicated.
ASSERT_TRUE(sync_connection.PushToSendingQueue(std::make_shared<RaySyncMessage>(msg)));
ASSERT_FALSE(sync_connection.PushToSendingQueue(std::make_shared<RaySyncMessage>(msg)));
ASSERT_EQ(1, sync_connection.sending_buffer_.size());
ASSERT_EQ(0, sync_connection.sending_buffer_.begin()->second->version());
ASSERT_EQ(1, sync_connection.node_versions_.size());
ASSERT_EQ(0,
sync_connection
.node_versions_[from_node_id.Binary()][RayComponentId::RESOURCE_MANAGER]);
msg.set_version(2);
ASSERT_TRUE(sync_connection.PushToSendingQueue(std::make_shared<RaySyncMessage>(msg)));
ASSERT_FALSE(sync_connection.PushToSendingQueue(std::make_shared<RaySyncMessage>(msg)));
// The previous message is deleted.
ASSERT_EQ(1, sync_connection.sending_buffer_.size());
ASSERT_EQ(1, sync_connection.node_versions_.size());
ASSERT_EQ(2, sync_connection.sending_buffer_.begin()->second->version());
ASSERT_EQ(2,
sync_connection
.node_versions_[from_node_id.Binary()][RayComponentId::RESOURCE_MANAGER]);
}
struct SyncerServerTest {
SyncerServerTest(std::string port, bool has_scheduler_reporter = true) {
this->server_port = port;
bool has_scheduler_receiver = !has_scheduler_reporter;
// Setup io context
auto node_id = NodeID::FromRandom();
for (auto &v : local_versions) {
v = 0;
}
// Setup syncer and grpc server
syncer = std::make_unique<RaySyncer>(io_context, node_id.Binary());
auto server_address = std::string("0.0.0.0:") + port;
grpc::ServerBuilder builder;
service = std::make_unique<RaySyncerService>(*syncer);
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
builder.RegisterService(service.get());
server = builder.BuildAndStart();
for (size_t cid = 0; cid < reporters.size(); ++cid) {
auto snapshot_received = [this](std::shared_ptr<const RaySyncMessage> message) {
auto iter = received_versions.find(message->node_id());
if (iter == received_versions.end()) {
for (auto &v : received_versions[message->node_id()]) {
v = 0;
}
iter = received_versions.find(message->node_id());
}
received_versions[message->node_id()][message->component_id()] =
message->version();
message_consumed[message->node_id()]++;
};
if (has_scheduler_receiver ||
static_cast<RayComponentId>(cid) != RayComponentId::SCHEDULER) {
receivers[cid] = std::make_unique<MockReceiverInterface>();
EXPECT_CALL(*receivers[cid], Update(_))
.WillRepeatedly(WithArg<0>(Invoke(snapshot_received)));
}
auto &reporter = reporters[cid];
auto take_snapshot =
[this, cid](int64_t version_after) mutable -> std::optional<RaySyncMessage> {
if (local_versions[cid] <= version_after) {
return std::nullopt;
} else {
auto msg = RaySyncMessage();
msg.set_component_id(static_cast<RayComponentId>(cid));
msg.set_version(local_versions[cid]);
msg.set_node_id(syncer->GetLocalNodeID());
snapshot_taken++;
return std::make_optional(std::move(msg));
}
};
if (has_scheduler_reporter ||
static_cast<RayComponentId>(cid) != RayComponentId::SCHEDULER) {
reporter = std::make_unique<MockReporterInterface>();
EXPECT_CALL(*reporter, Snapshot(_, Eq(cid)))
.WillRepeatedly(WithArg<0>(Invoke(take_snapshot)));
}
syncer->Register(static_cast<RayComponentId>(cid),
reporter.get(),
receivers[cid].get(),
static_cast<RayComponentId>(cid) == RayComponentId::SCHEDULER);
}
thread = std::make_unique<std::thread>([this] {
boost::asio::io_context::work work(io_context);
io_context.run();
});
}
void WaitSendingFlush() {
while (true) {
std::promise<bool> p;
auto f = p.get_future();
io_context.post(
[&p, this]() mutable {
for (const auto &[node_id, conn] : syncer->sync_connections_) {
if (!conn->sending_buffer_.empty()) {
p.set_value(false);
RAY_LOG(INFO) << NodeID::FromBinary(syncer->GetLocalNodeID()) << ": "
<< "Waiting for message on " << NodeID::FromBinary(node_id)
<< " to be sent."
<< " Remainings " << conn->sending_buffer_.size();
return;
}
}
p.set_value(true);
},
"TEST");
if (f.get()) {
return;
} else {
std::this_thread::sleep_for(1s);
}
}
}
bool WaitUntil(std::function<bool()> predicate, int64_t time_s) {
auto start = steady_clock::now();
while (duration_cast<seconds>(steady_clock::now() - start).count() <= time_s) {
std::promise<bool> p;
auto f = p.get_future();
io_context.post([&p, predicate]() mutable { p.set_value(predicate()); }, "TEST");
if (f.get()) {
return true;
} else {
std::this_thread::sleep_for(1s);
}
}
return false;
}
~SyncerServerTest() {
service.reset();
server.reset();
io_context.stop();
thread->join();
syncer.reset();
}
int64_t GetNumConsumedMessages(const std::string &node_id) const {
auto iter = message_consumed.find(node_id);
if (iter == message_consumed.end()) {
return 0;
} else {
return iter->second;
}
}
std::array<std::atomic<int64_t>, kComponentArraySize> _v;
const std::array<std::atomic<int64_t>, kComponentArraySize> &GetReceivedVersions(
const std::string &node_id) {
auto iter = received_versions.find(node_id);
if (iter == received_versions.end()) {
for (auto &v : _v) {
v.store(-1);
}
return _v;
}
return iter->second;
}
std::unique_ptr<RaySyncerService> service;
std::unique_ptr<RaySyncer> syncer;
std::unique_ptr<grpc::Server> server;
std::unique_ptr<std::thread> thread;
instrumented_io_context io_context;
std::string server_port;
std::array<std::atomic<int64_t>, kComponentArraySize> local_versions;
std::array<std::unique_ptr<MockReporterInterface>, kComponentArraySize> reporters = {
nullptr};
int64_t snapshot_taken = 0;
std::unordered_map<std::string, std::array<std::atomic<int64_t>, kComponentArraySize>>
received_versions;
std::unordered_map<std::string, std::atomic<int64_t>> message_consumed;
std::array<std::unique_ptr<MockReceiverInterface>, kComponentArraySize> receivers = {
nullptr};
};
// Useful for debugging
// std::ostream &operator<<(std::ostream &os, const SyncerServerTest &server) {
// auto dump_array = [&os](const std::array<int64_t, kComponentArraySize> &v,
// std::string label,
// int indent) mutable -> std::ostream & {
// os << std::string('\t', indent);
// os << label << ": ";
// for (size_t i = 0; i < v.size(); ++i) {
// os << v[i];
// if (i + 1 != v.size()) {
// os << ", ";
// }
// }
// return os;
// };
// os << "NodeID: " << NodeID::FromBinary(server.syncer->GetLocalNodeID()) << std::endl;
// dump_array(server.local_versions, "LocalVersions:", 1) << std::endl;
// for (auto [node_id, versions] : server.received_versions) {
// os << "\tFromNodeID: " << NodeID::FromBinary(node_id) << std::endl;
// dump_array(versions, "RemoteVersions:", 2) << std::endl;
// }
// return os;
// }
std::shared_ptr<grpc::Channel> MakeChannel(std::string port) {
grpc::ChannelArguments argument;
// Disable http proxy since it disrupts local connections. TODO(ekl) we should make
// this configurable, or selectively set it for known local connections only.
argument.SetInt(GRPC_ARG_ENABLE_HTTP_PROXY, 0);
argument.SetMaxSendMessageSize(::RayConfig::instance().max_grpc_message_size());
argument.SetMaxReceiveMessageSize(::RayConfig::instance().max_grpc_message_size());
return grpc::CreateCustomChannel(
"localhost:" + port, grpc::InsecureChannelCredentials(), argument);
}
using TClusterView = absl::flat_hash_map<
std::string,
std::array<std::shared_ptr<const RaySyncMessage>, kComponentArraySize>>;
TEST(SyncerTest, Test1To1) {
// s1: reporter: RayComponentId::RESOURCE_MANAGER
// s1: receiver: RayComponentId::SCHEDULER, RayComponentId::RESOURCE_MANAGER
auto s1 = SyncerServerTest("19990", false);
// s2: reporter: RayComponentId::RESOURCE_MANAGER, RayComponentId::SCHEDULER
// s2: receiver: RayComponentId::RESOURCE_MANAGER
auto s2 = SyncerServerTest("19991", true);
// Make sure the setup is correct
ASSERT_NE(nullptr, s1.receivers[RayComponentId::SCHEDULER]);
ASSERT_EQ(nullptr, s2.receivers[RayComponentId::SCHEDULER]);
ASSERT_EQ(nullptr, s1.reporters[RayComponentId::SCHEDULER]);
ASSERT_NE(nullptr, s2.reporters[RayComponentId::SCHEDULER]);
ASSERT_NE(nullptr, s1.receivers[RayComponentId::RESOURCE_MANAGER]);
ASSERT_NE(nullptr, s2.receivers[RayComponentId::RESOURCE_MANAGER]);
ASSERT_NE(nullptr, s1.reporters[RayComponentId::RESOURCE_MANAGER]);
ASSERT_NE(nullptr, s2.reporters[RayComponentId::RESOURCE_MANAGER]);
auto channel_to_s2 = MakeChannel("19991");
s1.syncer->Connect(channel_to_s2);
// Make sure s2 adds s1n
ASSERT_TRUE(s2.WaitUntil(
[&s2]() {
return s2.syncer->sync_connections_.size() == 1 && s2.snapshot_taken == 2;
},
5));
// Make sure s1 adds s2
ASSERT_TRUE(s1.WaitUntil(
[&s1]() {
return s1.syncer->sync_connections_.size() == 1 && s1.snapshot_taken == 1;
},
5));
// s1 will only send 1 message to s2 because it only has one reporter
ASSERT_TRUE(s2.WaitUntil(
[&s2, node_id = s1.syncer->GetLocalNodeID()]() {
return s2.GetNumConsumedMessages(node_id) == 1;
},
5));
// s2 will send 2 messages to s1 because it has two reporters.
ASSERT_TRUE(s1.WaitUntil(
[&s1, node_id = s2.syncer->GetLocalNodeID()]() {
return s1.GetNumConsumedMessages(node_id) == 2;
},
5));
// s2 local module version advance
s2.local_versions[0] = 1;
ASSERT_TRUE(s2.WaitUntil([&s2]() { return s2.snapshot_taken == 3; }, 2));
// Make sure s2 send the new message to s1.
ASSERT_TRUE(s1.WaitUntil(
[&s1, node_id = s2.syncer->GetLocalNodeID()]() {
return s1.GetReceivedVersions(node_id)[RayComponentId::RESOURCE_MANAGER] == 1 &&
s1.GetNumConsumedMessages(node_id) == 3;
},
5));
// Make sure no new messages are sent
s2.local_versions[0] = 0;
std::this_thread::sleep_for(1s);
ASSERT_TRUE(s1.GetNumConsumedMessages(s2.syncer->GetLocalNodeID()) == 3);
ASSERT_TRUE(s2.GetNumConsumedMessages(s1.syncer->GetLocalNodeID()) == 1);
// Change it back
s2.local_versions[0] = 1;
// Make some random messages
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> rand_sleep(0, 10000);
std::uniform_int_distribution<> choose_component(0, 1);
size_t s1_updated = 0;
size_t s2_updated = 0;
auto start = steady_clock::now();
for (int i = 0; i < 10000; ++i) {
if (choose_component(gen) == 0) {
s1.local_versions[0]++;
++s1_updated;
} else {
s2.local_versions[choose_component(gen)]++;
++s2_updated;
}
if (rand_sleep(gen) < 5) {
std::this_thread::sleep_for(1s);
}
}
auto end = steady_clock::now();
// Max messages can be send during this period of time.
// +1 is for corner cases.
auto max_sends =
duration_cast<milliseconds>(end - start).count() /
RayConfig::instance().raylet_report_resources_period_milliseconds() +
1;
ASSERT_TRUE(s1.WaitUntil(
[&s1, &s2]() {
return s1.GetReceivedVersions(s2.syncer->GetLocalNodeID()) == s2.local_versions &&
s2.GetReceivedVersions(s1.syncer->GetLocalNodeID())[0] ==
s1.local_versions[0];
},
5));
// s2 has two reporters + 3 for the ones send before the measure
ASSERT_LT(s1.GetNumConsumedMessages(s2.syncer->GetLocalNodeID()), max_sends * 2 + 3);
// s1 has one reporter + 1 for the one send before the measure
ASSERT_LT(s2.GetNumConsumedMessages(s1.syncer->GetLocalNodeID()), max_sends + 3);
}
TEST(SyncerTest, Broadcast) {
// This test covers the broadcast feature of ray syncer.
auto s1 = SyncerServerTest("19990", false);
auto s2 = SyncerServerTest("19991", true);
auto s3 = SyncerServerTest("19992", true);
// We need to make sure s1 is sending data to s3 for s2
s1.syncer->Connect(MakeChannel("19991"));
s1.syncer->Connect(MakeChannel("19992"));
// Make sure the setup is correct
ASSERT_TRUE(s1.WaitUntil(
[&s1]() {
return s1.syncer->sync_connections_.size() == 2 && s1.snapshot_taken == 1;
},
5));
ASSERT_TRUE(s1.WaitUntil(
[&s2]() {
return s2.syncer->sync_connections_.size() == 1 && s2.snapshot_taken == 2;
},
5));
ASSERT_TRUE(s1.WaitUntil(
[&s3]() {
return s3.syncer->sync_connections_.size() == 1 && s3.snapshot_taken == 2;
},
5));
// Change the resource in s2 and make sure s1 && s3 are correct
s2.local_versions[0] = 1;
s2.local_versions[1] = 1;
ASSERT_TRUE(s1.WaitUntil(
[&s1, node_id = s2.syncer->GetLocalNodeID()]() mutable {
return s1.received_versions[node_id][0] == 1 &&
s1.received_versions[node_id][1] == 1;
},
5));
ASSERT_TRUE(s1.WaitUntil(
[&s3, node_id = s2.syncer->GetLocalNodeID()]() mutable {
return s3.received_versions[node_id][0] == 1 &&
// Make sure SCHEDULE information is not sent to s3
s3.received_versions[node_id][1] == 0;
},
5));
}
bool CompareViews(const std::vector<std::unique_ptr<SyncerServerTest>> &servers,
const std::vector<TClusterView> &views,
const std::vector<std::set<size_t>> &g) {
// Check broadcasting is working
// component id = 0
// simply compare everything with server 0
for (size_t i = 1; i < views.size(); ++i) {
if (views[i].size() != views[0].size()) {
RAY_LOG(ERROR) << "View size wrong: (" << i << ") :" << views[i].size() << " vs "
<< views[0].size();
return false;
}
for (const auto &[k, v] : views[0]) {
auto iter = views[i].find(k);
if (iter == views[i].end()) {
return false;
}
const auto &vv = iter->second;
if (!google::protobuf::util::MessageDifferencer::Equals(*v[0], *vv[0])) {
RAY_LOG(ERROR) << i << ": FAIL RESOURCE: " << v[0] << ", " << vv[0] << ", "
<< v[1] << ", " << vv[1];
std::string dbg_message;
google::protobuf::util::MessageToJsonString(*v[0], &dbg_message);
RAY_LOG(ERROR) << "server[0] >> "
<< NodeID::FromBinary(servers[0]->syncer->GetLocalNodeID()) << ": "
<< dbg_message << " - " << NodeID::FromBinary(v[0]->node_id());
dbg_message.clear();
google::protobuf::util::MessageToJsonString(*vv[0], &dbg_message);
RAY_LOG(ERROR) << "server[i] << "
<< NodeID::FromBinary(servers[i]->syncer->GetLocalNodeID()) << ": "
<< dbg_message << " - " << NodeID::FromBinary(vv[0]->node_id());
return false;
}
}
}
std::map<std::string, size_t> node_id_to_idx;
for (size_t i = 0; i < servers.size(); ++i) {
node_id_to_idx[servers[i]->syncer->GetLocalNodeID()] = i;
}
// Check whether j is reachable from i
auto reachable = [&g](size_t i, size_t j) {
if (i == j) {
return true;
}
std::deque<size_t> q;
q.push_back(i);
while (!q.empty()) {
auto f = q.front();
q.pop_front();
for (auto m : g[f]) {
if (m == j) {
return true;
}
q.push_back(m);
}
}
return false;
};
// Check scheduler which is aggregating only
for (size_t i = 0; i < servers.size(); ++i) {
const auto &view = views[i];
// view: node_id -> msg
for (auto [node_id, msgs] : view) {
if (node_id_to_idx[node_id] == i) {
continue;
}
auto msg = msgs[1];
auto is_reachable = reachable(i, node_id_to_idx[node_id]);
if (msg == nullptr) {
if (is_reachable) {
RAY_LOG(ERROR) << i << " is null, but it can reach " << node_id_to_idx[node_id];
return false;
}
} else {
if (!is_reachable) {
RAY_LOG(ERROR) << i << " is not null, but it can't reachable "
<< node_id_to_idx[node_id];
return false;
}
auto iter = views[node_id_to_idx[node_id]].find(node_id);
if (iter == views[node_id_to_idx[node_id]].end()) {
return false;
}
auto msg2 = iter->second[1];
if (msg2 == nullptr) {
return false;
}
if (!google::protobuf::util::MessageDifferencer::Equals(*msg, *msg2)) {
std::string dbg_message;
google::protobuf::util::MessageToJsonString(*msg, &dbg_message);
RAY_LOG(ERROR) << "server[" << i << "] >> "
<< NodeID::FromBinary(servers[i]->syncer->GetLocalNodeID())
<< ": " << dbg_message;
dbg_message.clear();
google::protobuf::util::MessageToJsonString(*msg2, &dbg_message);
RAY_LOG(ERROR) << "server[" << node_id_to_idx[node_id] << "] << "
<< NodeID::FromBinary(servers[node_id_to_idx[node_id]]
->syncer->GetLocalNodeID())
<< ": " << dbg_message;
return false;
}
}
}
}
return true;
}
bool TestCorrectness(std::function<TClusterView(RaySyncer &syncer)> get_cluster_view,
std::vector<std::unique_ptr<SyncerServerTest>> &servers,
const std::vector<std::set<size_t>> &g) {
auto check = [&servers, get_cluster_view, &g]() {
std::vector<TClusterView> views;
for (auto &s : servers) {
views.push_back(get_cluster_view(*(s->syncer)));
}
return CompareViews(servers, views, g);
};
for (auto &server : servers) {
server->WaitSendingFlush();
}
for (size_t i = 0; i < 10; ++i) {
if (!check()) {
std::this_thread::sleep_for(1s);
} else {
break;
}
}
if (!check()) {
RAY_LOG(ERROR) << "Initial check failed";
return false;
}
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> rand_sleep(0, 1000000);
std::uniform_int_distribution<> choose_component(0, 1);
std::uniform_int_distribution<> choose_server(0, servers.size() - 1);
for (size_t i = 0; i < 1000000; ++i) {
auto server_idx = choose_server(gen);
auto component_id = choose_component(gen);
if (server_idx == 0) {
component_id = 0;
}
servers[server_idx]->local_versions[component_id]++;
// expect to sleep for 100 times for the whole loop.
if (rand_sleep(gen) < 100) {
std::this_thread::sleep_for(100ms);
}
}
for (auto &server : servers) {
server->WaitSendingFlush();
}
// Make sure everything is synced.
for (size_t i = 0; i < 10; ++i) {
if (!check()) {
std::this_thread::sleep_for(1s);
} else {
break;
}
}
return check();
}
TEST(SyncerTest, Test1ToN) {
size_t base_port = 18990;
std::vector<std::unique_ptr<SyncerServerTest>> servers;
for (int i = 0; i < 20; ++i) {
servers.push_back(
std::make_unique<SyncerServerTest>(std::to_string(i + base_port), i != 0));
}
std::vector<std::set<size_t>> g(servers.size());
for (size_t i = 1; i < servers.size(); ++i) {
servers[0]->syncer->Connect(MakeChannel(servers[i]->server_port));
g[0].insert(i);
}
auto get_cluster_view = [](RaySyncer &syncer) {
std::promise<TClusterView> p;
auto f = p.get_future();
syncer.GetIOContext().post(
[&p, &syncer]() mutable { p.set_value(syncer.node_state_->GetClusterView()); },
"TEST");
return f.get();
};
ASSERT_TRUE(TestCorrectness(get_cluster_view, servers, g));
}
TEST(SyncerTest, TestMToN) {
size_t base_port = 18990;
std::vector<std::unique_ptr<SyncerServerTest>> servers;
for (int i = 0; i < 20; ++i) {
servers.push_back(
std::make_unique<SyncerServerTest>(std::to_string(i + base_port), i != 0));
}
std::vector<std::set<size_t>> g(servers.size());
// Try to construct a tree based structure
size_t i = 1;
size_t curr = 0;
while (i < servers.size()) {
// try to connect to 2 servers per node.
for (int k = 0; k < 2 && i < servers.size(); ++k, ++i) {
servers[curr]->syncer->Connect(MakeChannel(servers[i]->server_port));
g[curr].insert(i);
}
++curr;
}
auto get_cluster_view = [](RaySyncer &syncer) {
std::promise<TClusterView> p;
auto f = p.get_future();
syncer.GetIOContext().post(
[&p, &syncer]() mutable { p.set_value(syncer.node_state_->GetClusterView()); },
"TEST");
return f.get();
};
ASSERT_TRUE(TestCorrectness(get_cluster_view, servers, g));
}
} // namespace syncer
} // namespace ray
| 35.01671 | 90 | 0.6304 | [
"vector"
] |
0889d697672ff4dd4caca172bc9aaee786862ab3 | 1,131 | cpp | C++ | lib/src/info.cpp | ih8celery/liboptparse | 60d323718eae934be2da42a5dbf6a64cb2353966 | [
"MIT"
] | 3 | 2018-06-20T14:57:19.000Z | 2018-09-27T11:41:01.000Z | lib/src/info.cpp | ih8celery/libcmdparse | 60d323718eae934be2da42a5dbf6a64cb2353966 | [
"MIT"
] | null | null | null | lib/src/info.cpp | ih8celery/libcmdparse | 60d323718eae934be2da42a5dbf6a64cb2353966 | [
"MIT"
] | null | null | null | /**
* \file info.cpp
*
* \author Adam Marshall (ih8celery)
*
* \brief parse command line arguments/options
*/
#include "info.h"
namespace cli {
std::optional<std::string> Info::find(const std::string& name) const {
opt_data_t::const_iterator iter = this->data.find(name);
if (iter == this->data.cend()) {
return std::nullopt;
}
return std::make_optional(iter->second);
}
std::optional<std::vector<std::string>> Info::find_all(const std::string& name) const {
const auto rng = data.equal_range(name);
std::vector<std::string> results;
for (auto start = rng.first; start != rng.second; start++) {
results.push_back(start->second);
}
if (results.empty()) {
return std::nullopt;
}
return std::make_optional(results);
}
opt_data_t::size_type Info::count(const std::string& name) const {
return data.count(name);
}
bool Info::has(const std::string& name) const {
return (data.find(name) != data.cend());
}
bool Info::has_command(const std::string& name) const {
return (this->commands.find(name) != this->commands.cend());
}
}
| 23.5625 | 89 | 0.635721 | [
"vector"
] |
088a70da93268c3d52ecefcb5c654a17a5abe2d1 | 4,551 | cc | C++ | cartographer/cartographer/mapping/internal/constraints/constraint_builder_2d_test.cc | adayimaxiga/cartographer_migrate_to_ros2 | db5a76357a2c9412bde32bd4382757565ce5665c | [
"Apache-2.0"
] | 35 | 2018-08-02T02:38:20.000Z | 2022-03-21T07:48:06.000Z | cartographer/cartographer/mapping/internal/constraints/constraint_builder_2d_test.cc | whydaydayup/cartographer_migrate_to_ros2 | db5a76357a2c9412bde32bd4382757565ce5665c | [
"Apache-2.0"
] | null | null | null | cartographer/cartographer/mapping/internal/constraints/constraint_builder_2d_test.cc | whydaydayup/cartographer_migrate_to_ros2 | db5a76357a2c9412bde32bd4382757565ce5665c | [
"Apache-2.0"
] | 37 | 2018-07-26T00:07:40.000Z | 2021-12-31T07:57:50.000Z | /*
* Copyright 2018 The Cartographer Authors
*
* 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 "cartographer/mapping/internal/constraints/constraint_builder_2d.h"
#include "cartographer/mapping/2d/probability_grid.h"
#include <functional>
#include "cartographer/common/internal/testing/thread_pool_for_testing.h"
#include "cartographer/mapping/2d/submap_2d.h"
#include "cartographer/mapping/internal/constraints/constraint_builder.h"
#include "cartographer/mapping/internal/testing/test_helpers.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
namespace cartographer {
namespace mapping {
namespace constraints {
namespace {
class MockCallback {
public:
MOCK_METHOD1(Run, void(const ConstraintBuilder2D::Result&));
};
class ConstraintBuilder2DTest : public ::testing::Test {
protected:
void SetUp() override {
auto constraint_builder_parameters = testing::ResolveLuaParameters(R"text(
include "pose_graph.lua"
POSE_GRAPH.constraint_builder.sampling_ratio = 1
POSE_GRAPH.constraint_builder.min_score = 0
POSE_GRAPH.constraint_builder.global_localization_min_score = 0
return POSE_GRAPH.constraint_builder)text");
constraint_builder_ = common::make_unique<ConstraintBuilder2D>(
CreateConstraintBuilderOptions(constraint_builder_parameters.get()),
&thread_pool_);
}
std::unique_ptr<ConstraintBuilder2D> constraint_builder_;
MockCallback mock_;
common::testing::ThreadPoolForTesting thread_pool_;
};
TEST_F(ConstraintBuilder2DTest, CallsBack) {
EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 0);
EXPECT_CALL(mock_, Run(::testing::IsEmpty()));
constraint_builder_->NotifyEndOfNode();
constraint_builder_->WhenDone(
[this](const constraints::ConstraintBuilder2D::Result& result) {
mock_.Run(result);
});
thread_pool_.WaitUntilIdle();
EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), 1);
}
TEST_F(ConstraintBuilder2DTest, FindsConstraints) {
TrajectoryNode::Data node_data;
node_data.filtered_gravity_aligned_point_cloud.push_back(
Eigen::Vector3f(0.1, 0.2, 0.3));
node_data.gravity_alignment = Eigen::Quaterniond::Identity();
node_data.local_pose = transform::Rigid3d::Identity();
SubmapId submap_id{0, 1};
MapLimits map_limits(1., Eigen::Vector2d(2., 3.), CellLimits(100, 110));
ValueConversionTables conversion_tables;
Submap2D submap(
Eigen::Vector2f(4.f, 5.f),
common::make_unique<ProbabilityGrid>(map_limits, &conversion_tables),
&conversion_tables);
int expected_nodes = 0;
for (int i = 0; i < 2; ++i) {
EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), expected_nodes);
for (int j = 0; j < 2; ++j) {
constraint_builder_->MaybeAddConstraint(submap_id, &submap, NodeId{0, 0},
&node_data,
transform::Rigid2d::Identity());
}
constraint_builder_->MaybeAddGlobalConstraint(submap_id, &submap,
NodeId{0, 0}, &node_data);
constraint_builder_->NotifyEndOfNode();
thread_pool_.WaitUntilIdle();
EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), ++expected_nodes);
constraint_builder_->NotifyEndOfNode();
thread_pool_.WaitUntilIdle();
EXPECT_EQ(constraint_builder_->GetNumFinishedNodes(), ++expected_nodes);
EXPECT_CALL(mock_,
Run(::testing::AllOf(
::testing::SizeIs(3),
::testing::Each(::testing::Field(
&PoseGraphInterface::Constraint::tag,
PoseGraphInterface::Constraint::INTER_SUBMAP)))));
constraint_builder_->WhenDone(
[this](const constraints::ConstraintBuilder2D::Result& result) {
mock_.Run(result);
});
thread_pool_.WaitUntilIdle();
constraint_builder_->DeleteScanMatcher(submap_id);
}
}
} // namespace
} // namespace constraints
} // namespace mapping
} // namespace cartographer
| 38.567797 | 79 | 0.702263 | [
"transform"
] |
08943c0ba61e62edbc963db60f7a9b61d9055f28 | 3,706 | hpp | C++ | include/pldm_fw.hpp | santoshpuranik/ibm-panel | ebd0bfdb8a32494d400e9e0182e35f18a8c83914 | [
"Apache-2.0"
] | null | null | null | include/pldm_fw.hpp | santoshpuranik/ibm-panel | ebd0bfdb8a32494d400e9e0182e35f18a8c83914 | [
"Apache-2.0"
] | null | null | null | include/pldm_fw.hpp | santoshpuranik/ibm-panel | ebd0bfdb8a32494d400e9e0182e35f18a8c83914 | [
"Apache-2.0"
] | null | null | null | #include "types.hpp"
#include <stdint.h>
#include <vector>
namespace panel
{
using PdrList = std::vector<types::PldmPacket>;
/**
* @brief A class to implement Pldm related functionalities.
*/
class PldmFramework
{
public:
/* Deleted methods */
PldmFramework(const PldmFramework&) = delete;
PldmFramework& operator=(const PldmFramework&) = delete;
PldmFramework(PldmFramework&&) = delete;
PldmFramework& operator=(const PldmFramework&&) = delete;
/**
* @brief Construtor
*/
PldmFramework() = default;
/**
* @brief Destructor
*/
~PldmFramework() = default;
/**
* @brief Send Panel Function to PHYP.
* This api is used to send panel function number to phyp by fetching and
* setting the corresponding effector.
*
* @param[in] funcNumber - Function number that needs to be sent to PHYP.
*/
void sendPanelFunctionToPhyp(const types::FunctionNumber& funcNumber);
private:
// TODO: <https://github.com/ibm-openbmc/ibm-panel/issues/57>
// use PLDM defined header file to refer following constants.
/** Host mctp eid */
static constexpr auto mctpEid = (types::Byte)9;
// Constants required for PLDM packet.
static constexpr auto phypTerminusID = (types::Byte)208;
static constexpr auto frontPanelBoardEntityId = (uint16_t)32837;
static constexpr auto stateIdToEnablePanelFunc = (uint16_t)32778;
/**
* @brief An api to prepare "set effecter" request packet.
* This api prepares the message packet that needs to be sent to the PHYP.
*
* @param[in] pdrs - Panel pdr data.
* @param[in] instanceId - instance id which uniquely identifies the
* requested message packet. This needs to be encoded in the message packet.
* @param[in] function - function number that needs to be sent to PHYP.
*
* @return Returns a Pldm packet.
*/
types::PldmPacket
prepareSetEffecterReq(const PdrList& pdrs, types::Byte instanceId,
const types::FunctionNumber& function);
/**
* @brief Fetch the Panel effecter state set from PDR.
* This api fetches host effecter id, effecter count and effecter position
* from the panel's PDR.
* @param[in] pdrs - Panel PDR data.
* @param[out] effecterId - effecter id retrieved from the PDR.
* @param[out] effecterCount - effecter count retrieved from the PDR.
* @param[out] panelEffecterPos - Position of panel effecter.
*/
void fetchPanelEffecterStateSet(const PdrList& pdrs, uint16_t& effecterId,
types::Byte& effecterCount,
types::Byte& panelEffecterPos);
/**
* @brief Get instance ID
* This api returns the instance id by making a dbus call to GetInstanceId
* api of Pldm. Instance id is to uniquely identify a message packet. This
* id is generated by pldm.
*
* @return one byte instance id.
*/
types::Byte getInstanceID();
/**
* @brief Find and retrieve the PDR.
* This api returns the pdr for the given terminusId, entityId and
* stateSetId.
*
* @param[in] terminusId - PLDM terminus id.
* @param[in] entityId - Id representing an entity associated to the given
* PLDM state set.
* @param[in] stateSetId - Id representing PLDM state set.
* @param[in] pdrMethod - PDR method name
* (FindStateEffecterPDR/FindStateSensorPDR).
*
* @return PDR data.
*/
PdrList getPDR(const uint8_t& terminusId, const uint16_t& entityId,
const uint16_t& stateSetId, const std::string& pdrMethod);
};
} // namespace panel
| 33.690909 | 80 | 0.650027 | [
"vector"
] |
089a738c1a2e6d74425567df663a669c952e9c3d | 3,526 | cc | C++ | src/envoy/http/alpn/alpn_filter.cc | lijinchao/proxy | 422ba7d52af4e9e12ae75497f0d7483a565908b1 | [
"Apache-2.0"
] | 2 | 2020-06-02T03:20:51.000Z | 2020-08-31T17:10:24.000Z | src/envoy/http/alpn/alpn_filter.cc | lijinchao/proxy | 422ba7d52af4e9e12ae75497f0d7483a565908b1 | [
"Apache-2.0"
] | null | null | null | src/envoy/http/alpn/alpn_filter.cc | lijinchao/proxy | 422ba7d52af4e9e12ae75497f0d7483a565908b1 | [
"Apache-2.0"
] | 1 | 2021-02-18T02:46:09.000Z | 2021-02-18T02:46:09.000Z | /* Copyright 2019 Istio Authors. 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 "src/envoy/http/alpn/alpn_filter.h"
#include "common/network/application_protocol.h"
#include "envoy/upstream/cluster_manager.h"
namespace Envoy {
namespace Http {
namespace Alpn {
AlpnFilterConfig::AlpnFilterConfig(
const istio::envoy::config::filter::http::alpn::v2alpha1::FilterConfig
&proto_config,
Upstream::ClusterManager &cluster_manager)
: cluster_manager_(cluster_manager) {
for (const auto &pair : proto_config.alpn_override()) {
std::vector<std::string> application_protocols;
for (const auto &protocol : pair.alpn_override()) {
application_protocols.push_back(protocol);
}
alpn_overrides_.insert({getHttpProtocol(pair.upstream_protocol()),
std::move(application_protocols)});
}
}
Http::Protocol AlpnFilterConfig::getHttpProtocol(
const istio::envoy::config::filter::http::alpn::v2alpha1::FilterConfig::
Protocol &protocol) {
switch (protocol) {
case istio::envoy::config::filter::http::alpn::v2alpha1::FilterConfig::
Protocol::FilterConfig_Protocol_HTTP10:
return Http::Protocol::Http10;
case istio::envoy::config::filter::http::alpn::v2alpha1::FilterConfig::
Protocol::FilterConfig_Protocol_HTTP11:
return Http::Protocol::Http11;
case istio::envoy::config::filter::http::alpn::v2alpha1::FilterConfig::
Protocol::FilterConfig_Protocol_HTTP2:
return Http::Protocol::Http2;
default:
// will not reach here.
NOT_IMPLEMENTED_GCOVR_EXCL_LINE;
}
}
Http::FilterHeadersStatus AlpnFilter::decodeHeaders(Http::RequestHeaderMap &,
bool) {
Router::RouteConstSharedPtr route = decoder_callbacks_->route();
const Router::RouteEntry *route_entry;
if (!route || !(route_entry = route->routeEntry())) {
ENVOY_LOG(debug, "cannot find route entry");
return Http::FilterHeadersStatus::Continue;
}
Upstream::ThreadLocalCluster *cluster =
config_->clusterManager().get(route_entry->clusterName());
if (!cluster || !cluster->info()) {
ENVOY_LOG(debug, "cannot find cluster {}", route_entry->clusterName());
return Http::FilterHeadersStatus::Continue;
}
Http::Protocol protocol = cluster->info()->upstreamHttpProtocol(
decoder_callbacks_->streamInfo().protocol());
const auto &alpn_override = config_->alpnOverrides(protocol);
if (!alpn_override.empty()) {
ENVOY_LOG(debug, "override with {} ALPNs", alpn_override.size());
decoder_callbacks_->streamInfo().filterState()->setData(
Network::ApplicationProtocols::key(),
std::make_unique<Network::ApplicationProtocols>(alpn_override),
Envoy::StreamInfo::FilterState::StateType::ReadOnly);
} else {
ENVOY_LOG(debug, "ALPN override is empty");
}
return Http::FilterHeadersStatus::Continue;
}
} // namespace Alpn
} // namespace Http
} // namespace Envoy
| 37.115789 | 77 | 0.703063 | [
"vector"
] |
08ac8915e73553204fc9c04a75b6f4e2e67d07a0 | 2,794 | hpp | C++ | src/lib/server/FrontPanelControllerBasis.hpp | gerickson/openhlx | f23a825ca56ee226db393da14d81a7d4e9ae0b33 | [
"Apache-2.0"
] | 1 | 2021-05-21T21:10:09.000Z | 2021-05-21T21:10:09.000Z | src/lib/server/FrontPanelControllerBasis.hpp | gerickson/openhlx | f23a825ca56ee226db393da14d81a7d4e9ae0b33 | [
"Apache-2.0"
] | 12 | 2021-06-12T16:42:30.000Z | 2022-02-01T18:44:42.000Z | src/lib/server/FrontPanelControllerBasis.hpp | gerickson/openhlx | f23a825ca56ee226db393da14d81a7d4e9ae0b33 | [
"Apache-2.0"
] | null | null | null | /*
* Copyright (c) 2021 Grant Erickson
* 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.
*
*/
/**
* @file
* This file defines a derivable object for realizing a HLX
* physical front panel controller, in a server.
*
*/
#ifndef OPENHLXSERVERFRONTPANELCONTROLLERBASIS_HPP
#define OPENHLXSERVERFRONTPANELCONTROLLERBASIS_HPP
#include <OpenHLX/Model/FrontPanelModel.hpp>
#include <OpenHLX/Server/FrontPanelControllerCommands.hpp>
#include <OpenHLX/Server/ObjectControllerBasis.hpp>
namespace HLX
{
namespace Server
{
/**
* @brief
* A derivable object for realizing a HLX physical front panel
* controller, in a server.
*
* @ingroup server
* @ingroup front-panel
*
*/
class FrontPanelControllerBasis :
public Server::ObjectControllerBasis
{
public:
virtual ~FrontPanelControllerBasis(void);
protected:
FrontPanelControllerBasis(Model::FrontPanelModel &aFrontPanelModel);
// Initializer(s)
virtual Common::Status Init(CommandManager &aCommandManager);
private:
// Implementation
Common::Status RequestInit(void);
private:
Model::FrontPanelModel & mFrontPanelModel;
protected:
// Observation (Query) Command Request Handlers
// Observation (Query) Command Request Instance Handlers
Common::Status HandleQueryReceived(Common::ConnectionBuffer::MutableCountedPointer &aBuffer) const;
protected:
// Observation (Query) Command Request Class (Static) Handlers
protected:
// Command Response Handlers
// Command Response Class (Static) Handlers
static Common::Status HandleBrightnessResponse(const Model::FrontPanelModel::BrightnessType &aBrightness, Common::ConnectionBuffer::MutableCountedPointer &aBuffer);
static Common::Status HandleLockedResponse(const Model::FrontPanelModel::LockedType &aLocked, Common::ConnectionBuffer::MutableCountedPointer &aBuffer);
protected:
static Server::Command::FrontPanel::QueryRequest kQueryRequest;
static Server::Command::FrontPanel::SetBrightnessRequest kSetBrightnessRequest;
static Server::Command::FrontPanel::SetLockedRequest kSetLockedRequest;
};
}; // namespace Server
}; // namespace HLX
#endif // OPENHLXSERVERFRONTPANELCONTROLLERBASIS_HPP
| 28.222222 | 168 | 0.74481 | [
"object",
"model"
] |
08b1c2fbe32120d7682a004c43280f154841666d | 10,514 | cpp | C++ | airplay2/lib/fdk-aac/libAACenc/src/transform.cpp | ikas-mc/airplay2-win | 8fcf66768a436ea152008848c71cd311bdcc1233 | [
"MIT"
] | 192 | 2020-03-03T02:31:29.000Z | 2022-03-13T01:37:37.000Z | airplay2/lib/fdk-aac/libAACenc/src/transform.cpp | QQ1112880/airplay2-win | a2fd01ea40ceb9274a8ca3eb784f96e64e9c3559 | [
"MIT"
] | 15 | 2020-03-03T03:24:25.000Z | 2022-02-21T03:28:14.000Z | airplay2/lib/fdk-aac/libAACenc/src/transform.cpp | QQ1112880/airplay2-win | a2fd01ea40ceb9274a8ca3eb784f96e64e9c3559 | [
"MIT"
] | 72 | 2020-03-03T05:01:30.000Z | 2022-03-31T13:34:01.000Z | /* -----------------------------------------------------------------------------
Software License for The Fraunhofer FDK AAC Codec Library for Android
© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
scheme for digital audio. This FDK AAC Codec software is intended to be used on
a wide variety of Android devices.
AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
general perceptual audio codecs. AAC-ELD is considered the best-performing
full-bandwidth communications codec by independent studies and is widely
deployed. AAC has been standardized by ISO and IEC as part of the MPEG
specifications.
Patent licenses for necessary patent claims for the FDK AAC Codec (including
those of Fraunhofer) may be obtained through Via Licensing
(www.vialicensing.com) or through the respective patent owners individually for
the purpose of encoding or decoding bit streams in products that are compliant
with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
Android devices already license these patent claims through Via Licensing or
directly from the patent owners, and therefore FDK AAC Codec software may
already be covered under those patent licenses when it is used for those
licensed purposes only.
Commercially-licensed AAC software libraries, including floating-point versions
with enhanced sound quality, are also available from Fraunhofer. Users are
encouraged to check the Fraunhofer website for additional applications
information and documentation.
2. COPYRIGHT LICENSE
Redistribution and use in source and binary forms, with or without modification,
are permitted without payment of copyright license fees provided that you
satisfy the following conditions:
You must retain the complete text of this software license in redistributions of
the FDK AAC Codec or your modifications thereto in source code form.
You must retain the complete text of this software license in the documentation
and/or other materials provided with redistributions of the FDK AAC Codec or
your modifications thereto in binary form. You must make available free of
charge copies of the complete source code of the FDK AAC Codec and your
modifications thereto to recipients of copies in binary form.
The name of Fraunhofer may not be used to endorse or promote products derived
from this library without prior written permission.
You may not charge copyright license fees for anyone to use, copy or distribute
the FDK AAC Codec software or your modifications thereto.
Your modified versions of the FDK AAC Codec must carry prominent notices stating
that you changed the software and the date of any change. For modified versions
of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
AAC Codec Library for Android."
3. NO PATENT LICENSE
NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
Fraunhofer provides no warranty of patent non-infringement with respect to this
software.
You may use this FDK AAC Codec software or modifications thereto only for
purposes that are authorized by appropriate patent licenses.
4. DISCLAIMER
This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
including but not limited to the implied warranties of merchantability and
fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
or consequential damages, including but not limited to procurement of substitute
goods or services; loss of use, data, or profits, or business interruption,
however caused and on any theory of liability, whether in contract, strict
liability, or tort (including negligence), arising in any way out of the use of
this software, even if advised of the possibility of such damage.
5. CONTACT INFORMATION
Fraunhofer Institute for Integrated Circuits IIS
Attention: Audio and Multimedia Departments - FDK AAC LL
Am Wolfsmantel 33
91058 Erlangen, Germany
www.iis.fraunhofer.de/amm
amm-info@iis.fraunhofer.de
----------------------------------------------------------------------------- */
/**************************** AAC encoder library ******************************
Author(s): Tobias Chalupka
Description: FDKaacLdEnc_MdctTransform480:
The module FDKaacLdEnc_MdctTransform will perform the MDCT.
The MDCT supports the sine window and
the zero padded window. The algorithm of the MDCT
can be divided in Windowing, PreModulation, Fft and
PostModulation.
*******************************************************************************/
#include "transform.h"
#include "dct.h"
#include "psy_const.h"
#include "aacEnc_rom.h"
#include "FDK_tools_rom.h"
#if defined(__arm__)
#endif
INT FDKaacEnc_Transform_Real(const INT_PCM *pTimeData,
FIXP_DBL *RESTRICT mdctData, const INT blockType,
const INT windowShape, INT *prevWindowShape,
H_MDCT mdctPers, const INT frameLength,
INT *pMdctData_e, INT filterType) {
const INT_PCM *RESTRICT timeData;
UINT numSpec;
UINT numMdctLines;
UINT offset;
int fr; /* fr: right window slope length */
SHORT mdctData_e[8];
timeData = pTimeData;
if (blockType == SHORT_WINDOW) {
numSpec = 8;
numMdctLines = frameLength >> 3;
} else {
numSpec = 1;
numMdctLines = frameLength;
}
offset = (windowShape == LOL_WINDOW) ? ((frameLength * 3) >> 2) : 0;
switch (blockType) {
case LONG_WINDOW:
case STOP_WINDOW:
fr = frameLength - offset;
break;
case START_WINDOW: /* or StopStartSequence */
case SHORT_WINDOW:
fr = frameLength >> 3;
break;
default:
FDK_ASSERT(0);
return -1;
}
mdct_block(mdctPers, timeData, frameLength, mdctData, numSpec, numMdctLines,
FDKgetWindowSlope(fr, windowShape), fr, mdctData_e);
if (blockType == SHORT_WINDOW) {
if (!(mdctData_e[0] == mdctData_e[1] && mdctData_e[1] == mdctData_e[2] &&
mdctData_e[2] == mdctData_e[3] && mdctData_e[3] == mdctData_e[4] &&
mdctData_e[4] == mdctData_e[5] && mdctData_e[5] == mdctData_e[6] &&
mdctData_e[6] == mdctData_e[7])) {
return -1;
}
}
*prevWindowShape = windowShape;
*pMdctData_e = mdctData_e[0];
return 0;
}
INT FDKaacEnc_Transform_Real_Eld(const INT_PCM *pTimeData,
FIXP_DBL *RESTRICT mdctData,
const INT blockType, const INT windowShape,
INT *prevWindowShape, const INT frameLength,
INT *mdctData_e, INT filterType,
FIXP_DBL *RESTRICT overlapAddBuffer) {
const INT_PCM *RESTRICT timeData;
INT i;
/* tl: transform length
fl: left window slope length
nl: left window slope offset
fr: right window slope length
nr: right window slope offset */
const FIXP_WTB *pWindowELD = NULL;
int N = frameLength;
int L = frameLength;
timeData = pTimeData;
if (blockType != LONG_WINDOW) {
return -1;
}
/*
* MDCT scale:
* + 1: fMultDiv2() in windowing.
* + 1: Because of factor 1/2 in Princen-Bradley compliant windowed TDAC.
*/
*mdctData_e = 1 + 1;
switch (frameLength) {
case 512:
pWindowELD = ELDAnalysis512;
break;
case 480:
pWindowELD = ELDAnalysis480;
break;
case 256:
pWindowELD = ELDAnalysis256;
*mdctData_e += 1;
break;
case 240:
pWindowELD = ELDAnalysis240;
*mdctData_e += 1;
break;
case 128:
pWindowELD = ELDAnalysis128;
*mdctData_e += 2;
break;
case 120:
pWindowELD = ELDAnalysis120;
*mdctData_e += 2;
break;
default:
FDK_ASSERT(0);
return -1;
}
for (i = 0; i < N / 4; i++) {
FIXP_DBL z0, outval;
z0 = (fMult((FIXP_PCM)timeData[L + N * 3 / 4 - 1 - i],
pWindowELD[N / 2 - 1 - i])
<< (WTS0 - 1)) +
(fMult((FIXP_PCM)timeData[L + N * 3 / 4 + i], pWindowELD[N / 2 + i])
<< (WTS0 - 1));
outval = (fMultDiv2((FIXP_PCM)timeData[L + N * 3 / 4 - 1 - i],
pWindowELD[N + N / 2 - 1 - i]) >>
(-WTS1));
outval += (fMultDiv2((FIXP_PCM)timeData[L + N * 3 / 4 + i],
pWindowELD[N + N / 2 + i]) >>
(-WTS1));
outval += (fMultDiv2(overlapAddBuffer[N / 2 + i], pWindowELD[2 * N + i]) >>
(-WTS2 - 1));
overlapAddBuffer[N / 2 + i] = overlapAddBuffer[i];
overlapAddBuffer[i] = z0;
mdctData[i] = overlapAddBuffer[N / 2 + i] +
(fMultDiv2(overlapAddBuffer[N + N / 2 - 1 - i],
pWindowELD[2 * N + N / 2 + i]) >>
(-WTS2 - 1));
mdctData[N - 1 - i] = outval;
overlapAddBuffer[N + N / 2 - 1 - i] = outval;
}
for (i = N / 4; i < N / 2; i++) {
FIXP_DBL z0, outval;
z0 = fMult((FIXP_PCM)timeData[L + N * 3 / 4 - 1 - i],
pWindowELD[N / 2 - 1 - i])
<< (WTS0 - 1);
outval = (fMultDiv2((FIXP_PCM)timeData[L + N * 3 / 4 - 1 - i],
pWindowELD[N + N / 2 - 1 - i]) >>
(-WTS1));
outval += (fMultDiv2(overlapAddBuffer[N / 2 + i], pWindowELD[2 * N + i]) >>
(-WTS2 - 1));
overlapAddBuffer[N / 2 + i] =
overlapAddBuffer[i] +
(fMult((FIXP_PCM)timeData[L - N / 4 + i], pWindowELD[N / 2 + i])
<< (WTS0 - 1));
overlapAddBuffer[i] = z0;
mdctData[i] = overlapAddBuffer[N / 2 + i] +
(fMultDiv2(overlapAddBuffer[N + N / 2 - 1 - i],
pWindowELD[2 * N + N / 2 + i]) >>
(-WTS2 - 1));
mdctData[N - 1 - i] = outval;
overlapAddBuffer[N + N / 2 - 1 - i] = outval;
}
dct_IV(mdctData, frameLength, mdctData_e);
*prevWindowShape = windowShape;
return 0;
}
| 35.640678 | 80 | 0.640004 | [
"transform"
] |
08b1ed4baf3792737be903ed34f014e2dbf1f69a | 6,747 | cxx | C++ | private/inet/xml/xml/om/xqlnodelist.cxx | King0987654/windows2000 | 01f9c2e62c4289194e33244aade34b7d19e7c9b8 | [
"MIT"
] | 11 | 2017-09-02T11:27:08.000Z | 2022-01-02T15:25:24.000Z | private/inet/xml/xml/om/xqlnodelist.cxx | King0987654/windows2000 | 01f9c2e62c4289194e33244aade34b7d19e7c9b8 | [
"MIT"
] | null | null | null | private/inet/xml/xml/om/xqlnodelist.cxx | King0987654/windows2000 | 01f9c2e62c4289194e33244aade34b7d19e7c9b8 | [
"MIT"
] | 14 | 2019-01-16T01:01:23.000Z | 2022-02-20T15:54:27.000Z | /*
* @(#)XQLNodeList.cxx 1.0 7/6/98
*
* Copyright (C) 1998,1999 Microsoft Corporation. All rights reserved. *
*/
#include "core.hxx"
#pragma hdrstop
#ifndef _XML_OM_IXMLDOMNODE
#include "domnode.hxx"
#endif
#ifndef _XML_OM_XQLNODELIST
#include "xqlnodelist.hxx"
#endif
#ifndef _XQL_PARSER_XQLPARSER
#include "xql/parser/xqlparser.hxx"
#endif
#define CleanupTEST(t) if (!t) { hr=S_FALSE; goto Cleanup; }
#define ARGTEST(t) if (!t) { hr=E_INVALIDARG; goto Cleanup; }
//=======================================================================
/* NOTE: THIS CONSTRUCTOR HAS BEEN MOVED
** to domnode.cxx, because to not do so breaks all of XQL under Unix
** due to a unix compiler bug which has to do with statics and templates
**
XQLNodeList::XQLNodeList()
{
_pResults = new Vector(5);
_lIndex = -1;
_fCacheComplete = false;
}
*
*/
XQLNodeList::~XQLNodeList()
{
}
extern CSMutex * g_pMutex;
void
XQLNodeList::setQuery(const String* xql, Element* pContext)
{
//long __RPC_FAR pLength;
//HRESULT hr;
XQLParser* parser = new XQLParser(true); // GC'd object.
_pQuery = parser->parse(xql);
_pQuery->setContext(null, pContext);
Assert(pContext);
Document * pDoc = pContext->getDocument();
if (pDoc)
_pMutex = pDoc->getMutex();
else
_pMutex = g_pMutex;
//hr = get_length(&pLength);
}
////////////////////////////////////////////////////////////////////////////////
// IXMLDOMNodeList Interface
//
HRESULT STDMETHODCALLTYPE
XQLNodeList::QueryInterface(REFIID iid, void ** ppv)
{
STACK_ENTRY_IUNKNOWN(this);
HRESULT hr = S_OK;
TRY
{
if (iid == IID_IUnknown || iid == IID_IDispatch ||
iid == IID_IXMLDOMNodeList)
{
AddRef();
*ppv = SAFE_CAST(IXMLDOMNodeList *,this);
}
else if (iid == IID_IEnumVARIANT)
{
hr = get__newEnum((IUnknown**)ppv);
}
else if (iid == IID_IDispatchEx)
{
AddRef();
*ppv = SAFE_CAST(IDispatchEx *, this);
}
else
{
*ppv = NULL;
hr = E_NOINTERFACE;
}
}
CATCH
{
hr = ERESULTINFO;
}
ENDTRY
return hr;
}
HRESULT STDMETHODCALLTYPE
XQLNodeList::get_item(
/* [in][optional] */ long index,
/* [out][retval] */ IXMLDOMNode __RPC_FAR *__RPC_FAR *ppNode)
{
STACK_ENTRY_IUNKNOWN(this);
HRESULT hr = moveTo(index, (IXMLDOMNode**)ppNode);
return hr;
}
HRESULT STDMETHODCALLTYPE
XQLNodeList::get_length(
/* [out][retval] */ long __RPC_FAR *pl)
{
STACK_ENTRY_IUNKNOWN(this);
HRESULT hr;
ARGTEST(pl);
*pl = 0;
TRY
{
// Fill the cache then return the cache size.
while (!_fCacheComplete)
_next();
*pl = _pResults->size();
hr = S_OK;
}
CATCH
{
hr = ERESULTINFO;
}
ENDTRY
Cleanup:
return hr;
}
HRESULT STDMETHODCALLTYPE
XQLNodeList::nextNode(
/* [out][retval] */ IXMLDOMNode __RPC_FAR *__RPC_FAR *ppNode)
{
STACK_ENTRY_IUNKNOWN(this);
HRESULT hr = moveTo(_lIndex+1, ppNode);
return hr;
}
HRESULT STDMETHODCALLTYPE
XQLNodeList::reset( void)
{
_lIndex = -1;
return S_OK;
}
HRESULT STDMETHODCALLTYPE
XQLNodeList::get__newEnum(
/* [out][retval] */ IUnknown __RPC_FAR *__RPC_FAR *ppUnk)
{
STACK_ENTRY_IUNKNOWN(this);
TraceTag((tagDOMOM, "XQLNodeList::get__newEnum"));
HRESULT hr = S_OK;
ARGTEST( ppUnk);
TRY
{
// Create a new enumeration that enumerates through the same
// set of children as this XQLNodeList.
*ppUnk = IEnumVARIANTWrapper::newIEnumVARIANTWrapper((IXMLDOMNodeList*)this, (EnumVariant*)this, _pMutex);
}
CATCH
{
hr = ERESULTINFO;
}
ENDTRY
Cleanup:
return hr;
}
////////////////////////////////////////////////////////////////////////////////
// EnumVariant Interface
/////////////////////////////////////////////////////////////////////////////
// This method is called by the IEnumVARIANTWrapper, so no lock or try/catch
// is needed here.
IDispatch *
XQLNodeList::enumGetIDispatch(Node * pNode)
{
if (pNode)
{
IXMLDOMNode * pDisp;
HRESULT hr;
hr = getIDOMNode(pNode, &pDisp);
if (!hr)
return (IDispatch *)pDisp;
}
return null;
}
Node *
XQLNodeList::enumGetNext(void ** ppv)
{
long * pl = (long *)ppv;
Node * pNode = moveToNode(*pl);
if (pNode)
++(*pl);
return pNode;
}
// -------------- PRIVATE METHODS --------------------------------------
Node *
XQLNodeList::moveToNode(long lIndex)
{
if (lIndex >= 0)
{
// We now prefect all nodes in setQuery(), so we should not
// be doing any more fetching in here. So don't uncomment
// the following couple lines of code. And don't try to get
// around the prefetching behavior because the XQL performance
// is assuming all results are prefetched. Jan 14, 1999 (wiladams)
// Fill the cache up to the index required.
while (!_fCacheComplete && (lIndex+1) >= _pResults->size())
_next();
if (lIndex < _pResults->size())
{
Element* e = (Element*)_pResults->elementAt(lIndex);
_lIndex = lIndex;
return CAST_TO(ElementNode*, e);
}
}
return null;
}
HRESULT
XQLNodeList::moveTo(
/* [in] */ long lIndex,
/* [out][retval] */ IXMLDOMNode __RPC_FAR *__RPC_FAR *ppNode)
{
STACK_ENTRY_IUNKNOWN(this);
HRESULT hr;
ARGTEST(ppNode);
*ppNode = 0;
TRY
{
ElementNode* e = moveToNode(lIndex);
hr = getIDOMNode(e, ppNode);
}
CATCH
{
hr = ERESULTINFO;
}
ENDTRY
Cleanup:
return hr;
}
Element*
XQLNodeList::_next()
{
Element* e = null;
long size = _pResults->size();
if (! _fCacheComplete)
{
e = (Element *) _pQuery->nextElement();
if (e)
{
_pResults->addElement(e);
}
else
{
_fCacheComplete = true;
}
}
return e;
}
HRESULT
XQLNodeList::getIDOMNode(Element * e, IXMLDOMNode ** pp)
{
HRESULT hr;
if (e != null)
{
checkhr(e->QueryInterface(IID_IXMLDOMNode, (void **) pp));
hr = S_OK;
}
else
{
*pp = null;
hr = S_FALSE;
}
return hr;
}
| 21.905844 | 115 | 0.528679 | [
"object",
"vector"
] |
08b40c6c690436222c6f0dfd7a8e86ea381fc3cb | 1,321 | cpp | C++ | Aiko/src/engine/utils.cpp | jotask/aiko_engine | 41ea03002fa094e728d95aa91aff267bc400b313 | [
"MIT"
] | null | null | null | Aiko/src/engine/utils.cpp | jotask/aiko_engine | 41ea03002fa094e728d95aa91aff267bc400b313 | [
"MIT"
] | null | null | null | Aiko/src/engine/utils.cpp | jotask/aiko_engine | 41ea03002fa094e728d95aa91aff267bc400b313 | [
"MIT"
] | null | null | null | #include "utils.h"
float Utils::random1D()
{
return Utils::random1D(0.0f, 1.0f);
}
float Utils::random1D(float min, float max)
{
std::random_device rd; //Will be used to obtain a seed for the random number engine
std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
std::uniform_real_distribution<float> dis(min, max);
return dis(gen);
}
sf::Vector2f Utils::randomPointInScreen()
{
const float x = random1D(0.0f, (float) WIDTH );
const float y = random1D(0.0f, (float) HEIGHT );
return sf::Vector2f(x, y);
}
sf::Vector2f Utils::random2D()
{
const float x = random1D(-1.0, 1.0f);
const float y = random1D(-1.0, 1.0f);
return sf::Vector2f(x, y);
}
sf::Color Utils::randomColor(bool alpha)
{
const auto r = random(0, 255);
const auto g = random(0, 255);
const auto b = random(0, 255);
const auto a = random(0, 255);
if (alpha == true)
{
return sf::Color(r, g, b, a);
}
return sf::Color(r, g, b);
}
sf::Vector2f Utils::getGlobalCenter(sf::Shape& shape)
{
// TODO implement
const auto p = shape.getPosition();
const auto b = shape.getGlobalBounds();
sf::Vector2f localCenter;
localCenter.x = 0;
localCenter.y = 0;
sf::Vector2f center(shape.getPosition());
return center;
} | 21.655738 | 88 | 0.629069 | [
"shape"
] |
08b7df2bf0e96304691485d5eb663e347e380058 | 10,501 | cpp | C++ | src/bindings/python/PyProcessor.cpp | KevinJW/OpenColorIO | 412aa7ba273616867e607de646e4975791198812 | [
"BSD-3-Clause"
] | 1 | 2021-06-09T22:50:23.000Z | 2021-06-09T22:50:23.000Z | src/bindings/python/PyProcessor.cpp | KevinJW/OpenColorIO | 412aa7ba273616867e607de646e4975791198812 | [
"BSD-3-Clause"
] | null | null | null | src/bindings/python/PyProcessor.cpp | KevinJW/OpenColorIO | 412aa7ba273616867e607de646e4975791198812 | [
"BSD-3-Clause"
] | null | null | null | /*
Copyright (c) 2003-2010 Sony Pictures Imageworks Inc., et al.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Sony Pictures Imageworks nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <Python.h>
#include <sstream>
#include <OpenColorIO/OpenColorIO.h>
#include "PyUtil.h"
#include "PyDoc.h"
OCIO_NAMESPACE_ENTER
{
PyObject * BuildConstPyProcessor(ConstProcessorRcPtr processor)
{
return BuildConstPyOCIO<PyOCIO_Processor, ProcessorRcPtr,
ConstProcessorRcPtr>(processor, PyOCIO_ProcessorType);
}
bool IsPyProcessor(PyObject * pyobject)
{
return IsPyOCIOType(pyobject, PyOCIO_ProcessorType);
}
ConstProcessorRcPtr GetConstProcessor(PyObject * pyobject)
{
return GetConstPyOCIO<PyOCIO_Processor, ConstProcessorRcPtr>(pyobject,
PyOCIO_ProcessorType);
}
namespace
{
///////////////////////////////////////////////////////////////////////
///
int PyOCIO_Processor_init(PyOCIO_Processor * self, PyObject * args, PyObject * kwds);
void PyOCIO_Processor_delete(PyOCIO_Processor * self);
PyObject * PyOCIO_Processor_isNoOp(PyObject * self, PyObject *);
PyObject * PyOCIO_Processor_hasChannelCrosstalk(PyObject * self, PyObject *);
PyObject * PyOCIO_Processor_getProcessorMetadata(PyObject * self, PyObject *);
PyObject * PyOCIO_Processor_applyRGB(PyObject * self, PyObject * args);
PyObject * PyOCIO_Processor_applyRGBA(PyObject * self, PyObject * args);
///////////////////////////////////////////////////////////////////////
///
PyMethodDef PyOCIO_Processor_methods[] = {
{ "isNoOp",
(PyCFunction) PyOCIO_Processor_isNoOp, METH_NOARGS, PROCESSOR_ISNOOP__DOC__ },
{ "hasChannelCrosstalk",
(PyCFunction) PyOCIO_Processor_hasChannelCrosstalk, METH_NOARGS, PROCESSOR_HASCHANNELCROSSTALK__DOC__ },
{ "getProcessorMetadata",
(PyCFunction) PyOCIO_Processor_getProcessorMetadata, METH_NOARGS, PROCESSOR_GETPROCESSORMETADATA__DOC__ },
{ "applyRGB",
PyOCIO_Processor_applyRGB, METH_VARARGS, PROCESSOR_APPLYRGB__DOC__ },
{ "applyRGBA",
PyOCIO_Processor_applyRGBA, METH_VARARGS, PROCESSOR_APPLYRGBA__DOC__ },
{ NULL, NULL, 0, NULL }
};
const char initMessage[] =
"Processor objects cannot be instantiated directly. "
"Please use config.getProcessor() instead.";
}
///////////////////////////////////////////////////////////////////////////
///
PyTypeObject PyOCIO_ProcessorType = {
PyVarObject_HEAD_INIT(NULL, 0) //ob_size
OCIO_PYTHON_NAMESPACE(Processor), //tp_name
sizeof(PyOCIO_Processor), //tp_basicsize
0, //tp_itemsize
(destructor)PyOCIO_Processor_delete, //tp_dealloc
0, //tp_print
0, //tp_getattr
0, //tp_setattr
0, //tp_compare
0, //tp_repr
0, //tp_as_number
0, //tp_as_sequence
0, //tp_as_mapping
0, //tp_hash
0, //tp_call
0, //tp_str
0, //tp_getattro
0, //tp_setattro
0, //tp_as_buffer
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, //tp_flags
PROCESSOR__DOC__, //tp_doc
0, //tp_traverse
0, //tp_clear
0, //tp_richcompare
0, //tp_weaklistoffset
0, //tp_iter
0, //tp_iternext
PyOCIO_Processor_methods, //tp_methods
0, //tp_members
0, //tp_getset
0, //tp_base
0, //tp_dict
0, //tp_descr_get
0, //tp_descr_set
0, //tp_dictoffset
(initproc) PyOCIO_Processor_init, //tp_init
0, //tp_alloc
0, //tp_new
0, //tp_free
0, //tp_is_gc
};
///////////////////////////////////////////////////////////////////////////
///
namespace
{
///////////////////////////////////////////////////////////////////////
///
int PyOCIO_Processor_init(PyOCIO_Processor * /*self*/, PyObject * /*args*/, PyObject * /*kwds*/)
{
PyErr_SetString( PyExc_RuntimeError, initMessage);
return -1;
}
void PyOCIO_Processor_delete(PyOCIO_Processor *self)
{
DeletePyObject<PyOCIO_Processor>(self);
}
PyObject * PyOCIO_Processor_isNoOp(PyObject * self, PyObject *)
{
OCIO_PYTRY_ENTER()
ConstProcessorRcPtr processor = GetConstProcessor(self);
return PyBool_FromLong(processor->isNoOp());
OCIO_PYTRY_EXIT(NULL)
}
PyObject * PyOCIO_Processor_hasChannelCrosstalk(PyObject * self, PyObject *)
{
OCIO_PYTRY_ENTER()
ConstProcessorRcPtr processor = GetConstProcessor(self);
return PyBool_FromLong(processor->hasChannelCrosstalk());
OCIO_PYTRY_EXIT(NULL)
}
PyObject * PyOCIO_Processor_getProcessorMetadata(PyObject * self, PyObject *)
{
OCIO_PYTRY_ENTER()
ConstProcessorRcPtr processor = GetConstProcessor(self);
return BuildConstPyProcessorMetadata(processor->getProcessorMetadata());
OCIO_PYTRY_EXIT(NULL)
}
PyObject * PyOCIO_Processor_applyRGB(PyObject * self, PyObject * args)
{
OCIO_PYTRY_ENTER()
PyObject* pyData = 0;
if (!PyArg_ParseTuple(args, "O:applyRGB",
&pyData)) return NULL;
ConstProcessorRcPtr processor = GetConstProcessor(self);
if(processor->isNoOp())
{
Py_INCREF(pyData);
return pyData;
}
std::vector<float> data;
if(!FillFloatVectorFromPySequence(pyData, data) ||
((data.size() % 3) != 0))
{
std::ostringstream os;
os << "First argument must be a float array, size multiple of 3. ";
os << "Size: " << data.size() << ".";
PyErr_SetString(PyExc_TypeError, os.str().c_str());
return 0;
}
PackedImageDesc img(&data[0], long(data.size()/3), 1, 3);
processor->getDefaultCPUProcessor()->apply(img);
return CreatePyListFromFloatVector(data);
OCIO_PYTRY_EXIT(NULL)
}
PyObject * PyOCIO_Processor_applyRGBA(PyObject * self, PyObject * args)
{
OCIO_PYTRY_ENTER()
PyObject* pyData = 0;
if (!PyArg_ParseTuple(args, "O:applyRGBA",
&pyData)) return NULL;
ConstProcessorRcPtr processor = GetConstProcessor(self);
if(processor->isNoOp())
{
Py_INCREF(pyData);
return pyData;
}
std::vector<float> data;
if(!FillFloatVectorFromPySequence(pyData, data) ||
((data.size() % 4) != 0))
{
std::ostringstream os;
os << "First argument must be a float array, size multiple of 4. ";
os << "Size: " << data.size() << ".";
PyErr_SetString(PyExc_TypeError, os.str().c_str());
return 0;
}
PackedImageDesc img(&data[0], long(data.size()/4), 1, 4);
processor->getDefaultCPUProcessor()->apply(img);
return CreatePyListFromFloatVector(data);
OCIO_PYTRY_EXIT(NULL)
}
}
}
OCIO_NAMESPACE_EXIT
| 43.213992 | 118 | 0.505476 | [
"vector"
] |
08c09b88013d696df25049357665ee67ce1e316f | 2,926 | hpp | C++ | src/armnn/LoadedNetwork.hpp | tom-gall/armnn | a21620d32a8a0a8d527c061e2a22d51009d75877 | [
"MIT"
] | null | null | null | src/armnn/LoadedNetwork.hpp | tom-gall/armnn | a21620d32a8a0a8d527c061e2a22d51009d75877 | [
"MIT"
] | null | null | null | src/armnn/LoadedNetwork.hpp | tom-gall/armnn | a21620d32a8a0a8d527c061e2a22d51009d75877 | [
"MIT"
] | null | null | null | //
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once
#include <armnn/Tensor.hpp>
#include <armnn/Types.hpp>
#include "Network.hpp"
#include "LayerFwd.hpp"
#include "Profiling.hpp"
#include <backendsCommon/IBackendInternal.hpp>
#include <backendsCommon/TensorHandleFactoryRegistry.hpp>
#include <backendsCommon/Workload.hpp>
#include <backendsCommon/WorkloadFactory.hpp>
#include <mutex>
#include <unordered_map>
namespace cl
{
class Context;
class CommandQueue;
class Device;
}
namespace armnn
{
class LoadedNetwork
{
public:
using WorkloadQueue = std::vector< std::unique_ptr<IWorkload> >;
~LoadedNetwork(){ FreeWorkingMemory(); }
TensorInfo GetInputTensorInfo(LayerBindingId layerId) const;
TensorInfo GetOutputTensorInfo(LayerBindingId layerId) const;
Status EnqueueWorkload(const InputTensors& inputTensors, const OutputTensors& outputTensors);
static std::unique_ptr<LoadedNetwork> MakeLoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
std::string & errorMessage,
const INetworkProperties& networkProperties);
// NOTE we return by reference as the purpose of this method is only to provide
// access to the private m_Profiler and in theory we should not need to increment
// the shared_ptr's reference counter
const std::shared_ptr<Profiler>& GetProfiler() const { return m_Profiler; }
void FreeWorkingMemory();
void RegisterDebugCallback(const DebugCallbackFunction& func);
private:
void AllocateWorkingMemory();
LoadedNetwork(std::unique_ptr<OptimizedNetwork> net, const INetworkProperties& networkProperties);
void EnqueueInput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo);
void EnqueueOutput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo);
bool Execute();
const IWorkloadFactory& GetWorkloadFactory(const Layer& layer) const;
using BackendPtrMap = std::unordered_map<BackendId, IBackendInternalUniquePtr>;
using WorkloadFactoryWithMemoryManager =
std::pair<IBackendInternal::IWorkloadFactoryPtr, IBackendInternal::IMemoryManagerSharedPtr>;
using WorkloadFactoryMap = std::unordered_map<BackendId, WorkloadFactoryWithMemoryManager>;
BackendPtrMap m_Backends;
WorkloadFactoryMap m_WorkloadFactories;
std::unique_ptr<OptimizedNetwork> m_OptimizedNetwork;
WorkloadQueue m_InputQueue;
WorkloadQueue m_WorkloadQueue;
WorkloadQueue m_OutputQueue;
std::shared_ptr<Profiler> m_Profiler;
mutable std::mutex m_WorkingMemMutex;
bool m_IsWorkingMemAllocated=false;
bool m_IsImportEnabled=false;
bool m_IsExportEnabled=false;
TensorHandleFactoryRegistry m_TensorHandleFactoryRegistry;
};
}
| 30.8 | 110 | 0.741969 | [
"vector"
] |
08c12916f47e27935b7d6da3445884efe09a4ccd | 4,906 | cpp | C++ | third_party/gfootball_engine/src/base/properties.cpp | mahi97/football | 18d51cb110034ce7080b2ccce14a2539d2a04af3 | [
"Apache-2.0"
] | 3 | 2019-06-20T05:47:02.000Z | 2019-08-25T05:04:11.000Z | third_party/gfootball_engine/src/base/properties.cpp | AzharMithani/football | 0f09bcb8b3d48ac31987e13739e21a58ef0ca405 | [
"Apache-2.0"
] | 1 | 2019-06-09T10:06:36.000Z | 2019-06-09T10:06:36.000Z | third_party/gfootball_engine/src/base/properties.cpp | nczempin/gfootball | 617e9cb6d48b4ac7187b9b3de68bd4ab44ea528e | [
"Apache-2.0"
] | 1 | 2019-06-09T12:42:28.000Z | 2019-06-09T12:42:28.000Z | // Copyright 2019 Google LLC & Bastiaan Konings
// 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.
// written by bastiaan konings schuiling 2008 - 2014
// this work is public domain. the code is undocumented, scruffy, untested, and should generally not be used for anything important.
// i do not offer support, so don't ask. to be used for inspiration :)
#include "properties.hpp"
#include "../defines.hpp"
#include "utils.hpp"
#include "log.hpp"
#include <fstream>
#include <iostream>
using namespace std;
namespace blunted {
std::string Properties::emptyString = "";
Properties::Properties() {
}
Properties::~Properties() {
}
bool Properties::Exists(const char *name) const {
auto iter = properties.find(std::string(name));
if (iter == properties.end()) {
return false;
} else {
return true;
}
}
void Properties::Set(const char *name, const std::string &value) {
properties[std::string(name)] = value;
}
void Properties::SetInt(const char *name, int value) {
std::string value_str = int_to_str(value);
Set(name, value_str);
}
void Properties::Set(const char *name, real value) {
std::string value_str = real_to_str(value);
Set(name, value_str);
}
void Properties::SetBool(const char *name, bool value) {
std::string value_str = value ? "true" : "false";
Set(name, value_str);
}
const std::string &Properties::Get(const char *name, const std::string &defaultValue) const {
auto iter = properties.find(std::string(name));
if (iter == properties.end()) {
return defaultValue;
} else {
return iter->second;
}
}
bool Properties::GetBool(const char *name, bool defaultValue) const {
auto iter = properties.find(std::string(name));
if (iter == properties.end()) {
return defaultValue;
} else {
if (iter->second.compare("true") == 0) return true; else return false;
}
}
real Properties::GetReal(const char *name, real defaultValue) const {
auto iter = properties.find(std::string(name));
if (iter == properties.end()) {
return defaultValue;
} else {
return atof(iter->second.c_str());
}
}
int Properties::GetInt(const char *name, int defaultValue) const {
auto iter = properties.find(std::string(name));
if (iter == properties.end()) {
return defaultValue;
} else {
return int(floor(atof(iter->second.c_str())));
}
}
void Properties::AddProperties(const Properties *userprops) {
if (!userprops) return;
const map_Properties *userpropdata = userprops->GetProperties();
map_Properties::const_iterator iter = userpropdata->begin();
while (iter != userpropdata->end()) {
properties[iter->first] = iter->second;
iter++;
}
}
void Properties::AddProperties(const Properties &userprops) {
const map_Properties *userpropdata = userprops.GetProperties();
map_Properties::const_iterator iter = userpropdata->begin();
while (iter != userpropdata->end()) {
properties[iter->first] = iter->second;
iter++;
}
}
const map_Properties *Properties::GetProperties() const {
return &properties;
}
void Properties::LoadFile(const std::string &filename) {
std::vector <std::string> content;
file_to_vector(filename, content);
int contentSize = content.size();
for (int i = 0; i < contentSize; i++) {
int param_start = content.at(i).find_first_of('"') + 1;
int param_end = content.at(i).find_first_of('"', param_start);
int value_start = content.at(i).find_first_of('"', param_end + 1) + 1;
int value_end = content.at(i).find_first_of('"', value_start);
std::string param, value;
if (param_start < param_end && value_start < value_end && param_end < value_start) {
param = content.at(i).substr(param_start, param_end - param_start);
value = content.at(i).substr(value_start, value_end - value_start);
this->Set(param.c_str(), value);
}
}
}
void Properties::SaveFile(const std::string &filename) const {
ofstream cfile;
cfile.open(filename.c_str(), ios::out);
map_Properties::const_iterator iter = properties.begin();
while (iter != properties.end()) {
std::string bla = "\"" + iter->first + "\" \"" + iter->second + "\"\n";
cfile << bla.c_str();
iter++;
}
cfile.close();
}
}
| 30.09816 | 132 | 0.655524 | [
"vector"
] |
c09ff6eb16062ce7dba2cc7c02baa0b12fa93a52 | 687 | cpp | C++ | Dataset/Leetcode/train/62/203.cpp | kkcookies99/UAST | fff81885aa07901786141a71e5600a08d7cb4868 | [
"MIT"
] | null | null | null | Dataset/Leetcode/train/62/203.cpp | kkcookies99/UAST | fff81885aa07901786141a71e5600a08d7cb4868 | [
"MIT"
] | null | null | null | Dataset/Leetcode/train/62/203.cpp | kkcookies99/UAST | fff81885aa07901786141a71e5600a08d7cb4868 | [
"MIT"
] | null | null | null | class Solution {
public:
int XXX(int m, int n)
{
vector<vector<int>> ans(m,vector<int>(n));
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(i==0&&j==0)
{
ans[i][j]=1;
}
else if(i==0)
{
ans[i][j]=ans[i][j-1];
}
else if(j==0)
{
ans[i][j]=ans[i-1][j];
}
else
{
ans[i][j]=ans[i-1][j]+ans[i][j-1];
}
}
}
return ans[m-1][n-1];
}
};
| 20.818182 | 50 | 0.244541 | [
"vector"
] |
c0a1f676250879727c7111c9a71c6d7ff99813ab | 12,150 | cpp | C++ | src/label.cpp | gamobink/anura | 410721a174aae98f32a55d71a4e666ad785022fd | [
"CC0-1.0"
] | null | null | null | src/label.cpp | gamobink/anura | 410721a174aae98f32a55d71a4e666ad785022fd | [
"CC0-1.0"
] | null | null | null | src/label.cpp | gamobink/anura | 410721a174aae98f32a55d71a4e666ad785022fd | [
"CC0-1.0"
] | null | null | null | /*
Copyright (C) 2003-2014 by David White <davewx7@gmail.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 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 <iostream>
#include "Canvas.hpp"
#include "Font.hpp"
#include "button.hpp"
#include "color_picker.hpp"
#include "dropdown_widget.hpp"
#include "grid_widget.hpp"
#include "i18n.hpp"
#include "input.hpp"
#include "label.hpp"
#include "slider.hpp"
#include "text_editor_widget.hpp"
#include "widget_settings_dialog.hpp"
namespace gui
{
namespace
{
const int default_font_size = 14;
}
Label::Label(const std::string& text, int size, const std::string& font)
: text_(i18n::tr(text)),
border_size_(0),
size_(size),
down_(false),
fixed_width_(false),
highlight_color_(KRE::Color::colorRed()),
highlight_on_mouseover_(false),
draw_highlight_(false),
font_(font)
{
setEnvironment();
recalculateTexture();
}
Label::Label(const std::string& text, const KRE::Color& color, int size, const std::string& font)
: text_(i18n::tr(text)),
border_size_(0),
size_(size),
down_(false),
font_(font),
fixed_width_(false),
highlight_color_(KRE::Color::colorRed()),
highlight_on_mouseover_(false),
draw_highlight_(false)
{
setColor(color);
setEnvironment();
recalculateTexture();
}
Label::Label(const variant& v, game_logic::FormulaCallable* e)
: Widget(v,e),
fixed_width_(false),
down_(false),
highlight_color_(KRE::Color::colorRed()),
draw_highlight_(false),
font_(v["font"].as_string_default())
{
text_ = i18n::tr(v["text"].as_string());
if(v.has_key("border_color")) {
border_color_.reset(new KRE::Color(v["border_color"]));
if(v.has_key("border_size")) {
border_size_ = v["border_size"].as_int();
} else {
border_size_ = 2;
}
}
size_ = v.has_key("size") ? v["size"].as_int() : default_font_size;
if(v.has_key("on_click")) {
ASSERT_LOG(getEnvironment() != 0, "You must specify a callable environment");
ffl_click_handler_ = getEnvironment()->createFormula(v["on_click"]);
on_click_ = std::bind(&Label::clickDelegate, this);
}
if(v.has_key("highlight_color")) {
highlight_color_ = KRE::Color(v["highlight_color"]);
}
highlight_on_mouseover_ = v["highlight_on_mouseover"].as_bool(false);
setClaimMouseEvents(v["claim_mouse_events"].as_bool(false));
recalculateTexture();
}
Label::Label(const Label& l)
: Widget(l),
text_(l.text_),
formatted_(l.formatted_),
texture_(l.texture_),
border_texture_(l.border_texture_),
border_size_(l.border_size_),
highlight_color_(l.highlight_color_),
border_color_(l.border_color_ ? new KRE::Color(*l.border_color_) : nullptr),
size_(l.size_),
font_(l.font_),
fixed_width_(l.fixed_width_),
on_click_(l.on_click_),
ffl_click_handler_(l.ffl_click_handler_),
highlight_on_mouseover_(l.highlight_on_mouseover_),
draw_highlight_(l.draw_highlight_),
down_(l.down_)
{
}
void Label::clickDelegate()
{
if(getEnvironment()) {
variant value = ffl_click_handler_->execute(*getEnvironment());
getEnvironment()->executeCommand(value);
} else {
LOG_ERROR("Label::clickDelegate() called without environment!");
}
}
void Label::setFontSize(int size)
{
size_ = size;
recalculateTexture();
}
void Label::setFont(const std::string& font)
{
font_ = font;
recalculateTexture();
}
void Label::setText(const std::string& text)
{
text_ = i18n::tr(text);
reformatText();
recalculateTexture();
}
std::string& Label::currentText() {
if(fixed_width_) {
return formatted_;
}
return text_;
}
const std::string& Label::currentText() const {
if(fixed_width_) {
return formatted_;
}
return text_;
}
void Label::setFixedWidth(bool fixed_width)
{
fixed_width_ = fixed_width;
reformatText();
recalculateTexture();
}
void Label::setDim(int w, int h) {
if(w != width() || h != height()) {
innerSetDim(w, h);
reformatText();
recalculateTexture();
}
}
void Label::handleColorChanged()
{
recalculateTexture();
}
void Label::innerSetDim(int w, int h) {
Widget::setDim(w, h);
}
void Label::reformatText()
{
if(fixed_width_) {
formatted_ = text_;
}
}
void Label::recalculateTexture()
{
if(!currentText().empty()) {
texture_ = KRE::Font::getInstance()->renderText(currentText(), getColor(), size_, true, font_);
innerSetDim(texture_->width(), texture_->height());
} else {
texture_.reset();
}
if(border_color_) {
border_texture_ = KRE::Font::getInstance()->renderText(currentText(), *border_color_, size_, true, font_);
}
}
void Label::handleDraw() const
{
if(draw_highlight_) {
KRE::Canvas::getInstance()->drawSolidRect(rect(x(), y(), width(), height()), highlight_color_);
}
if(border_texture_) {
KRE::Canvas::getInstance()->blitTexture(border_texture_, 0, rect(x() - border_size_, y()));
KRE::Canvas::getInstance()->blitTexture(border_texture_, 0, rect(x() + border_size_, y()));
KRE::Canvas::getInstance()->blitTexture(border_texture_, 0, rect(x(), y() - border_size_));
KRE::Canvas::getInstance()->blitTexture(border_texture_, 0, rect(y() + border_size_));
}
if(texture_) {
KRE::Canvas::getInstance()->blitTexture(texture_, 0, rect(x(), y()));
}
}
void Label::setTexture(KRE::TexturePtr t) {
texture_ = t;
}
bool Label::handleEvent(const SDL_Event& event, bool claimed)
{
if(!on_click_ && !highlight_on_mouseover_) {
return claimed;
}
if((event.type == SDL_MOUSEWHEEL) && inWidget(event.button.x, event.button.y)) {
// skip processing if mousewheel event
return claimed;
}
if(event.type == SDL_MOUSEMOTION) {
const SDL_MouseMotionEvent& e = event.motion;
if(highlight_on_mouseover_) {
if(inWidget(e.x,e.y)) {
draw_highlight_ = true;
} else {
draw_highlight_ = false;
}
claimed = claimMouseEvents();
}
} else if(event.type == SDL_MOUSEBUTTONDOWN) {
const SDL_MouseButtonEvent& e = event.button;
if(inWidget(e.x,e.y)) {
down_ = true;
claimed = claimMouseEvents();
}
} else if(event.type == SDL_MOUSEBUTTONUP) {
down_ = false;
const SDL_MouseButtonEvent& e = event.button;
if(inWidget(e.x,e.y)) {
if(on_click_) {
on_click_();
}
claimed = claimMouseEvents();
}
}
return claimed;
}
variant Label::handleWrite()
{
variant_builder res;
res.add("type", "Label");
res.add("text", text());
if(size() != default_font_size) {
res.add("size", size());
}
if(font().empty() == false) {
res.add("font", font());
}
if(border_color_) {
res.add("border_color", border_color_->write());
if(border_size_ != 2) {
res.add("border_size", border_size_);
}
}
if(highlight_on_mouseover_) {
res.add("highlight_on_mouseover", true);
}
if(claimMouseEvents()) {
res.add("claim_mouse_events", true);
}
return res.build();
}
WidgetSettingsDialog* Label::settingsDialog(int x, int y, int w, int h)
{
WidgetSettingsDialog* d = Widget::settingsDialog(x,y,w,h);
/*
grid_ptr g(new grid(2));
TextEditorWidgetPtr text_edit = new TextEditorWidget(150, 30);
text_edit->setText(text());
text_edit->setOnUserChangeHandler([=](){setText(text_edit->text());});
g->addCol(new Label("Text:", d->getTextSize(), d->font()))
.addCol(text_edit);
g->addCol(new Label("Size:", d->getTextSize(), d->font())).
addCol(new Slider(120, [&](float f){setFontSize(static_cast<int>(f*72.0f+6.0f));}, (size()-6.0f)/72.0f, 1));
std::vector<std::string> fonts = font::getAvailableFonts();
fonts.insert(fonts.begin(), "");
DropdownWidgetPtr font_list(new DropdownWidget(fonts, 150, 28, dropdown_widget::DROPDOWN_LIST));
font_list->setFontSize(14);
font_list->setDropdownHeight(height());
auto fit = std::find(fonts.begin(), fonts.end(), font());
font_list->setSelection(fit == fonts.end() ? 0 : fit-fonts.begin());
font_list->setOnSelectHandler([&](int n, const std::string& s){setFont(s);});
font_list->setZOrder(19);
g->addCol(new Label("Font:", d->getTextSize(), d->font()))
.addCol(font_list);
g->addCol(new Label("Color:", d->getTextSize(), d->font()))
.addCol(new button(new Label("Choose...", d->getTextSize(), d->font()), [&](){
int mx, my;
input::sdl_get_mouse_state(&mx, &my);
mx = mx + 200 > preferences::actual_screen_width() ? preferences::actual_screen_width()-200 : mx;
my = my + 600 > preferences::actual_screen_height() ? preferences::actual_screen_height()-600 : my;
my -= d->y();
ColorPicker* cp = new ColorPicker(rect(0, 0, 200, 600), [&](const graphics::color& color){setColor(color.as_sdl_color());});
cp->setPrimaryColor(graphics::color(color_));
grid_ptr gg = new grid(1);
gg->allowSelection();
gg->swallowClicks();
gg->setShowBackground(true);
gg->allowDrawHighlight(false);
gg->registerSelectionCallback([=](int n){if(n != 0){d->removeWidget(gg); d->init();}});
gg->setZOrder(100);
gg->addCol(cp);
d->addWidget(gg, d->x()-mx-100, my);
}));
d->addWidget(g);*/
return d;
}
WidgetPtr Label::clone() const
{
return WidgetPtr(new Label(*this));
}
BEGIN_DEFINE_CALLABLE(Label, Widget)
DEFINE_FIELD(text, "string")
return variant(obj.text_);
DEFINE_SET_FIELD
if(value.is_null()) {
obj.setText("");
} else {
obj.setText(value.as_string());
}
DEFINE_FIELD(size, "int")
return variant(obj.size_);
DEFINE_SET_FIELD
obj.setFontSize(value.as_int());
DEFINE_FIELD(font, "string")
return variant(obj.font_);
DEFINE_SET_FIELD
obj.setFont(value.as_string());
DEFINE_FIELD(color, "string")
return variant();
DEFINE_SET_FIELD
obj.setColor(KRE::Color(value));
END_DEFINE_CALLABLE(Label)
DialogLabel::DialogLabel(const std::string& text, const KRE::Color& color, int size)
: Label(text, color, size),
progress_(0)
{
recalculateTexture();
}
DialogLabel::DialogLabel(const variant& v, game_logic::FormulaCallable* e)
: Label(v, e),
progress_(0)
{
recalculateTexture();
}
void DialogLabel::setProgress(int progress)
{
progress_ = progress;
recalculateTexture();
}
void DialogLabel::recalculateTexture()
{
Label::recalculateTexture();
stages_ = static_cast<int>(currentText().size());
int prog = progress_;
if(prog < 0) prog = 0;
if(prog > stages_) prog = stages_;
std::string txt = currentText().substr(0, prog);
if(prog > 0) {
setTexture(KRE::Font::getInstance()->renderText(txt, getColor(), size(), false, font()));
} else {
setTexture(KRE::TexturePtr());
}
}
WidgetPtr DialogLabel::clone() const
{
return WidgetPtr(new DialogLabel(*this));
}
BEGIN_DEFINE_CALLABLE(DialogLabel, Label)
DEFINE_FIELD(progress, "int")
return variant(obj.progress_);
DEFINE_SET_FIELD
obj.setProgress(value.as_int());
DEFINE_FIELD(stages, "int")
return variant(obj.stages_);
DEFINE_SET_FIELD
obj.stages_ = value.as_int();
END_DEFINE_CALLABLE(DialogLabel)
LabelFactory::LabelFactory(const KRE::Color& color, int size)
: color_(color), size_(size)
{}
LabelPtr LabelFactory::create(const std::string& text) const
{
return LabelPtr(new Label(text, color_, size_));
}
LabelPtr LabelFactory::create(const std::string& text, const std::string& tip) const
{
const LabelPtr res(create(text));
res->setTooltip(tip);
return res;
}
}
| 26.821192 | 128 | 0.67358 | [
"vector"
] |
c0a2a6a4a2805fc65066480e44a1e35814e8a08e | 513 | cc | C++ | ash/assistant/model/ui/assistant_timers_element.cc | sarang-apps/darshan_browser | 173649bb8a7c656dc60784d19e7bb73e07c20daa | [
"BSD-3-Clause-No-Nuclear-License-2014",
"BSD-3-Clause"
] | null | null | null | ash/assistant/model/ui/assistant_timers_element.cc | sarang-apps/darshan_browser | 173649bb8a7c656dc60784d19e7bb73e07c20daa | [
"BSD-3-Clause-No-Nuclear-License-2014",
"BSD-3-Clause"
] | null | null | null | ash/assistant/model/ui/assistant_timers_element.cc | sarang-apps/darshan_browser | 173649bb8a7c656dc60784d19e7bb73e07c20daa | [
"BSD-3-Clause-No-Nuclear-License-2014",
"BSD-3-Clause"
] | null | null | null | // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/assistant/model/ui/assistant_timers_element.h"
namespace ash {
AssistantTimersElement::AssistantTimersElement(
const std::vector<std::string>& timer_ids)
: AssistantUiElement(AssistantUiElementType::kTimers),
timer_ids_(timer_ids) {}
AssistantTimersElement::~AssistantTimersElement() = default;
} // namespace ash
| 30.176471 | 73 | 0.766082 | [
"vector",
"model"
] |
c0a2a7036bc7693c6ba51be39895bf6c04af5f0e | 485 | hh | C++ | elec/GridRouter.hh | paulkefer/cardioid | 59c07b714d8b066b4f84eb50487c36f6eadf634c | [
"MIT-0",
"MIT"
] | 33 | 2018-12-12T20:05:06.000Z | 2021-09-26T13:30:16.000Z | elec/GridRouter.hh | paulkefer/cardioid | 59c07b714d8b066b4f84eb50487c36f6eadf634c | [
"MIT-0",
"MIT"
] | 5 | 2019-04-25T11:34:43.000Z | 2021-11-14T04:35:37.000Z | elec/GridRouter.hh | paulkefer/cardioid | 59c07b714d8b066b4f84eb50487c36f6eadf634c | [
"MIT-0",
"MIT"
] | 15 | 2018-12-21T22:44:59.000Z | 2021-08-29T10:30:25.000Z | #ifndef GRIDROUTER_H
#define GRIDROUTER_H
#include <mpi.h>
#include <vector>
#include "Long64.hh"
class CommTable;
class GridRouter
{
private:
int selfTest();
MPI_Comm comm_;
std::vector<int> sendRank_;
std::vector<int> sendOffset_;
std::vector<int> sendMap_;
public:
GridRouter(std::vector<Long64>& gid, int nx, int ny, int nz, MPI_Comm comm);
CommTable commTable() const;
const std::vector<int>& sendMap() const {return sendMap_;}
};
#endif
| 16.724138 | 79 | 0.682474 | [
"vector"
] |
c0a8fdc2abc92e757c0d515290bdd6e4b88ef5df | 2,955 | cc | C++ | pop_shots/src/source/level.cc | onqtam/old-stuff | 6ee0fbb36463525977caad8b66192292a73ac4d1 | [
"MIT"
] | 4 | 2016-10-12T15:53:58.000Z | 2020-12-22T16:28:23.000Z | pop_shots/src/source/level.cc | onqtam/fun-stuff | 6ee0fbb36463525977caad8b66192292a73ac4d1 | [
"MIT"
] | 1 | 2016-01-26T13:14:40.000Z | 2016-01-26T13:14:40.000Z | pop_shots/src/source/level.cc | onqtam/fun-stuff | 6ee0fbb36463525977caad8b66192292a73ac4d1 | [
"MIT"
] | 2 | 2019-02-08T12:59:54.000Z | 2019-10-11T10:40:24.000Z | /******************************************************************************
* *
* POP SHOTS. *
* *
* Technological School Electronic Systems *
* Technical University of Sofia *
* *
* Copyright (C) 2009-2010 Viktor Kirilov ( n1ntendo@abv.bg ) *
* *
******************************************************************************/
#include "../include/level.h"
#include "../include/engine.h"
#include "../include/camera.h"
Level::Level() :
map(NULL),
destructive(true) {
map = NULL;
}
Level::~Level() {
if ( map != NULL) {
SDL_FreeSurface(map);
}
}
bool Level::setMap(string arg_mapName) {
if ( map != NULL ) {
SDL_FreeSurface(map);
}
map = SDL_DisplayFormat(IMG_Load(arg_mapName.c_str()));
SDL_SetColorKey(map, SDL_SRCCOLORKEY, SDL_MapRGB(map->format, 240, 240, 240));
collision.set(map);
return true;
}
void Level::toggleLevelDestruction() {
destructive = !destructive;
}
void Level::makeCollisionOnSides(vector<Side::side>& sides, int thickness) {
for ( unsigned int i = 0; i < sides.size(); i++ ) {
switch (sides[i]) {
case Side::left:
Engine::engine->logic.level.collision.setRect(0, 0, thickness, getHeight(), 1);
break;
case Side::right:
Engine::engine->logic.level.collision.setRect(getWidth() - thickness, 0, thickness, getHeight(), 1);
break;
case Side::top:
collision.setRect(0,0,getWidth(),thickness,1);
break;
case Side::bottom:
Engine::engine->logic.level.collision.setRect(0, getHeight() - thickness, getWidth(), thickness,1);
break;
};
}
}
void Level::drawSides(vector<Side::side>& sides, Uint32 col, int thickness) {
SDL_Rect area;
for ( unsigned int i = 0; i < sides.size(); i++ ) {
switch (sides[i]) {
case Side::left:
area.x = 0;
area.y = 0;
area.w = thickness;
area.h = getHeight();
SDL_FillRect(map, &area, col);
break;
case Side::right:
area.x = getWidth() - thickness;
area.y = 0;
area.w = thickness;
area.h = getHeight();
SDL_FillRect(map, &area, col);
break;
case Side::top:
area.x = 0;
area.y = 0;
area.w = getWidth();
area.h = thickness;
SDL_FillRect(map, &area, col);
break;
case Side::bottom:
area.x = 0;
area.y = getHeight() - thickness;
area.w = getWidth();
area.h = thickness;
SDL_FillRect(map, &area, col);
break;
};
}
}
| 25.695652 | 104 | 0.462267 | [
"vector"
] |
c0c1cf6a7011bd31eb4b5f4abd9fc87da5d944c5 | 3,434 | cpp | C++ | src/library/ComputeModuleDefinition.cpp | charlesrwest/Caffe2ComputeModules | 7d9d67159bf84b7611211945d0d7e26f5c3614ab | [
"BSD-2-Clause"
] | 6 | 2017-08-01T07:35:07.000Z | 2018-01-02T13:25:03.000Z | src/library/ComputeModuleDefinition.cpp | charlesrwest/Caffe2ComputeModules | 7d9d67159bf84b7611211945d0d7e26f5c3614ab | [
"BSD-2-Clause"
] | 2 | 2017-10-04T02:13:50.000Z | 2017-10-04T03:11:58.000Z | src/library/ComputeModuleDefinition.cpp | charlesrwest/Caffe2ComputeModules | 7d9d67159bf84b7611211945d0d7e26f5c3614ab | [
"BSD-2-Clause"
] | null | null | null | #include "ComputeModuleDefinition.hpp"
#include "UtilityFunctions.hpp"
#include<algorithm>
#include<iostream>
using namespace GoodBot;
void ComputeModuleDefinition::SetName(const std::string& inputName)
{
name = inputName;
}
std::string ComputeModuleDefinition::Name() const
{
return name;
}
bool ComputeModuleDefinition::SetMode(const std::string& inputMode)
{
mode = inputMode;
return true;
}
std::string ComputeModuleDefinition::Mode() const
{
return mode;
}
std::vector<std::string> ComputeModuleDefinition::GetInputBlobNames() const
{
return {};
}
std::vector<std::string> ComputeModuleDefinition::GetOutputBlobNames() const
{
return {};
}
std::vector<std::string> ComputeModuleDefinition::GetTrainableBlobNames() const
{
return {};
}
std::vector<std::vector<int64_t>> ComputeModuleDefinition::GetTrainableBlobShapes() const
{
return {};
}
std::vector<std::string> ComputeModuleDefinition::GetGradientBlobNames() const
{
std::vector<caffe2::OperatorDef> gradientOperators = GetGradientOperators();
std::vector<std::string> results;
for(const caffe2::OperatorDef& gradientOperator : gradientOperators)
{
for(int64_t outputIndex = 0; outputIndex < gradientOperator.output_size(); outputIndex++)
{
results.emplace_back(gradientOperator.output(outputIndex));
}
}
//remove any redundant blob names
std::sort(results.begin(), results.end());
results.erase(std::unique(results.begin(), results.end()));
return results;
}
std::vector<caffe2::OperatorDef> ComputeModuleDefinition::GetNetworkOperators() const
{
return {};
}
std::vector<caffe2::OperatorDef> ComputeModuleDefinition::GetNetworkInitializationOperators() const
{
return {};
}
std::vector<caffe2::OperatorDef> ComputeModuleDefinition::GetGradientOperators() const
{
std::vector<caffe2::OperatorDef> result;
std::vector<caffe2::OperatorDef> networkOperators = GetNetworkOperators();
//Reverse the order and make a gradient operator for each network operator
for(std::vector<caffe2::OperatorDef>::reverse_iterator iter = networkOperators.rbegin(); iter != networkOperators.rend(); iter++ )
{
std::vector<caffe2::OperatorDef> gradientOperators = GetGradientOperatorsFromOperator(*iter);
result.insert(result.end(), gradientOperators.begin(), gradientOperators.end());
}
return result;
}
caffe2::NetDef ComputeModuleDefinition::GetInitializationNetwork() const
{
caffe2::NetDef network;
network.set_name(Name() + "_" + Mode() + "_init");
std::vector<caffe2::OperatorDef> initOperators = GetNetworkInitializationOperators();
for(const caffe2::OperatorDef& operatorDefinition : initOperators)
{
*network.add_op() = operatorDefinition; //Add to network
}
return network;
}
caffe2::NetDef ComputeModuleDefinition::GetNetwork(const std::vector<std::string>& inputPreviouslyExistingBlobNames) const
{
caffe2::NetDef network;
network.set_name(Name() + "_" + Mode());
std::vector<caffe2::OperatorDef> networkOperators = GetNetworkOperators();
if(mode == "TRAIN")
{
//Add any gradient calculations to the network too
std::vector<caffe2::OperatorDef> gradientOperators = GetGradientOperators();
networkOperators.insert(networkOperators.end(), gradientOperators.begin(), gradientOperators.end());
}
networkOperators = ReorderOperatorsToResolveDependencies(networkOperators, inputPreviouslyExistingBlobNames);
for(const caffe2::OperatorDef& operatorDefinition : networkOperators)
{
*network.add_op() = operatorDefinition; //Add to network
}
return network;
}
| 25.065693 | 130 | 0.778975 | [
"vector"
] |
c0c2fe6aba9932c1b13ce87770f44125be1fa84c | 3,638 | cpp | C++ | Codeforces/ICPC Team Prep/2015 Damascus/I.cpp | Mindjolt2406/Competitive-Programming | d000d98bf7005ee4fb809bcea2f110e4c4793b80 | [
"MIT"
] | 2 | 2018-12-11T14:37:24.000Z | 2022-01-23T18:11:54.000Z | Codeforces/ICPC Team Prep/2015 Damascus/I.cpp | Mindjolt2406/Competitive-Programming | d000d98bf7005ee4fb809bcea2f110e4c4793b80 | [
"MIT"
] | null | null | null | Codeforces/ICPC Team Prep/2015 Damascus/I.cpp | Mindjolt2406/Competitive-Programming | d000d98bf7005ee4fb809bcea2f110e4c4793b80 | [
"MIT"
] | null | null | null | /*
Rathin Bhargava
IIIT Bangalore
*/
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 4e9+1
#define MOD 1000000007
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x) cerr<<#x<<" : "<<x<<endl
#define t2(x, y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z) cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d) cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e) cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f) cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; }
const int N = 102;
vector<pair<ll,ll> > adj[N] = {};
void path(int n,int u,vector<ll> &dist)
{
set<pair<ll,ll> > pq;
pq.insert(mp(0,u));
dist[u] = 0;
while(!pq.empty())
{
pair<ll,ll> temp = (*pq.begin());
int u = temp.se;
pq.erase(temp);
for(auto p : adj[u])
{
ll v = p.se, weight = p.fi;
if(dist[v]> dist[u]+weight)
{
pq.erase(mp(dist[v],v));
dist[v] = dist[u] + weight;
pq.insert(mp(dist[v],v));
}
}
}
}
ll min(ld x, ld y)
{
if(x<y) return x;
return y;
}
ld dis1(ll x1, ll y1, ll x2, ll y2)
{
return sqrt(abs(x1-x2)*abs(x1-x2) + abs(y1-y2)*abs(y1-y2));
}
ll dis2(ll x1, ll y1, ll x2, ll y2)
{
return abs(x1-x2) + abs(y1-y2);
}
int main()
{
__;
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
vector<vector<ll> > w;
vector<ll> dist(n+2,INF);
for(int i=0;i<n;i++)
{
ll a,b,c;
cin >> a >> b >> c;
w.pu({a,b,c});
}
ll x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
w.pu({x1,y1,0});
w.pu({x2,y2,0});
for(int i=0;i<w.size();i++)
{
ll p = w[i][2];
for(int j=0;j<w.size();j++)
{
if(i==j) continue;
ld d1 = dis1(w[i][0],w[i][1],w[j][0],w[j][1]);
ll d2 = dis2(w[i][0],w[i][1],w[j][0],w[j][1]);
// t(i,j,d1,d2);
if(d1<=p)
{
if(2LL<d2) adj[i].pu(mp(2,j));
// adj[i].pu(mp(d2,j));
}
adj[i].pu(mp(d2,j));
}
}
// for(int i=0;i<n;i++) t(adj[i]);
path(n+2,n,dist);
// for(int i=0;i<=n+1;i++) cout << dist[i] << " "; cout << endl;
cout << dist[n+1] << endl;
for(int i=0;i<n+2;i++) adj[i].clear();
// memset(adj,0,sizeof(adj));
}
return 0;
}
/*
2
3
5 5 5
9 5 3
11 7 2
4 6 11 8
3
5 5 5
9 5 3
11 7 2
4 6 11 8
*/
| 24.416107 | 226 | 0.45602 | [
"vector"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.