本文整理汇总了C++中Vec::Append方法的典型用法代码示例。如果您正苦于以下问题:C++ Vec::Append方法的具体用法?C++ Vec::Append怎么用?C++ Vec::Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vec
的用法示例。
在下文中一共展示了Vec::Append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadCbrFile
bool CbxEngineImpl::LoadCbrFile(const WCHAR *file)
{
if (!file)
return false;
fileName = str::Dup(file);
fileExt = L".cbr";
RAROpenArchiveDataEx arcData = { 0 };
arcData.ArcNameW = (WCHAR *)file;
arcData.OpenMode = RAR_OM_EXTRACT;
HANDLE hArc = RAROpenArchiveEx(&arcData);
if (!hArc || arcData.OpenResult != 0)
return false;
// UnRAR does not seem to support extracting a single file by name,
// so lazy image loading doesn't seem possible
Vec<ImagesPage *> found;
for (;;) {
RARHeaderDataEx rarHeader;
int res = RARReadHeaderEx(hArc, &rarHeader);
if (0 != res)
break;
const WCHAR *fileName = rarHeader.FileNameW;
if (ImageEngine::IsSupportedFile(fileName)) {
ImagesPage *page = LoadCurrentCbrPage(hArc, rarHeader);
if (page)
found.Append(page);
}
else if (str::EqI(fileName, L"ComicInfo.xml")) {
ScopedMem<char> xmlData(LoadCurrentCbrFile(hArc, rarHeader, NULL));
if (xmlData)
ParseComicInfoXml(xmlData);
}
else
RARProcessFile(hArc, RAR_SKIP, NULL, NULL);
}
RARCloseArchive(hArc);
if (found.Count() == 0)
return false;
found.Sort(ImagesPage::cmpPageByName);
for (size_t i = 0; i < found.Count(); i++) {
pages.Append(found.At(i)->bmp);
found.At(i)->bmp = NULL;
}
mediaboxes.AppendBlanks(pages.Count());
DeleteVecMembers(found);
return true;
}
示例2: PaintSelection
void PaintSelection(WindowInfo* win, HDC hdc) {
CrashIf(!win->AsFixed());
Vec<RectI> rects;
if (win->mouseAction == MouseAction::Selecting) {
// during rectangle selection
RectI selRect = win->selectionRect;
if (selRect.dx < 0) {
selRect.x += selRect.dx;
selRect.dx *= -1;
}
if (selRect.dy < 0) {
selRect.y += selRect.dy;
selRect.dy *= -1;
}
rects.Append(selRect);
} else {
// during text selection or after selection is done
if (MouseAction::SelectingText == win->mouseAction) {
UpdateTextSelection(win);
if (!win->currentTab->selectionOnPage) {
// prevent the selection from disappearing while the
// user is still at it (OnSelectionStop removes it
// if it is still empty at the end)
win->currentTab->selectionOnPage = new Vec<SelectionOnPage>();
win->showSelection = true;
}
}
CrashIf(!win->currentTab->selectionOnPage);
if (!win->currentTab->selectionOnPage)
return;
for (SelectionOnPage& sel : *win->currentTab->selectionOnPage) {
rects.Append(sel.GetRect(win->AsFixed()));
}
}
PaintTransparentRectangles(hdc, win->canvasRc, rects, gGlobalPrefs->fixedPageUI.selectionColor);
}
示例3: DictTestMapStrToInt
void DictTestMapStrToInt()
{
dict::MapStrToInt d(4); // start small so that we can test resizing
bool ok;
int val;
utassert(0 == d.Count());
ok = d.Get("foo", &val);
utassert(!ok);
ok = d.Remove("foo", nullptr);
utassert(!ok);
ok = d.Insert("foo", 5, nullptr);
utassert(ok);
utassert(1 == d.Count());
ok = d.Get("foo", &val);
utassert(ok);
utassert(val == 5);
ok = d.Insert("foo", 8, &val);
utassert(!ok);
utassert(val == 5);
ok = d.Get("foo", &val);
utassert(ok);
utassert(val == 5);
ok = d.Get("bar", &val);
utassert(!ok);
val = 0;
ok = d.Remove("foo", &val);
utassert(ok);
utassert(val == 5);
utassert(0 == d.Count());
srand((unsigned int)time(nullptr));
Vec<char *> toRemove;
for (int i=0; i < 1024; i++) {
char *k = GenRandomString();
ok = d.Insert(k, i, nullptr);
// no guarantee that the string is unique, so Insert() doesn't always succeeds
if (!ok)
continue;
toRemove.Append(str::Dup(k));
utassert(toRemove.Count() == d.Count());
ok = d.Get(k, &val);
CrashIf(!ok);
CrashIf(i != val);
}
for (const char *k : toRemove) {
ok = d.Remove(k, nullptr);
utassert(ok);
}
FreeVecMembers(toRemove);
}
示例4: 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.Count(); 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.Count() - 1;
}
filesPerType.At(typeNo)->Append(str::Dup(file));
}
for (size_t j = 0; j < filesPerType.Count(); j++) {
WStrVec *all = filesPerType.At(j);
WStrVec *random = new WStrVec();
for (int n = 0; n < maxPerType && all->Count() > 0; n++) {
int idx = rand() % all->Count();
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.Count(); j++) {
WStrVec *random = filesPerType.At(j);
if (random->Count() > 0) {
gotAll = false;
WCHAR *file = random->At(0);
files.Append(file);
random->RemoveAtFast(0);
}
}
}
for (size_t j = 0; j < filesPerType.Count(); j++) {
delete filesPerType.At(j);
}
}
示例5: sqt
static Vec<PageAnnotation> *ParseFileModifications(const char *data)
{
if (!data)
return NULL;
SquareTree sqt(data);
if (!sqt.root || sqt.root->data.Count() == 0)
return NULL;
SquareTreeNode::DataItem& item = sqt.root->data.At(0);
if (!item.isChild || !str::EqI(item.key, "@meta"))
return NULL;
if (!item.value.child->GetValue("version")) {
// don't check the version value - rather extend the format
// in a way to ensure backwards compatibility
return NULL;
}
Vec<PageAnnotation> *list = new Vec<PageAnnotation>();
for (SquareTreeNode::DataItem *i = sqt.root->data.IterStart(); i; i = sqt.root->data.IterNext()) {
PageAnnotType type = str::EqI(i->key, "highlight") ? Annot_Highlight :
str::EqI(i->key, "underline") ? Annot_Underline :
str::EqI(i->key, "strikeout") ? Annot_StrikeOut :
str::EqI(i->key, "squiggly") ? Annot_Squiggly :
Annot_None;
CrashIf(!i->isChild);
if (Annot_None == type || !i->isChild)
continue;
int pageNo;
geomutil::RectT<float> rect;
PageAnnotation::Color color;
float opacity;
int r, g, b;
SquareTreeNode *node = i->value.child;
const char *value = node->GetValue("page");
if (!value || !str::Parse(value, "%d%$", &pageNo))
continue;
value = node->GetValue("rect");
if (!value || !str::Parse(value, "%f %f %f %f%$", &rect.x, &rect.y, &rect.dx, &rect.dy))
continue;
value = node->GetValue("color");
if (!value || !str::Parse(value, "#%2x%2x%2x%$", &r, &g, &b))
continue;
value = node->GetValue("opacity");
if (!value || !str::Parse(value, "%f%$", &opacity))
opacity = 1.0f;
color = PageAnnotation::Color((uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)(255 * opacity));
list->Append(PageAnnotation(type, pageNo, rect.Convert<double>(), color));
}
return list;
}
示例6: PaintSelection
void PaintSelection(WindowInfo *win, HDC hdc)
{
Vec<RectI> rects;
if (win->mouseAction == MA_SELECTING) {
// during rectangle selection
RectI selRect = win->selectionRect;
if (selRect.dx < 0) {
selRect.x += selRect.dx;
selRect.dx *= -1;
}
if (selRect.dy < 0) {
selRect.y += selRect.dy;
selRect.dy *= -1;
}
rects.Append(selRect);
} else {
// during text selection or after selection is done
if (MA_SELECTING_TEXT == win->mouseAction) {
UpdateTextSelection(win);
if (!win->selectionOnPage) {
// prevent the selection from disappearing while the
// user is still at it (OnSelectionStop removes it
// if it is still empty at the end)
win->selectionOnPage = new Vec<SelectionOnPage>();
win->showSelection = true;
}
}
CrashIf(!win->selectionOnPage);
if (!win->selectionOnPage)
return;
for (size_t i = 0; i < win->selectionOnPage->Count(); i++)
rects.Append(win->selectionOnPage->At(i).GetRect(win->dm));
}
PaintTransparentRectangles(hdc, win->canvasRc, rects, COL_SELECTION_RECT);
}
示例7: ParsePageRanges
// parses a list of page ranges such as 1,3-5,7- (i..e all but pages 2 and 6)
// into an interable list (returns nullptr on parsing errors)
// caller must delete the result
bool ParsePageRanges(const WCHAR* ranges, Vec<PageRange>& result) {
if (!ranges)
return false;
WStrVec rangeList;
rangeList.Split(ranges, L",", true);
rangeList.SortNatural();
for (size_t i = 0; i < rangeList.size(); i++) {
int start, end;
if (str::Parse(rangeList.at(i), L"%d-%d%$", &start, &end) && 0 < start && start <= end)
result.Append(PageRange(start, end));
else if (str::Parse(rangeList.at(i), L"%d-%$", &start) && 0 < start)
result.Append(PageRange(start, INT_MAX));
else if (str::Parse(rangeList.at(i), L"%d%$", &start) && 0 < start)
result.Append(PageRange(start, start));
else
return false;
}
return result.size() > 0;
}
示例8: Clear
void FileHistory::Clear(bool keepFavorites) {
if (!states)
return;
Vec<DisplayState*> keep;
for (size_t i = 0; i < states->size(); i++) {
if (keepFavorites && states->at(i)->favorites->size() > 0) {
states->at(i)->openCount = 0;
keep.Append(states->at(i));
} else {
DeleteDisplayState(states->at(i));
}
}
*states = keep;
}
示例9: 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.Count() - 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;
}
示例10: ApplyPrintSettings
static void ApplyPrintSettings(const WCHAR *settings, int pageCount, Vec<PRINTPAGERANGE>& ranges, Print_Advanced_Data& advanced)
{
WStrVec rangeList;
if (settings)
rangeList.Split(settings, L",", true);
for (size_t i = 0; i < rangeList.Count(); i++) {
PRINTPAGERANGE pr;
if (str::Parse(rangeList.At(i), L"%d-%d%$", &pr.nFromPage, &pr.nToPage)) {
pr.nFromPage = limitValue(pr.nFromPage, (DWORD)1, (DWORD)pageCount);
pr.nToPage = limitValue(pr.nToPage, (DWORD)1, (DWORD)pageCount);
ranges.Append(pr);
}
else if (str::Parse(rangeList.At(i), L"%d%$", &pr.nFromPage)) {
pr.nFromPage = pr.nToPage = limitValue(pr.nFromPage, (DWORD)1, (DWORD)pageCount);
ranges.Append(pr);
}
else if (str::Eq(rangeList.At(i), L"even"))
advanced.range = PrintRangeEven;
else if (str::Eq(rangeList.At(i), L"odd"))
advanced.range = PrintRangeOdd;
else if (str::Eq(rangeList.At(i), L"noscale"))
advanced.scale = PrintScaleNone;
else if (str::Eq(rangeList.At(i), L"shrink"))
advanced.scale = PrintScaleShrink;
else if (str::Eq(rangeList.At(i), L"fit"))
advanced.scale = PrintScaleFit;
else if (str::Eq(rangeList.At(i), L"compat"))
advanced.asImage = true;
}
if (ranges.Count() == 0) {
PRINTPAGERANGE pr = { 1, pageCount };
ranges.Append(pr);
}
}
示例11:
Vec<SelectionOnPage>* SelectionOnPage::FromTextSelect(TextSel* textSel) {
Vec<SelectionOnPage>* sel = new Vec<SelectionOnPage>(textSel->len);
for (int i = textSel->len - 1; i >= 0; i--) {
RectD rect = textSel->rects[i].Convert<double>();
sel->Append(SelectionOnPage(textSel->pages[i], &rect));
}
sel->Reverse();
if (sel->size() == 0) {
delete sel;
return nullptr;
}
return sel;
}
示例12: ExtractPageAnchors
bool EbookEngine::ExtractPageAnchors()
{
ScopedCritSec scope(&pagesAccess);
DrawInstr *baseAnchor = NULL;
for (int pageNo = 1; pageNo <= PageCount(); pageNo++) {
Vec<DrawInstr> *pageInstrs = GetHtmlPage(pageNo);
if (!pageInstrs)
return false;
for (size_t k = 0; k < pageInstrs->Count(); k++) {
DrawInstr *i = &pageInstrs->At(k);
if (InstrAnchor != i->type)
continue;
anchors.Append(PageAnchor(i, pageNo));
if (k < 2 && str::StartsWith(i->str.s + i->str.len, "\" page_marker />"))
baseAnchor = i;
}
baseAnchors.Append(baseAnchor);
}
CrashIf(baseAnchors.Count() != pages->Count());
return true;
}
示例13: Font
Font *GetFont(const WCHAR *name, float size, FontStyle style) {
int idx = cache.Find(Entry((WCHAR *)name, size, style));
if (idx != -1)
return cache.At(idx).font;
Font *font = ::new Font(name, size, style);
if (!font) {
// fall back to the default font, if a desired font can't be created
font = ::new Font(L"Times New Roman", size, style);
if (!font) {
return cache.Count() > 0 ? cache.At(0).font : NULL;
}
}
cache.Append(Entry(str::Dup(name), size, style, font));
return font;
}
示例14: url
ImageData *GetImageData(const char *id, const char *pagePath) {
ScopedMem<char> url(NormalizeURL(id, pagePath));
str::UrlDecodeInPlace(url);
for (size_t i = 0; i < images.Count(); i++) {
if (str::Eq(images.At(i).id, url))
return &images.At(i).base;
}
ImageData2 data = { 0 };
data.base.data = (char *)doc->GetData(url, &data.base.len);
if (!data.base.data)
return NULL;
data.id = url.StealData();
images.Append(data);
return &images.Last().base;
}
示例15: p
static WCHAR *ExtractHtmlText(EpubDoc *doc)
{
size_t len;
const char *data = doc->GetTextData(&len);
str::Str<char> text(len / 2);
HtmlPullParser p(data, len);
HtmlToken *t;
Vec<HtmlTag> tagNesting;
while ((t = p.Next()) != NULL && !t->IsError()) {
if (t->IsText() && !tagNesting.Contains(Tag_Head) && !tagNesting.Contains(Tag_Script) && !tagNesting.Contains(Tag_Style)) {
// trim whitespace (TODO: also normalize within text?)
while (t->sLen > 0 && str::IsWs(t->s[0])) {
t->s++;
t->sLen--;
}
while (t->sLen > 0 && str::IsWs(t->s[t->sLen-1]))
t->sLen--;
if (t->sLen > 0) {
text.AppendAndFree(ResolveHtmlEntities(t->s, t->sLen));
text.Append(' ');
}
}
else if (t->IsStartTag()) {
// TODO: force-close tags similar to HtmlFormatter.cpp's AutoCloseOnOpen?
if (!IsTagSelfClosing(t->tag))
tagNesting.Append(t->tag);
}
else if (t->IsEndTag()) {
if (!IsInlineTag(t->tag) && text.Size() > 0 && text.Last() == ' ') {
text.Pop();
text.Append("\r\n");
}
// when closing a tag, if the top tag doesn't match but
// there are only potentially self-closing tags on the
// stack between the matching tag, we pop all of them
if (tagNesting.Contains(t->tag)) {
while (tagNesting.Last() != t->tag)
tagNesting.Pop();
}
if (tagNesting.Count() > 0 && tagNesting.Last() == t->tag)
tagNesting.Pop();
}
}
return str::conv::FromUtf8(text.Get());
}