本文整理汇总了C++中Vec::at方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec::at方法的具体用法?C++ Vec::at怎么用?C++ Vec::at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vec
的用法示例。
在下文中一共展示了Vec::at方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SourceToDoc
int Pdfsync::SourceToDoc(const WCHAR* srcfilename, UINT line, UINT col, UINT* page, Vec<RectI>& rects) {
if (IsIndexDiscarded())
if (RebuildIndex() != PDFSYNCERR_SUCCESS)
return PDFSYNCERR_SYNCFILE_CANNOT_BE_OPENED;
Vec<size_t> found_records;
UINT ret = SourceToRecord(srcfilename, line, col, found_records);
if (ret != PDFSYNCERR_SUCCESS || found_records.size() == 0)
return ret;
rects.Reset();
// records have been found for the desired source position:
// we now find the page and positions in the PDF corresponding to these found records
UINT firstPage = UINT_MAX;
for (size_t i = 0; i < points.size(); i++) {
if (!found_records.Contains(points.at(i).record))
continue;
if (firstPage != UINT_MAX && firstPage != points.at(i).page)
continue;
firstPage = *page = points.at(i).page;
RectD rc(SYNC_TO_PDF_COORDINATE(points.at(i).x), SYNC_TO_PDF_COORDINATE(points.at(i).y), MARK_SIZE, MARK_SIZE);
// PdfSync coordinates are y-inversed
RectD mbox = engine->PageMediabox(firstPage);
rc.y = mbox.dy - (rc.y + rc.dy);
rects.Push(rc.Round());
}
if (rects.size() > 0)
return PDFSYNCERR_SUCCESS;
// the record does not correspond to any point in the PDF: this is possible...
return PDFSYNCERR_NOSYNCPOINT_FOR_LINERECORD;
}
示例2: DocToSource
int Pdfsync::DocToSource(UINT pageNo, PointI pt, AutoFreeW& filename, UINT* line, UINT* col) {
if (IsIndexDiscarded())
if (RebuildIndex() != PDFSYNCERR_SUCCESS)
return PDFSYNCERR_SYNCFILE_CANNOT_BE_OPENED;
// find the entry in the index corresponding to this page
if (pageNo <= 0 || pageNo >= sheetIndex.size() || pageNo > (UINT)engine->PageCount())
return PDFSYNCERR_INVALID_PAGE_NUMBER;
// PdfSync coordinates are y-inversed
RectI mbox = engine->PageMediabox(pageNo).Round();
pt.y = mbox.dy - pt.y;
// distance to the closest pdf location (in the range <PDFSYNC_EPSILON_SQUARE)
UINT closest_xydist = UINT_MAX;
UINT selected_record = UINT_MAX;
// If no record is found within a distance^2 of PDFSYNC_EPSILON_SQUARE
// (selected_record == -1) then we pick up the record that is closest
// vertically to the hit-point.
UINT closest_ydist = UINT_MAX; // vertical distance between the hit point and the vertically-closest record
UINT closest_xdist = UINT_MAX; // horizontal distance between the hit point and the vertically-closest record
UINT closest_ydist_record = UINT_MAX; // vertically-closest record
// read all the sections of 'p' declarations for this pdf sheet
for (size_t i = sheetIndex.at(pageNo); i < points.size() && points.at(i).page == pageNo; i++) {
// check whether it is closer than the closest point found so far
UINT dx = abs(pt.x - (int)SYNC_TO_PDF_COORDINATE(points.at(i).x));
UINT dy = abs(pt.y - (int)SYNC_TO_PDF_COORDINATE(points.at(i).y));
UINT dist = dx * dx + dy * dy;
if (dist < PDFSYNC_EPSILON_SQUARE && dist < closest_xydist) {
selected_record = points.at(i).record;
closest_xydist = dist;
} else if ((closest_xydist == UINT_MAX) && dy < PDFSYNC_EPSILON_Y &&
(dy < closest_ydist || (dy == closest_ydist && dx < closest_xdist))) {
closest_ydist_record = points.at(i).record;
closest_ydist = dy;
closest_xdist = dx;
}
}
if (selected_record == UINT_MAX)
selected_record = closest_ydist_record;
if (selected_record == UINT_MAX)
return PDFSYNCERR_NO_SYNC_AT_LOCATION; // no record was found close enough to the hit point
// We have a record number, we need to find its declaration ('l ...') in the syncfile
PdfsyncLine cmp;
cmp.record = selected_record;
PdfsyncLine* found =
(PdfsyncLine*)bsearch(&cmp, lines.LendData(), lines.size(), sizeof(PdfsyncLine), cmpLineRecords);
AssertCrash(found);
if (!found)
return PDFSYNCERR_NO_SYNC_AT_LOCATION;
filename.SetCopy(srcfiles.at(found->file));
*line = found->line;
*col = found->column;
return PDFSYNCERR_SUCCESS;
}
示例3: IsInRange
static bool IsInRange(Vec<PageRange>& ranges, int pageNo) {
for (size_t i = 0; i < ranges.size(); i++) {
if (ranges.at(i).start <= pageNo && pageNo <= ranges.at(i).end)
return true;
}
return false;
}
示例4: BenchFile
static void BenchFile(const WCHAR* filePath, const WCHAR* pagesSpec) {
if (!file::Exists(filePath)) {
return;
}
// ad-hoc: if enabled times layout instead of rendering and does layout
// using all text rendering methods, so that we can compare and find
// docs that take a long time to load
if (Doc::IsSupportedFile(filePath) && !gGlobalPrefs->ebookUI.useFixedPageUI) {
BenchEbookLayout(filePath);
return;
}
if (ChmModel::IsSupportedFile(filePath) && !gGlobalPrefs->chmUI.useFixedPageUI) {
BenchChmLoadOnly(filePath);
return;
}
Timer total;
logbench(L"Starting: %s", filePath);
Timer t;
BaseEngine* engine = EngineManager::CreateEngine(filePath);
if (!engine) {
logbench(L"Error: failed to load %s", filePath);
return;
}
double timeMs = t.Stop();
logbench(L"load: %.2f ms", timeMs);
int pages = engine->PageCount();
logbench(L"page count: %d", pages);
if (nullptr == pagesSpec) {
for (int i = 1; i <= pages; i++) {
BenchLoadRender(engine, i);
}
}
AssertCrash(!pagesSpec || IsBenchPagesInfo(pagesSpec));
Vec<PageRange> ranges;
if (ParsePageRanges(pagesSpec, ranges)) {
for (size_t i = 0; i < ranges.size(); i++) {
for (int j = ranges.at(i).start; j <= ranges.at(i).end; j++) {
if (1 <= j && j <= pages)
BenchLoadRender(engine, j);
}
}
}
delete engine;
total.Stop();
logbench(L"Finished (in %.2f ms): %s", total.GetTimeInMs(), filePath);
}
示例5: RandomizeFiles
// Select random files to test. We want to test each file type equally, so
// we first group them by file extension and then select up to maxPerType
// for each extension, randomly, and inter-leave the files with different
// extensions, so their testing is evenly distributed.
// Returns result in <files>.
static void RandomizeFiles(WStrVec& files, int maxPerType) {
WStrVec fileExts;
Vec<WStrVec*> filesPerType;
for (size_t i = 0; i < files.size(); i++) {
const WCHAR* file = files.at(i);
const WCHAR* ext = path::GetExt(file);
CrashAlwaysIf(!ext);
int typeNo = fileExts.FindI(ext);
if (-1 == typeNo) {
fileExts.Append(str::Dup(ext));
filesPerType.Append(new WStrVec());
typeNo = (int)filesPerType.size() - 1;
}
filesPerType.at(typeNo)->Append(str::Dup(file));
}
for (size_t j = 0; j < filesPerType.size(); j++) {
WStrVec* all = filesPerType.at(j);
WStrVec* random = new WStrVec();
for (int n = 0; n < maxPerType && all->size() > 0; n++) {
int idx = rand() % all->size();
WCHAR* file = all->at(idx);
random->Append(file);
all->RemoveAtFast(idx);
}
filesPerType.at(j) = random;
delete all;
}
files.Reset();
bool gotAll = false;
while (!gotAll) {
gotAll = true;
for (size_t j = 0; j < filesPerType.size(); j++) {
WStrVec* random = filesPerType.at(j);
if (random->size() > 0) {
gotAll = false;
WCHAR* file = random->at(0);
files.Append(file);
random->RemoveAtFast(0);
}
}
}
for (size_t j = 0; j < filesPerType.size(); j++) {
delete filesPerType.at(j);
}
}
示例6: addCoord
// add offset to coordinate in dimension d of index i
long addCoord(long i, long d, long offset) const {
assert(i >= 0 && i < size);
offset = offset % dims.at(d);
if (offset < 0) offset += dims.at(d);
long i_d = getCoord(i, d);
long i_d1 = (i_d + offset) % dims.at(d);
long i1 = i + (i_d1 - i_d) * prods.at(d+1);
return i1;
}
示例7: applyPermToVec
void applyPermToVec(Vec<T>& out, const Vec<T>& in, const Permut& p1)
{
assert(&out != &in); // NOT an in-place procedure
out.SetLength(p1.length());
for (long i=0; i<p1.length(); i++)
out[i] = in.at(p1[i]);
}
示例8: Purge
// removes file history entries which shouldn't be saved anymore
// (see the loop below for the details)
void FileHistory::Purge(bool alwaysUseDefaultState) {
// minOpenCount is set to the number of times a file must have been
// opened to be kept (provided that there is no other valuable
// information about the file to be remembered)
int minOpenCount = 0;
if (alwaysUseDefaultState) {
Vec<DisplayState*> frequencyList;
GetFrequencyOrder(frequencyList);
if (frequencyList.size() > FILE_HISTORY_MAX_RECENT)
minOpenCount = frequencyList.at(FILE_HISTORY_MAX_FREQUENT)->openCount / 2;
}
for (size_t j = states->size(); j > 0; j--) {
DisplayState* state = states->at(j - 1);
// never forget pinned documents, documents we've remembered a password for and
// documents for which there are favorites
if (state->isPinned || state->decryptionKey != nullptr || state->favorites->size() > 0)
continue;
// forget about missing documents without valuable state
if (state->isMissing && (alwaysUseDefaultState || state->useDefaultState))
states->RemoveAt(j - 1);
// forget about files last opened longer ago than the last FILE_HISTORY_MAX_FILES ones
else if (j > FILE_HISTORY_MAX_FILES)
states->RemoveAt(j - 1);
// forget about files that were hardly used (and without valuable state)
else if (alwaysUseDefaultState && state->openCount < minOpenCount && j > FILE_HISTORY_MAX_RECENT)
states->RemoveAt(j - 1);
else
continue;
DeleteDisplayState(state);
}
}
示例9: SourceToRecord
// Find a record corresponding to the given source file, line number and optionally column number.
// (at the moment the column parameter is ignored)
//
// If there are several *consecutively declared* records for the same line then they are all returned.
// The list of records is added to the vector 'records'
//
// If there is no record for that line, the record corresponding to the nearest line is selected
// (within a range of EPSILON_LINE)
//
// The function returns PDFSYNCERR_SUCCESS if a matching record was found.
UINT Pdfsync::SourceToRecord(const WCHAR* srcfilename, UINT line, UINT col, Vec<size_t>& records) {
UNUSED(col);
if (!srcfilename)
return PDFSYNCERR_INVALID_ARGUMENT;
AutoFreeW srcfilepath;
// convert the source file to an absolute path
if (PathIsRelative(srcfilename))
srcfilepath.Set(PrependDir(srcfilename));
else
srcfilepath.SetCopy(srcfilename);
if (!srcfilepath)
return PDFSYNCERR_OUTOFMEMORY;
// find the source file entry
size_t isrc;
for (isrc = 0; isrc < srcfiles.size(); isrc++)
if (path::IsSame(srcfilepath, srcfiles.at(isrc)))
break;
if (isrc == srcfiles.size())
return PDFSYNCERR_UNKNOWN_SOURCEFILE;
if (fileIndex.at(isrc).start == fileIndex.at(isrc).end)
return PDFSYNCERR_NORECORD_IN_SOURCEFILE; // there is not any record declaration for that particular source file
// look for sections belonging to the specified file
// starting with the first section that is declared within the scope of the file.
UINT min_distance = EPSILON_LINE; // distance to the closest record
size_t lineIx = (size_t)-1; // closest record-line index
for (size_t isec = fileIndex.at(isrc).start; isec < fileIndex.at(isrc).end; isec++) {
// does this section belong to the desired file?
if (lines.at(isec).file != isrc)
continue;
UINT d = abs((int)lines.at(isec).line - (int)line);
if (d < min_distance) {
min_distance = d;
lineIx = isec;
if (0 == d)
break; // We have found a record for the requested line!
}
}
if (lineIx == (size_t)-1)
return PDFSYNCERR_NORECORD_FOR_THATLINE;
// we read all the consecutive records until we reach a record belonging to another line
for (size_t i = lineIx; i < lines.size() && lines.at(i).line == lines.at(lineIx).line; i++)
records.Push(lines.at(i).record);
return PDFSYNCERR_SUCCESS;
}
示例10: AppendFavMenus
// For easy access, we try to show favorites in the menu, similar to a list of
// recently opened files.
// The first menu items are for currently opened file (up to MAX_FAV_MENUS), based
// on the assumption that user is usually interested in navigating current file.
// Then we have a submenu for each file for which there are bookmarks (up to
// MAX_FAV_SUBMENUS), each having up to MAX_FAV_MENUS menu items.
// If not all favorites can be shown, we also enable "Show all favorites" menu which
// will provide a way to see all favorites.
// Note: not sure if that's the best layout. Maybe we should always use submenu and
// put the submenu for current file as the first one (potentially named as "Current file"
// or some such, to make it stand out from other submenus)
static void AppendFavMenus(HMENU m, const WCHAR* currFilePath) {
// To minimize mouse movement when navigating current file via favorites
// menu, put favorites for current file first
DisplayState* currFileFav = nullptr;
if (currFilePath) {
currFileFav = gFavorites.GetFavByFilePath(currFilePath);
}
// sort the files with favorites by base file name of file path
Vec<const WCHAR*> filePathsSorted;
if (HasPermission(Perm_DiskAccess)) {
// only show favorites for other files, if we're allowed to open them
GetSortedFilePaths(filePathsSorted, currFileFav);
}
if (currFileFav && currFileFav->favorites->size() > 0) {
filePathsSorted.InsertAt(0, currFileFav->filePath);
}
if (filePathsSorted.size() == 0) {
return;
}
AppendMenu(m, MF_SEPARATOR, 0, nullptr);
gFavorites.ResetMenuIds();
UINT menuId = IDM_FAV_FIRST;
size_t menusCount = filePathsSorted.size();
if (menusCount > MAX_FAV_MENUS) {
menusCount = MAX_FAV_MENUS;
}
for (size_t i = 0; i < menusCount; i++) {
const WCHAR* filePath = filePathsSorted.at(i);
DisplayState* f = gFavorites.GetFavByFilePath(filePath);
CrashIf(!f);
HMENU sub = m;
bool combined = (f->favorites->size() == 1);
if (!combined) {
sub = CreateMenu();
}
AppendFavMenuItems(sub, f, menuId, combined, f == currFileFav);
if (!combined) {
if (f == currFileFav) {
AppendMenu(m, MF_POPUP | MF_STRING, (UINT_PTR)sub, _TR("Current file"));
} else {
AutoFreeW tmp;
tmp.SetCopy(path::GetBaseName(filePath));
auto fileName = win::menu::ToSafeString(tmp);
AppendMenuW(m, MF_POPUP | MF_STRING, (UINT_PTR)sub, fileName);
}
}
}
}
示例11: CanEmitElasticSpace
// don't emit multiple spaces and don't emit spaces
// at the beginning of the line
static bool CanEmitElasticSpace(float currX, float NewLineX, float maxCurrX, Vec<DrawInstr>& currLineInstr) {
if (NewLineX == currX || 0 == currLineInstr.size())
return false;
// prevent elastic spaces from being flushed to the
// beginning of the next line
if (currX > maxCurrX)
return false;
DrawInstr& di = currLineInstr.Last();
// don't add a space if only an anchor would be in between them
if (InstrAnchor == di.type && currLineInstr.size() > 1)
di = currLineInstr.at(currLineInstr.size() - 2);
return (InstrElasticSpace != di.type) && (InstrFixedSpace != di.type);
}
示例12: getShiftAmounts
// For each position in the data vector, compute how many slots it should be
// shifted inside its small permutation.
// Return value is zero if all the shift amounts are zero, nonzero otherwise.
long ColPerm::getShiftAmounts(Vec<long>& out) const
{
long sz = getSize();
out.SetLength(sz);
long nonZero = 0;
for (long k = 0; k < sz; k++) {
long i = getCoord(k, dim);
long pi_i = at(k);
if (i != pi_i) nonZero = 1;
out.at(addCoord(k, dim, pi_i-i)) = i - pi_i;
}
return nonZero;
}
示例13: VerticalLayoutFromDef
static VerticalLayout* VerticalLayoutFromDef(ParsedMui& parsed, TxtNode* structDef) {
CrashIf(!structDef->IsStructWithName("VerticalLayout"));
VerticalLayoutDef* def = DeserializeVerticalLayoutDef(structDef);
VerticalLayout* l = new VerticalLayout();
l->SetName(def->name);
Vec<DirectionalLayoutDataDef*>* children = def->children;
DirectionalLayoutData ld;
for (size_t i = 0; children && i < children->size(); i++) {
SetDirectionalLayouData(ld, parsed, children->at(i));
l->Add(ld);
}
FreeVerticalLayoutDef(def);
return l;
}
示例14: HasPreviousLineSingleImage
static bool HasPreviousLineSingleImage(Vec<DrawInstr>& instrs) {
REAL imageY = -1;
for (size_t idx = instrs.size(); idx > 0; idx--) {
DrawInstr& i = instrs.at(idx - 1);
if (!IsVisibleDrawInstr(i))
continue;
if (-1 != imageY) {
// if another visible item precedes the image,
// it must be completely above it (previous line)
return i.bbox.Y + i.bbox.Height <= imageY;
}
if (InstrImage != i.type)
return false;
imageY = i.bbox.Y;
}
return imageY != -1;
}
示例15: MeasureTextQuick
RectF MeasureTextQuick(Graphics* g, Font* f, const WCHAR* s, int len) {
CrashIf(0 >= len);
static Vec<Font*> fontCache;
static Vec<bool> fixCache;
RectF bbox;
g->MeasureString(s, len, f, PointF(0, 0), &bbox);
int idx = fontCache.Find(f);
if (-1 == idx) {
LOGFONTW lfw;
Status ok = f->GetLogFontW(g, &lfw);
bool isItalicOrMonospace = Ok != ok || lfw.lfItalic || str::Eq(lfw.lfFaceName, L"Courier New") ||
str::Find(lfw.lfFaceName, L"Consol") || str::EndsWith(lfw.lfFaceName, L"Mono") ||
str::EndsWith(lfw.lfFaceName, L"Typewriter");
fontCache.Append(f);
fixCache.Append(isItalicOrMonospace);
idx = (int)fontCache.size() - 1;
}
// most documents look good enough with these adjustments
if (!fixCache.at(idx)) {
REAL correct = 0;
for (int i = 0; i < len; i++) {
switch (s[i]) {
case 'i':
case 'l':
correct += 0.2f;
break;
case 't':
case 'f':
case 'I':
correct += 0.1f;
break;
case '.':
case ',':
case '!':
correct += 0.1f;
break;
}
}
bbox.Width *= (1.0f - correct / len) * 0.99f;
}
bbox.Height *= 0.95f;
return bbox;
}