本文整理汇总了C++中Library类的典型用法代码示例。如果您正苦于以下问题:C++ Library类的具体用法?C++ Library怎么用?C++ Library使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Library类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lib_file
bool SRAssembler::read_library_file() {
ifstream lib_file(this->library_file.c_str());
string line;
Library* lib = NULL;
while (getline(lib_file, line)){
line = trim(line);
if (line == "[LIBRARY]") {
if (lib != NULL){
if (lib->get_left_read() == ""){
print_message("r1 file is expected in config file!");
return false;
}
this->libraries.push_back(*lib);
}
lib = new Library(this->libraries.size(), this->data_dir, this->tmp_dir, this->logger);
} else {
vector<string> tokens;
tokenize(line, tokens, "=");
if (tokens.size() == 2){
string param = trim(tokens[0]);
string value = trim(tokens[1]);
if (param == "r1" && lib != NULL) {
lib->set_left_read(value);
if (!file_exists(lib->get_left_read())) {
print_message("r1 file in config file: " + lib->get_left_read() + " does not exist!");
return false;
}
}
if (param == "r2" && lib != NULL) {
lib->set_right_read(value);
if (!file_exists(lib->get_right_read())) {
print_message("r2 file in config file: " + lib->get_right_read() + " does not exist!");
return false;
}
lib->set_paired_end(true);
}
if (param == "insert_size" && lib != NULL) {
lib->set_insert_size(str2int(value));
}
if (param == "direction" && lib != NULL) {
lib->set_reversed(str2int(value));
}
if (param == "format" && lib != NULL) {
if (value == "fastq") {
lib->set_format(FORMAT_FASTQ);
}
else if (value == "fasta") {
lib->set_format(FORMAT_FASTA);
} else {
print_message("format in config file should be 'fastq' or 'fasta'!");
return false;
}
}
}
}
}
if (lib != NULL){
if (lib->get_left_read() == ""){
print_message("r1 file is expected in config file!");
return false;
}
this->libraries.push_back(*lib);
}
if (this->libraries.size() == 0){
print_message(" No [LIBRARY] section found in config file!");
return false;
}
return true;
}
示例2: main
int main()
{
int choice;
Library myLibrary;
cout << "Welcome to the Library Simulator!" << endl;
//MENU
//every option corresponds to a Library class member function
//some require input before the function can be called
//It is all very self-documenting
do
{
cout << " Please make your choice: " << endl;
cout << " [1] ADD BOOK" << endl;
cout << " [2] ADD PATRON" << endl;
cout << " [3] CHECK OUT BOOK" << endl;
cout << " [4] RETURN BOOK" << endl;
cout << " [5] REQUEST BOOK" << endl;
cout << " [6] INCREASE DATE" << endl;
cout << " [7] PAY FINE" << endl;
cout << " [8] VIEW PATRON INFO" << endl;
cout << " [9] VIEW BOOK INFO" << endl;
cout << " [0] QUIT" << endl;
cin >> choice;
cin.ignore();
if(choice == 1)
{
myLibrary.addBook();
}
else if(choice == 2)
{
myLibrary.addMember();
}
else if(choice == 3)
{
string tempPatron, tempBook;
cout << "Please enter the ID for the Patron." << endl;
getline(cin, tempPatron);
cout << "Please enter the ID for the Book." << endl;
getline(cin, tempBook);
myLibrary.checkOutBook(tempPatron, tempBook);
}
else if(choice == 4)
{
string tempBook;
cout << "Please enter to Book ID that you wish to return: ";
getline(cin, tempBook);
myLibrary.returnBook(tempBook);
}
else if(choice == 5)
{
string tempPatron, tempBook;
cout << "Please enter the ID for the Patron." << endl;
getline(cin, tempPatron);
cout << "Please enter the ID for the Book." << endl;
getline(cin, tempBook);
myLibrary.requestBook(tempPatron, tempBook);
}
else if(choice == 6)
{
myLibrary.incrementCurrentDate();
}
else if(choice == 7)
{
string tempPatron;
double tempPayment;
cout << "Please enter the ID for the Patron." << endl;
getline(cin, tempPatron);
cout << "How much to pay? ";
cin >> tempPayment;
cin.ignore();
myLibrary.payFine(tempPatron, tempPayment);
}
else if(choice == 8)
{
string tempPatron;
cout << "Please enter the ID of the Patron you wish to view: ";
getline(cin, tempPatron);
myLibrary.viewPatronInfo(tempPatron);
}
else if(choice == 9)
{
string tempBook;
cout << "Please enter the ID of the Book you wish to view: ";
getline(cin, tempBook);
myLibrary.viewBookInfo(tempBook);
}
}
示例3: container
void container() const {
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<def>\n"
" <container id=\"A\" startPattern=\"std :: A <\" endPattern=\"> !!::\">\n"
" <type templateParameter=\"1\"/>\n"
" <size templateParameter=\"4\">\n"
" <function name=\"resize\" action=\"resize\"/>\n"
" <function name=\"clear\" action=\"clear\"/>\n"
" <function name=\"size\" yields=\"size\"/>\n"
" <function name=\"empty\" yields=\"empty\"/>\n"
" <function name=\"push_back\" action=\"push\"/>\n"
" <function name=\"pop_back\" action=\"pop\"/>\n"
" </size>\n"
" <access>\n"
" <function name=\"at\" yields=\"at_index\"/>\n"
" <function name=\"begin\" yields=\"start-iterator\"/>\n"
" <function name=\"end\" yields=\"end-iterator\"/>\n"
" <function name=\"data\" yields=\"buffer\"/>\n"
" <function name=\"c_str\" yields=\"buffer-nt\"/>\n"
" <function name=\"front\" yields=\"item\"/>\n"
" <function name=\"find\" action=\"find\"/>\n"
" </access>\n"
" </container>\n"
" <container id=\"B\" startPattern=\"std :: B <\" inherits=\"A\">\n"
" <size templateParameter=\"3\"/>\n" // Inherits all but templateParameter
" </container>\n"
" <container id=\"C\">\n"
" <type string=\"std-like\"/>\n"
" <access indexOperator=\"array-like\"/>\n"
" </container>\n"
"</def>";
tinyxml2::XMLDocument doc;
doc.Parse(xmldata, sizeof(xmldata));
Library library;
library.load(doc);
Library::Container& A = library.containers["A"];
Library::Container& B = library.containers["B"];
Library::Container& C = library.containers["C"];
ASSERT_EQUALS(A.type_templateArgNo, 1);
ASSERT_EQUALS(A.size_templateArgNo, 4);
ASSERT_EQUALS(A.startPattern, "std :: A <");
ASSERT_EQUALS(A.endPattern, "> !!::");
ASSERT_EQUALS(A.stdStringLike, false);
ASSERT_EQUALS(A.arrayLike_indexOp, false);
ASSERT_EQUALS(Library::Container::SIZE, A.getYield("size"));
ASSERT_EQUALS(Library::Container::EMPTY, A.getYield("empty"));
ASSERT_EQUALS(Library::Container::AT_INDEX, A.getYield("at"));
ASSERT_EQUALS(Library::Container::START_ITERATOR, A.getYield("begin"));
ASSERT_EQUALS(Library::Container::END_ITERATOR, A.getYield("end"));
ASSERT_EQUALS(Library::Container::BUFFER, A.getYield("data"));
ASSERT_EQUALS(Library::Container::BUFFER_NT, A.getYield("c_str"));
ASSERT_EQUALS(Library::Container::ITEM, A.getYield("front"));
ASSERT_EQUALS(Library::Container::NO_YIELD, A.getYield("foo"));
ASSERT_EQUALS(Library::Container::RESIZE, A.getAction("resize"));
ASSERT_EQUALS(Library::Container::CLEAR, A.getAction("clear"));
ASSERT_EQUALS(Library::Container::PUSH, A.getAction("push_back"));
ASSERT_EQUALS(Library::Container::POP, A.getAction("pop_back"));
ASSERT_EQUALS(Library::Container::FIND, A.getAction("find"));
ASSERT_EQUALS(Library::Container::NO_ACTION, A.getAction("foo"));
ASSERT_EQUALS(B.type_templateArgNo, 1);
ASSERT_EQUALS(B.size_templateArgNo, 3);
ASSERT_EQUALS(B.startPattern, "std :: B <");
ASSERT_EQUALS(B.endPattern, "> !!::");
ASSERT_EQUALS(B.functions.size(), A.functions.size());
ASSERT(C.functions.empty());
ASSERT_EQUALS(C.type_templateArgNo, -1);
ASSERT_EQUALS(C.size_templateArgNo, -1);
ASSERT_EQUALS(C.stdStringLike, true);
ASSERT_EQUALS(C.arrayLike_indexOp, true);
}
示例4: setUp
virtual void setUp()
{
init = new Library;
init->video().timer();
reached_callback = a = b = c = false;
}
示例5: main
int main(){
Library myLib;
int iChoice;
char cChoice;
string temp1, temp2;
double tempDouble;
do{
displayMenu();
iChoice = getChoice();
switch (iChoice){
case 0: //Quit
break;
case 1: //Add a book
myLib.addBook();
break;
case 2: //Add a member
myLib.addMember();
break;
case 3: //Check out a Book
checkOutBook(myLib);
cin.get();
break;
case 4: //Return a Book
std::cout << "What is the ID code of the book? ";
std::getline(std::cin, temp1);
myLib.returnBook(temp1);
cin.get();
break;
case 5: //Request a Book
cout << "What is the member's ID number? ";
getline(cin, temp1);
cout << "What is the ID code of the book? ";
getline(cin, temp2);
myLib.requestBook(temp1,temp2);
cin.get();
break;
case 6: //Pay a Fine
cout << "What is the member's ID number? ";
getline(cin, temp1);
cout << "How much would they like to pay? ";
cin >> tempDouble;
cin.get();
myLib.payFine(temp1,tempDouble);
cin.get();
break;
case 7: //Increment Date
cout << "Current Date: " << myLib.getCurrentDate() << endl;
cout << "Would you like to increment? (\'y\'/\'n\') ";
cin >> cChoice;
clearBuffer();
if (cChoice == 'y')
myLib.incrementCurrentDate();
else
cout << "Date not incremented." << endl;
cin.get();
break;
case 8: //View Member Information
cout << "What is the member's ID number? ";
getline(cin,temp1);
myLib.viewPatronInfo(temp1);
cin.get();
break;
case 9: //View Book Information
cout << "What is the book's ID code? ";
getline(cin,temp1);
myLib.viewBookInfo(temp1);
cin.get();
break;
}
}while (iChoice > 0 && iChoice <= 9);
return 0;
}
示例6: ERROR3
BOOL LibraryFile::AddSpecificIndex(SuperGallery *ParentGal, PathName *Path, SGLibType Type,
StringBase *Description, UINT32 bModified, BOOL bIsWebLib)
{
if(ParentGal == NULL || Path == NULL || !Libraries.IsEmpty() || !Path->IsValid())
{
ERROR3("LibraryFile::AddSpecificIndex - Problems on entry");
return FALSE;
}
// Check the path for the library exists
// if(!SGLibOil::FileExists(Path))
// return FALSE;
// Remember the pathname and type
MyPath = *Path;
MyType = Type;
ParentGallery = ParentGal;
// Create the sub lib
Library *NewSubLib = new Library;
if (NewSubLib != NULL)
{
// Path = "C:\testlib\animals\xarainfo\animals.txt"
// Path of files themselves... FilesPath = "C:\testlib\animals"
NewSubLib->m_bIsWebLib = bIsWebLib;
PathName TmpPath(Path->GetLocation(FALSE));
NewSubLib->SetModified(bModified);
// If it's a root directory we need the slash...
PathName FilesPath;
String_256 TmpRootCheck(TmpPath.GetLocation(TRUE));
if(SGLibOil::IsRootDirectory(&TmpRootCheck))
FilesPath.SetPathName(TmpPath.GetLocation(TRUE));
else
FilesPath.SetPathName(TmpPath.GetLocation(FALSE));
// Default title for the new group
String_256 Desc256;
String_64 Desc64;
if(Description == NULL)
Desc256 = Path->GetTruncatedPath(60);
else
Desc256 = *Description;
Desc256.Left(&Desc64, 64);
// The filename of the index
String_64 IndexFilename(Path->GetFileName(TRUE));
// Add this new index to the library file and scan it in...
if(NewSubLib->Init(ParentGal, &FilesPath, &Desc64, &IndexFilename, Type, FALSE, (Description != NULL)))
{
Libraries.AddTail(NewSubLib);
// Keep track of libraries added for redraw purposes...
AddNewFolderToScrollRedrawSystem(NewSubLib);
return TRUE;
}
else
{
// if there was a problem, don't go round leaving memory everywhere...
delete NewSubLib;
NewSubLib = NULL;
}
}
// Nothing added
return FALSE;
}
示例7: SoMuchEvil
void SoMuchEvil(OnionEncryptor &oe)
{
int count = Random::GetInstance().GetInt(10, 20);
int changed0 = Random::GetInstance().GetInt(0, count - 5);
int changed1 = Random::GetInstance().GetInt(changed0 + 1, count + 1);
int mchanged0 = Random::GetInstance().GetInt(0, count);
int mchanged1 = Random::GetInstance().GetInt(0, count);
Library *lib = CryptoFactory::GetInstance().GetLibrary();
QVector<QSharedPointer<AsymmetricKey> > private_keys;
QVector<QSharedPointer<AsymmetricKey> > public_keys;
for(int idx = 0; idx < count; idx++) {
private_keys.append(QSharedPointer<AsymmetricKey>(lib->CreatePrivateKey()));
public_keys.append(QSharedPointer<AsymmetricKey>(private_keys.last()->GetPublicKey()));
}
QVector<QByteArray> cleartexts;
QVector<QByteArray> ciphertexts;
QScopedPointer<Random> rand(lib->GetRandomNumberGenerator());
for(int idx = 0; idx < count; idx++) {
QByteArray cleartext(1500, 0);
rand->GenerateBlock(cleartext);
QByteArray ciphertext;
EXPECT_EQ(oe.Encrypt(public_keys, cleartext, ciphertext, 0), -1);
cleartexts.append(cleartext);
ciphertexts.append(ciphertext);
}
QVector<QVector<QByteArray> > onions(count + 1);
onions.last() = ciphertexts;
// Find first evil peer
for(int idx = count - 1; idx >= changed1; idx--) {
EXPECT_TRUE(oe.Decrypt(private_keys[idx], onions[idx + 1], onions[idx], 0));
oe.RandomizeBlocks(onions[idx]);
}
QVector<QSharedPointer<AsymmetricKey> > swap_keys(public_keys);
swap_keys.resize(changed1);
QByteArray cleartext(1500, 0);
rand->GenerateBlock(cleartext);
EXPECT_EQ(oe.Encrypt(swap_keys, cleartext, onions[changed1][mchanged1], 0), -1);
// Find second evil peer
for(int idx = changed1 - 1; idx >= changed0; idx--) {
EXPECT_TRUE(oe.Decrypt(private_keys[idx], onions[idx + 1], onions[idx], 0));
oe.RandomizeBlocks(onions[idx]);
}
swap_keys.resize(changed0);
rand->GenerateBlock(cleartext);
EXPECT_EQ(oe.Encrypt(swap_keys, cleartext, onions[changed0][mchanged0], 0), -1);
for(int idx = changed0 - 1; idx >= 0; idx--) {
EXPECT_TRUE(oe.Decrypt(private_keys[idx], onions[idx + 1], onions[idx], 0));
oe.RandomizeBlocks(onions[idx]);
}
QBitArray bad;
EXPECT_FALSE(oe.VerifyAll(private_keys, onions, bad));
int good_count = 0;
int bad_count = 0;
for(int idx = 0; idx < count; idx++) {
if(idx == changed0 || idx == changed1) {
EXPECT_TRUE(bad[idx]);
} else {
EXPECT_FALSE(bad[idx]);
}
onions.first().contains(cleartexts[idx]) ? good_count++ : bad_count++;
}
EXPECT_TRUE(good_count >= count - 2);
EXPECT_TRUE(good_count < count);
EXPECT_TRUE(bad_count > 0);
EXPECT_TRUE(bad_count <= 2);
}
示例8: RoundTest_PeerDisconnectMiddle
void RoundTest_PeerDisconnectMiddle(CreateSessionCallback callback,
CreateGroupGenerator cgg)
{
Timer::GetInstance().UseVirtualTime();
int count = Random::GetInstance().GetInt(TEST_RANGE_MIN, TEST_RANGE_MAX);
int leader = Random::GetInstance().GetInt(0, count);
int sender = Random::GetInstance().GetInt(0, count);
int disconnecter = Random::GetInstance().GetInt(0, count);
QVector<TestNode *> nodes;
Group *group;
ConstructOverlay(count, nodes, group);
for(int idx = 0; idx < count; idx++) {
for(int jdx = 0; jdx < count; jdx++) {
if(idx == jdx) {
continue;
}
EXPECT_TRUE(nodes[idx]->cm.GetConnectionTable().GetConnection(nodes[jdx]->cm.GetId()));
}
}
for(int idx = 0; idx < count; idx++) {
EXPECT_TRUE(nodes[idx]->sink.Count() == 0);
}
Id leader_id = nodes[leader]->cm.GetId();
Id session_id;
CreateSessions(nodes, *group, leader_id, session_id, callback, cgg);
Library *lib = CryptoFactory::GetInstance().GetLibrary();
QScopedPointer<Dissent::Utils::Random> rand(lib->GetRandomNumberGenerator());
QByteArray msg(512, 0);
rand->GenerateBlock(msg);
nodes[sender]->session->Send(msg);
for(int idx = 0; idx < count; idx++) {
nodes[idx]->session->Start();
}
TestNode::calledback = 0;
qint64 next = Timer::GetInstance().VirtualRun();
// XXX This needs to be improved, but what we are doing is issuing a
// disconnect approximately 1 to count steps into the Round
qint64 run_before_disc = Time::GetInstance().MSecsSinceEpoch() +
Random::GetInstance().GetInt(10, 10 * count);
while(next != -1 && TestNode::calledback < count &&
Time::GetInstance().MSecsSinceEpoch() < run_before_disc)
{
Time::GetInstance().IncrementVirtualClock(next);
next = Timer::GetInstance().VirtualRun();
}
if(Time::GetInstance().MSecsSinceEpoch() >= run_before_disc) {
nodes[disconnecter]->cm.Disconnect();
}
while(next != -1 && TestNode::calledback < count) {
Time::GetInstance().IncrementVirtualClock(next);
next = Timer::GetInstance().VirtualRun();
}
if(Time::GetInstance().MSecsSinceEpoch() < run_before_disc) {
std::cout << "RoundTest_PeerDisconnectMiddle never caused a disconnect, "
"consider rerunning." << std::endl;
for(int idx = 0; idx < count; idx++) {
EXPECT_EQ(msg, nodes[idx]->sink.Last().first);
}
} else {
foreach(TestNode *node, nodes) {
EXPECT_TRUE(node->session->Stopped());
}
}
示例9:
/**
This method exists only to allow the TraverseExtFuncLibrary function
to make callbacks to the Library class from C.
@NOTE there might be issues with C/C++ linking here?
*/
void
Library::extMethodTraverse(void *a1, void *a2){
Library *self = (Library *)a2;
self->appendToExtMethodVector(a1);
}
示例10: RoundTest_MultiRound
void RoundTest_MultiRound(CreateSessionCallback callback, CreateGroupGenerator cgg)
{
Timer::GetInstance().UseVirtualTime();
int count = Random::GetInstance().GetInt(TEST_RANGE_MIN, TEST_RANGE_MAX);
int leader = Random::GetInstance().GetInt(0, count);
int sender0 = Random::GetInstance().GetInt(0, count);
int sender1 = Random::GetInstance().GetInt(0, count);
while(sender0 != sender1) {
sender1 = Random::GetInstance().GetInt(0, count);
}
QVector<TestNode *> nodes;
Group *group;
ConstructOverlay(count, nodes, group);
Id leader_id = nodes[leader]->cm.GetId();
Id session_id;
CreateSessions(nodes, *group, leader_id, session_id, callback, cgg);
Library *lib = CryptoFactory::GetInstance().GetLibrary();
QScopedPointer<Dissent::Utils::Random> rand(lib->GetRandomNumberGenerator());
QByteArray msg(512, 0);
rand->GenerateBlock(msg);
nodes[sender0]->session->Send(msg);
SignalCounter sc;
for(int idx = 0; idx < count; idx++) {
QObject::connect(&nodes[idx]->sink, SIGNAL(DataReceived()), &sc, SLOT(Counter()));
nodes[idx]->session->Start();
}
TestNode::calledback = 0;
qint64 next = Timer::GetInstance().VirtualRun();
while(next != -1 && sc.GetCount() < count && TestNode::calledback < count) {
Time::GetInstance().IncrementVirtualClock(next);
next = Timer::GetInstance().VirtualRun();
}
sc.Reset();
for(int idx = 0; idx < count; idx++) {
EXPECT_EQ(msg, nodes[idx]->sink.Last().first);
}
rand->GenerateBlock(msg);
nodes[sender1]->session->Send(msg);
TestNode::calledback = 0;
next = Timer::GetInstance().VirtualRun();
while(next != -1 && sc.GetCount() < count && TestNode::calledback < count * 2) {
Time::GetInstance().IncrementVirtualClock(next);
next = Timer::GetInstance().VirtualRun();
}
for(int idx = 0; idx < count; idx++) {
EXPECT_EQ(msg, nodes[idx]->sink.Last().first);
}
CleanUp(nodes);
delete group;
}
示例11: RoundTest_PeerDisconnectEnd
void RoundTest_PeerDisconnectEnd(CreateSessionCallback callback,
CreateGroupGenerator cgg)
{
Timer::GetInstance().UseVirtualTime();
int count = Random::GetInstance().GetInt(TEST_RANGE_MIN, TEST_RANGE_MAX);
int leader = Random::GetInstance().GetInt(0, count);
int disconnecter = Random::GetInstance().GetInt(0, count);
while(leader != disconnecter) {
disconnecter = Random::GetInstance().GetInt(0, count);
}
QVector<TestNode *> nodes;
Group *group;
ConstructOverlay(count, nodes, group);
Id leader_id = nodes[leader]->cm.GetId();
Id session_id;
CreateSessions(nodes, *group, leader_id, session_id, callback, cgg);
for(int idx = 0; idx < count; idx++) {
nodes[idx]->session->Start();
}
TestNode::calledback = 0;
qint64 next = Timer::GetInstance().VirtualRun();
while(next != -1 && TestNode::calledback < count) {
Time::GetInstance().IncrementVirtualClock(next);
next = Timer::GetInstance().VirtualRun();
}
nodes[disconnecter]->session->Stop();
nodes[disconnecter]->cm.Disconnect();
EXPECT_TRUE(nodes[disconnecter]->session->Stopped());
TestNode::calledback = 0;
next = Timer::GetInstance().VirtualRun();
while(next != -1 && TestNode::calledback < count) {
Time::GetInstance().IncrementVirtualClock(next);
next = Timer::GetInstance().VirtualRun();
}
Library *lib = CryptoFactory::GetInstance().GetLibrary();
QScopedPointer<Dissent::Utils::Random> rand(lib->GetRandomNumberGenerator());
QByteArray msg(512, 0);
rand->GenerateBlock(msg);
nodes[(leader + disconnecter) % count]->session->Send(msg);
TestNode::calledback = 0;
next = Timer::GetInstance().VirtualRun();
while(next != -1 && TestNode::calledback < count) {
Time::GetInstance().IncrementVirtualClock(next);
next = Timer::GetInstance().VirtualRun();
}
for(int idx = 0; idx < count; idx++) {
EXPECT_TRUE(nodes[idx]->sink.Count() == 0);
EXPECT_TRUE(nodes[idx]->session->Stopped());
}
delete nodes[disconnecter];
nodes.remove(disconnecter);
CleanUp(nodes);
delete group;
}
示例12: getLibrary
void Text::onDraw(const ParentDrawInfo& pdi, IDrawer& render)
{
Library* lib = getLibrary();
if(!lib)
return;
Bound absChildBound;
Bound b = childBound();
b.min = b.min * pdi.scale + pdi.offset;
b.max = b.max * pdi.scale + pdi.offset;
if(!pdi.bound.intersection(absChildBound, b))
return;
Font* fnt = lib->getFont(font);
if(!fnt)
return;
int settedTex = -1;
UnicodeReader ur(text);
Vector locsize = childBound().size();
Vector locpos(Scalar(0), locsize.y - (fnt->characterHeight() + Scalar(0.5)) * fontScale);
while(!ur.empty())
{
uint firstChar = ur.getFirst();
if(firstChar == '\n'){
locpos.y -= fnt->characterHeight() * fontScale;
locpos.x = 0;
ur.str = ur.str.afterLeftTrim(1);
continue;
}
if(firstChar == '\r'){
locpos.x = 0;
ur.str = ur.str.afterLeftTrim(1);
continue;
}
if(isSpace(firstChar)){
const Font::CharInfo* ci = fnt->charInfo(firstChar);
if(ci)
locpos.x += fontScale * ci->width() * fnt->characterHeight() / ci->fontHeight;
ur.str = ur.str.afterLeftTrim(1);
continue;
}
const utf8* wordFirst = ur.str.first();
const utf8* wordEnd = ur.str.first();
while(!ur.empty())
{
ConstString prev = ur.str;
if(isSpace(ur.pop())){
ur.str = prev;
break;
}
wordEnd = ur.str.first();
}
if(wrapping)
{
uint wordLenght = fnt->stringLineLenght(ConstString(wordFirst, wordEnd));
if(locpos.x + (Scalar(wordLenght) - Scalar(0.5)) * fontScale > locsize.x && Scalar(wordLenght) * fontScale <= locsize.x){
locpos.y -= fnt->characterHeight() * fontScale;
locpos.x = 0;
}
}
UnicodeReader u(ConstString(wordFirst, wordEnd));
uint prevChar = 0;
while(!u.empty())
{
uint ch = u.pop();
const Font::CharInfo* ci = fnt->charInfo(ch);
if(!ci)
continue;
Scalar scale = fontScale * fnt->characterHeight() / ci->fontHeight;
const Font::ImageInfo& imgInfo = fnt->imageInfo(ci->image);
locpos.x += Scalar(fnt->charactersKerning(prevChar, ch)) * scale;
Vector p = position + locpos + Vector((Scalar)ci->dx - Scalar(0.5), (Scalar)ci->dy - Scalar(0.5)) * scale;
Vector s((ci->du + 1) * scale, (ci->dv + 1) * scale);
Bound v;
v.min = p * pdi.scale + pdi.offset;
v.max = (p + s) * pdi.scale + pdi.offset;
Bound t(Scalar(ci->u) - Scalar(0.5), Scalar(ci->v) - Scalar(0.5), Scalar(ci->u + ci->du) + Scalar(0.5), Scalar(ci->v + ci->dv) + Scalar(0.5));
t.min *= imgInfo.invSize;
t.max *= imgInfo.invSize;
Bound clipedV, clipedT;
if(clip(clipedV, clipedT, absChildBound, v, t))
{
if(ci->image != settedTex){
render.setTexture(imgInfo.name);
settedTex = ci->image;
}
Vector s = clipedV.size();
clipedV.min.x = floor(clipedV.min.x / scale) * scale + Scalar(0.5) * scale;
clipedV.min.y = floor(clipedV.min.y / scale) * scale + Scalar(0.5) * scale;
s.x = floor(Scalar(s.x / scale) + Scalar(0.5)) * scale;
//.........这里部分代码省略.........
示例13: do_preprocessing
void SRAssembler::do_preprocessing(int lib_idx, int file_part){
Library lib = this->libraries[lib_idx];
logger->info("preprocessing lib " + int2str(lib_idx + 1) + ", reads file (" + int2str(file_part) + "/" + int2str(lib.get_num_parts()) + ")");
char suffixc[3];
suffixc[0] = (char)(((file_part-1) / 26) + 97);
suffixc[1] = (char)(((file_part-1) % 26) + 97);
suffixc[2] = '\0';
string suffix(suffixc);
string left_src_read = lib.get_prefix_split_src_file(lib.get_left_read()) + suffix;
string right_src_read = "";
if (lib.get_paired_end())
right_src_read = lib.get_prefix_split_src_file(lib.get_right_read()) + suffix;
ifstream left_file(left_src_read.c_str());
ifstream right_file;
if (lib.get_paired_end()){
right_file.open(right_src_read.c_str(), ios_base::in);
}
string left_header = "";
string right_header = "";
string left_seq = "";
string right_seq = "";
string left_qual = "";
string right_qual = "";
string plus;
ofstream split_read_fasta_file;
ofstream split_read_fastq_file;
split_read_fasta_file.open(lib.get_split_file_name(file_part, FORMAT_FASTA).c_str(), ios_base::out);
if (lib.get_format() == FORMAT_FASTQ)
split_read_fastq_file.open(lib.get_split_file_name(file_part, FORMAT_FASTQ).c_str(), ios_base::out);
while (getline(left_file, left_header)) {
// get read data point, which includes 4 lines
string lead_chr = (lib.get_format() == FORMAT_FASTQ)? "@" : ">";
if (left_header.substr(0,1) == lead_chr){
//save left-end reads
getline(left_file, left_seq);
if (lib.get_format() == FORMAT_FASTQ) {
getline(left_file, plus);
getline(left_file, left_qual);
}
if (lib.get_paired_end()){
//save right-end reads
while (getline(right_file, right_header))
if (right_header.substr(0,1) == lead_chr)
break;
getline(right_file, right_seq);
if (lib.get_format() == FORMAT_FASTQ) {
getline(right_file, plus);
getline(right_file, right_qual);
}
}
if (lib.get_format() == FORMAT_FASTQ) {
split_read_fastq_file << left_header << endl
<< left_seq << endl
<< "+" << endl
<< left_qual << endl;
}
split_read_fasta_file << ">" << left_header.substr(1) << endl << left_seq << endl;
if (lib.get_paired_end()){
if (lib.get_format() == FORMAT_FASTQ) {
split_read_fastq_file << right_header << endl
<< right_seq << endl
<< "+" << endl
<< right_qual << endl;
}
split_read_fasta_file << ">" << right_header.substr(1) << endl << right_seq << endl;
}
}
}
split_read_fasta_file.close();
if (lib.get_format() == FORMAT_FASTQ)
split_read_fastq_file.close();
left_file.close();
if (lib.get_paired_end())
right_file.close();
string cmd = "rm " + left_src_read + " " + right_src_read;
run_shell_command(cmd);
}
示例14: sci_load
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_load(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
if (in.size() < 1)
{
Scierror(999, _("%s: Wrong number of input argument(s): at least %d expected.\n"), fname.data(), 1);
return types::Function::Error;
}
InternalType* pIT = in[0];
if (pIT->getId() != InternalType::IdScalarString)
{
Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname.data(), 1);
return Function::Error;
}
String *pS = pIT->getAs<types::String>();
wchar_t* pwstPathLib = expandPathVariableW(pS->get(0));
char* pstPath = wide_string_to_UTF8(pwstPathLib);
if (FileExist(pstPath))
{
if (isHDF5File(pstPath))
{
FREE(pstPath);
FREE(pwstPathLib);
//call overload
std::wstring wstFuncName = L"%_sodload";
ast::ExecVisitor exec;
Callable::ReturnValue Ret = Callable::Error;
Ret = Overload::call(wstFuncName, in, _iRetCount, out, &exec);
return Ret;
}
else
{
int err = 0;
Library* lib = loadlib(pS->get(0), &err);
FREE(pstPath);
switch (err)
{
case 0:
//no error
break;
case 1:
{
char* pstPath = wide_string_to_UTF8(pS->get(0));
Scierror(999, _("%s: %s is not a valid module file.\n"), fname.data(), pstPath);
FREE(pstPath);
return Function::Error;
}
case 2:
{
Scierror(999, "%s: %s", fname.data(), _("Redefining permanent variable.\n"));
return Function::Error;
}
default:
{
//nothing
}
}
FREE(pwstPathLib);
lib->killMe();
}
}
else
{
Scierror(999, _("%s: Unable to open file: \"%ls\".\n"), fname.data(), pwstPathLib);
FREE(pstPath);
FREE(pwstPathLib);
return Function::Error;
}
return Function::OK;
}
示例15: SubP
BOOL LibraryFile::CheckForSubIndexes(SuperGallery *ParentGal, PathName *Path, SGLibType Type, BOOL Updated)
{
// The directory given had no XaraInfo\index.txt file, maybe it's a sublib, check
// For defaults...
String_256 DefaultIndex;
String_256 IndexDesc;
BOOL CanGenerate;
BOOL ok = TRUE;
// Need to reset the Quiet status before a stream of Library::Init calls
ParentLibraryGallery->SetQuietStatus(FALSE);
if(GetSubIndexDetails(ParentLibraryGallery, &DefaultIndex, &IndexDesc, &CanGenerate))
{
String_256 SubP(Path->GetPath(TRUE)); // "%s\\XaraInfo\\%s"
SubP += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
SubP += TEXT("\\") + DefaultIndex;
PathName SubPath(SubP);
if(!SubPath.IsValid())
{
ERROR3("LibraryFile::CheckForSubIndexes invalid subpath");
return FALSE;
}
BOOL Generate = FALSE;
BOOL Found = FALSE;
// Is there a default sub index ?
Found = SGLibOil::FileExists(&SubPath);
if(!Found && CanGenerate)
{
if(Library::RemoteIndexes && GenerateIndexFile::IsDirectoryReadOnly(Path))
{
// Check whether there's a 'temporary' index for this directory, and
// possibly use that instead of the read only directory...
String_256 RemoteLocationOfIndex;
BOOL Existing = GenerateIndexFile::CheckForRemote(Path, &RemoteLocationOfIndex);
if(Existing)
{
String_256 SubP(RemoteLocationOfIndex); // %s\\XaraInfo\\%s
SGLibOil::AppendSlashIfNotPresent(&SubP);
SubP += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
SubP += TEXT("\\") + DefaultIndex;
PathName TmpSubPath(SubP);
Found = SGLibOil::FileExists(&TmpSubPath);
// OK, so there's a remote index sitting pretty in the user's temporary
// location... Use that and don't bother generating a new one...
if(Found)
{
SubPath.SetPathName(SubP);
Path->SetPathName(RemoteLocationOfIndex);
}
}
}
if(!Found)
{
// tell the user that there is no index file, and ask if they want one generating
String_256 WarnMsg;
String_256 TmpPath(SubPath.GetLocation(FALSE));
LibraryFile::TidyUpSubPath(&TmpPath);
WarnMsg.MakeMsg(_R(IDS_LIBRARY_NO_INDEX_FILE_GEN), (TCHAR *)IndexDesc, (TCHAR *)TmpPath);
Error::SetError(0, WarnMsg, 0);
//INT32 ButtonPressed = InformMessage(0, _R(IDS_NOTHUMBNAILS), _R(IDS_THUMBNAILS), _R(IDS_CANCEL)/*, _R(IDS_HELP)*/);
INT32 ButtonPressed = InformMessage(0, _R(IDS_CREATE), _R(IDS_CANCEL));
Error::ClearError();
if(ButtonPressed < 2)
{
// Generate an index...
String_64 Author(PRODUCT_NAME);
Generate = GenerateDefaultIndex(&SubPath, Path, &Author, Type, TRUE);
ok = TRUE;
}
else
{
// Cancel or help clicked
ok = FALSE;
}
}
}
if(!Found && !CanGenerate)
{
// tell the user that there is no index file, and give them a cancel...
String_256 WarnMsg;
String_256 TmpPath(SubPath.GetLocation(FALSE));
LibraryFile::TidyUpSubPath(&TmpPath);
WarnMsg.MakeMsg(_R(IDS_LIBRARY_NO_INDEX_FILE), (TCHAR *)IndexDesc, (TCHAR *)TmpPath);
Error::SetError(0, WarnMsg, 0);
INT32 ButtonPressed = InformWarning(0, _R(IDS_CANCEL), NULL);
Error::ClearError();
ok = FALSE;
}
//.........这里部分代码省略.........