本文整理汇总了C++中FileStore类的典型用法代码示例。如果您正苦于以下问题:C++ FileStore类的具体用法?C++ FileStore怎么用?C++ FileStore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(FilePersistence, SaveMultipleUnits)
{
QString testDir = QDir::tempPath() + QDir::toNativeSeparators("/Envision/FilePersistence/tests");
Model::Model model;
FileStore store;
store.setBaseFolder(testDir);
TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));
model.beginModification(root, "set title");
root->name()->set("Root");
TestNodes::BinaryNode* left = root->setLeft<TestNodes::BinaryNodePersistenceUnit>();
TestNodes::BinaryNode* right = root->setRight<TestNodes::BinaryNode>();
left->name()->set("Left child");
TestNodes::BinaryNode* leftleft = left->setLeft<TestNodes::BinaryNode>();
leftleft->name()->set("in a new unit");
right->name()->set("Right child");
model.endModification();
model.setName("units");
model.save(&store);
CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/units/units", testDir + "/units/units");
CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/units/2", testDir + "/units/2");
}
示例2: TEST
TEST(FilePersistence, LoadMultipleUnits)
{
QString testDir = ":/FilePersistence/test/persisted";
Model::Model model;
FileStore store;
store.setBaseFolder(testDir);
model.load(&store, "units");
TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.root());
CHECK_STR_EQUAL("BinaryNode", root->typeName() );
CHECK_STR_EQUAL("Root", root->name()->get() );
CHECK_CONDITION(root->left() != nullptr);
CHECK_CONDITION(root->right() != nullptr);
CHECK_STR_EQUAL("BinaryNodePersistenceUnit", root->left()->typeName() );
CHECK_STR_EQUAL("Left child", root->left()->name()->get() );
CHECK_CONDITION(root->left()->left() != nullptr);
CHECK_CONDITION(root->left()->right() == nullptr);
CHECK_STR_EQUAL("BinaryNode", root->left()->left()->typeName() );
CHECK_STR_EQUAL("in a new unit", root->left()->left()->name()->get() );
CHECK_CONDITION(root->left()->left()->left() == nullptr);
CHECK_CONDITION(root->left()->left()->right() == nullptr);
CHECK_STR_EQUAL("BinaryNode", root->right()->typeName() );
CHECK_STR_EQUAL("Right child", root->right()->name()->get() );
CHECK_CONDITION(root->right()->left() == nullptr);
CHECK_CONDITION(root->right()->right() == nullptr);
}
示例3: TEST
TEST(FilePersistence, SaveList)
{
QString testDir = QDir::tempPath() + "/Envision/FilePersistence/tests";
Model::Model model;
FileStore store;
store.setBaseFolder(testDir);
TestNodes::PartialList* root = dynamic_cast<TestNodes::PartialList*> (model.createRoot("PartialList"));
model.beginModification(root, "create ");
Model::Text* one = new Model::Text();
one->set("one");
root->list()->append(one);
Model::Text* two = new Model::Text();
two->set("two");
root->list()->append(two);
Model::Text* three = new Model::Text();
three->set("three");
root->list()->append(three);
Model::Text* four = new Model::Text();
four->set("four");
root->list()->append(four);
model.endModification();
model.setName("partial");
model.save(&store);
CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/partial/partial", testDir + "/partial/partial");
}
示例4: TEST
TEST(FilePersistence, LoadingList)
{
QString testDir = ":/FilePersistence/test/persisted";
Model::Model model;
FileStore store;
store.setBaseFolder(testDir);
model.load(&store, "partial");
TestNodes::PartialList* root = dynamic_cast<TestNodes::PartialList*> (model.root());
CHECK_CONDITION(root != nullptr);
Model::List* list = root->list();
CHECK_CONDITION(list != nullptr);
CHECK_STR_EQUAL("List", list->typeName() );
CHECK_CONDITION(list->isFullyLoaded() == false);
CHECK_INT_EQUAL(1, list->id());
list->loadFully(store);
CHECK_CONDITION(list->isFullyLoaded());
CHECK_INT_EQUAL(4, list->size());
Model::Text* one = list->at<Model::Text>(0);
Model::Text* two = list->at<Model::Text>(1);
Model::Text* three = list->at<Model::Text>(2);
Model::Text* four = list->at<Model::Text>(3);
CHECK_CONDITION(one != nullptr);
CHECK_STR_EQUAL("one", one->get());
CHECK_INT_EQUAL(2, one->id());
CHECK_CONDITION(two != nullptr);
CHECK_STR_EQUAL("two", two->get());
CHECK_INT_EQUAL(3, two->id())
CHECK_CONDITION(three != nullptr);
CHECK_STR_EQUAL("three", three->get());
CHECK_INT_EQUAL(4, three->id())
CHECK_CONDITION(four != nullptr);
CHECK_STR_EQUAL("four", four->get());
CHECK_INT_EQUAL(5, four->id());
}
示例5: if
void Webserver::ProcessGcode(const char* gc)
{
if (StringStartsWith(gc, "M30 ")) // delete SD card file
{
reprap.GetGCodes()->DeleteFile(&gc[4]);
}
else if (StringStartsWith(gc, "M23 ")) // select SD card file to print next
{
reprap.GetGCodes()->QueueFileToPrint(&gc[4]);
}
else if (StringStartsWith(gc, "M112") && !isdigit(gc[4])) // emergency stop
{
reprap.EmergencyStop();
gcodeReadIndex = gcodeWriteIndex; // clear the buffer
reprap.GetGCodes()->Reset();
}
else if (StringStartsWith(gc, "M503") && !isdigit(gc[4])) // echo config.g file
{
FileStore *configFile = platform->GetFileStore(platform->GetSysDir(), platform->GetConfigFile(), false);
if (configFile == NULL)
{
HandleReply("Configuration file not found", true);
}
else
{
char c;
size_t i = 0;
while (i < ARRAY_UPB(gcodeReply) && configFile->Read(c))
{
gcodeReply[i++] = c;
}
configFile->Close();
gcodeReply[i] = 0;
++seq;
}
}
else if (StringStartsWith(gc, "M25") && !isDigit(gc[3])) // pause SD card print
{
reprap.GetGCodes()->PauseSDPrint();
}
else
{
StoreGcodeData(gc, strlen(gc) + 1);
}
}
示例6: TEST
TEST(FilePersistence, SavingTypedList)
{
QString testDir = QDir::tempPath() + "/Envision/FilePersistence/tests";
Model::Model model;
FileStore store;
store.setBaseFolder(testDir);
Model::TypedList<Model::Text>* list = dynamic_cast<Model::TypedList<Model::Text>*> (model.createRoot("TypedListOfText"));
model.beginModification(list, "create");
Model::Text* one = new Model::Text();
one->set("one");
list->append(one);
Model::Text* two = new Model::Text();
two->set("two");
list->append(two);
model.endModification();
model.setName("typedList");
model.save(&store);
CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/typedList/typedList", testDir + "/typedList/typedList");
}
示例7: FileStore
int SCShell_cat::execute(SCCommand *command, SCStream *in, SCStream *out){
// if no params, do nothing
if(command->getArgCount() != 1){
out->println("Must specify file to output");
return -1;
}
// only get first parameter
String pwd = fUtils.getPWD();
String target = command->getArg(0);
String *path = fUtils.combineName(pwd, target);
// check if file exists
int ret = 0;
if(SD.FileExists(path->c_str())){
FileStore fs = FileStore();
fs.Init();
if(fs.Open(NULL, path->c_str(), FILE_READ)){
unsigned long fileLength = fs.Length();
char buf[READ_CHUNK_SIZE];
while(fileLength > 0){
int bytesToRead = min(fileLength, READ_CHUNK_SIZE);
int bytesRead = fs.Read(buf, bytesToRead);
out->write((const uint8_t *)buf, bytesRead);
fileLength -= bytesRead;
}
fs.Close();
} else {
out->println("Cannot open file");
ret = -2;
}
} else {
out->println(target + " does not exist");
ret = -1;
}
delete path;
return ret;
}
示例8: testEverything
//---------------------------------------------------------------------------
int FileStore_T :: testEverything()
{
TestUtil initTester( "FileStore", "initialization", __FILE__, __LINE__ );
TestUtil sizeTester( "FileStore", "size", __FILE__, __LINE__ );
TestUtil nfilesTester( "FileStore", "nfiles", __FILE__, __LINE__ );
TestUtil clearTester( "FileStore", "clear", __FILE__, __LINE__ );
TestUtil getTester( "FileStore", "getFilenames", __FILE__, __LINE__ );
TestUtil addTester( "FileStore", "addFile", __FILE__, __LINE__ );
TestUtil headerTester( "FileStore", "getHeader", __FILE__, __LINE__ );
try // default initialization
{
FileStore<TestHeaderType> store;
initTester.assert( true, "unexpected exception", __LINE__ );
}
catch (...)
{
initTester.assert( false, "unexpected exception", __LINE__ );
}
FileStore<TestHeaderType> store; // Use this for the remaining tests
try // empty store (size)
{
sizeTester.assert( (0 == store.size() ), "empty store expected", __LINE__ );
}
catch (...)
{
sizeTester.assert( false, "unexpected exception", __LINE__ );
}
try // empty store (nfiles)
{
nfilesTester.assert( (0 == store.nfiles() ), "empty store expected", __LINE__ );
}
catch (...)
{
nfilesTester.assert( false, "unexpected exception", __LINE__ );
}
try // empty store (getFilenames)
{
getTester.assert( (0 == store.getFileNames().size() ), "empty store expected", __LINE__ );
}
catch (...)
{
getTester.assert( false, "unexpected exception", __LINE__ );
}
try // empty store (clear)
{
store.clear();
clearTester.assert( true, "unexpected exception", __LINE__ );
}
catch (...)
{
clearTester.assert( false, "unexpected exception", __LINE__ );
}
try // empty store (getHeader)
{
const TestHeaderType& header = store.getHeader("filename");
headerTester.assert( false, "expected exception", __LINE__ );
}
catch (InvalidRequest& ire)
{
headerTester.assert( true, "expected exception", __LINE__ );
}
catch (...)
{
headerTester.assert( false, "unexpected exception", __LINE__ );
}
try // empty store (addFile)
{
TestHeaderType header(1);
store.addFile("testfile1", header);
addTester.assert( true, "unexpected exception", __LINE__ );
sizeTester.assert( (1 == store.size() ), "single file expected", __LINE__ );
nfilesTester.assert( (1 == store.nfiles() ), "single file expected", __LINE__ );
std::vector<std::string> filenames = store.getFileNames();
getTester.assert( (1 == filenames.size() ), "single file expected", __LINE__ );
if (filenames.size() > 0)
{
getTester.assert( (0 == filenames[0].compare("testfile1") ), "unexpected filename", __LINE__ );
}
}
catch (...)
{
addTester.assert( false, "unexpected exception", __LINE__ );
}
try // non-empty store (getHeader, present)
{
const TestHeaderType& header = store.getHeader("testfile1");
headerTester.assert( true, "unexpected exception", __LINE__ );
headerTester.assert( (1 == header.value), "unexpected header", __LINE__ );
//.........这里部分代码省略.........
示例9: SendFile
// Start sending a file or a JSON response.
void Webserver::SendFile(const char* nameOfFileToSend)
{
if (StringEquals(nameOfFileToSend, "/"))
{
nameOfFileToSend = INDEX_PAGE;
}
FileStore *fileToSend = platform->GetFileStore(platform->GetWebDir(), nameOfFileToSend, false);
if (fileToSend == NULL)
{
nameOfFileToSend = FOUR04_FILE;
fileToSend = platform->GetFileStore(platform->GetWebDir(), nameOfFileToSend, false);
if (fileToSend == NULL)
{
RejectMessage("not found", 404);
return;
}
}
Network *net = reprap.GetNetwork();
RequestState *req = net->GetRequest(NULL);
req->Write("HTTP/1.1 200 OK\n");
const char* contentType;
bool zip = false;
if (StringEndsWith(nameOfFileToSend, ".png"))
{
contentType = "image/png";
}
else if (StringEndsWith(nameOfFileToSend, ".ico"))
{
contentType = "image/x-icon";
}
else if (StringEndsWith(nameOfFileToSend, ".js"))
{
contentType = "application/javascript";
}
else if (StringEndsWith(nameOfFileToSend, ".css"))
{
contentType = "text/css";
}
else if (StringEndsWith(nameOfFileToSend, ".htm") || StringEndsWith(nameOfFileToSend, ".html"))
{
contentType = "text/html";
}
else if (StringEndsWith(nameOfFileToSend, ".zip"))
{
contentType = "application/zip";
zip = true;
}
else
{
contentType = "application/octet-stream";
}
req->Printf("Content-Type: %s\n", contentType);
if (zip && fileToSend != NULL)
{
req->Write("Content-Encoding: gzip\n");
req->Printf("Content-Length: %lu", fileToSend->Length());
}
req->Write("Connection: close\n\n");
net->SendAndClose(fileToSend);
}
示例10: nfiles
/// Get number of files (all types) in FileStore.
int nfiles(void) throw()
{ return (SP3Files.size() + (useSP3clock ? 0 : clkFiles.size())); }
示例11: TEST
TEST(FilePersistence, LoadDataMultipleUnits)
{
QString testDir = ":/FilePersistence/test/persisted";
FileStore store;
store.setBaseFolder(testDir);
typedef PersistedValue< QString >* String;
typedef PersistedValue< QList<PersistedNode*> >* Composite;
// Root Node
Composite root = dynamic_cast<Composite> (store.loadCompleteNodeSubtree("units", nullptr));
CHECK_CONDITION(root);
CHECK_STR_EQUAL("BinaryNode", root->type() );
CHECK_STR_EQUAL("units", root->name());
CHECK_INT_EQUAL(0, root->id());
CHECK_CONDITION(!root->partialHint());
CHECK_CONDITION(!root->isNewPersistenceUnit());
CHECK_INT_EQUAL(3, root->value().size());
// Root Node children
String rootName = dynamic_cast<String> (root->value().at(0));
CHECK_CONDITION(rootName);
CHECK_STR_EQUAL("Text", rootName->type() );
CHECK_STR_EQUAL("name", rootName->name());
CHECK_INT_EQUAL(1, rootName->id());
CHECK_CONDITION(!rootName->partialHint());
CHECK_CONDITION(!rootName->isNewPersistenceUnit());
CHECK_STR_EQUAL("Root", rootName->value());
Composite left = dynamic_cast<Composite> (root->value().at(1));
CHECK_CONDITION(left);
CHECK_STR_EQUAL("BinaryNodePersistenceUnit", left->type() );
CHECK_STR_EQUAL("left", left->name());
CHECK_INT_EQUAL(2, left->id());
CHECK_CONDITION(!left->partialHint());
CHECK_CONDITION(left->isNewPersistenceUnit());
CHECK_INT_EQUAL(2, left->value().size());
Composite right = dynamic_cast<Composite> (root->value().at(2));
CHECK_CONDITION(right);
CHECK_STR_EQUAL("BinaryNode", right->type() );
CHECK_STR_EQUAL("right", right->name());
CHECK_INT_EQUAL(6, right->id());
CHECK_CONDITION(!right->partialHint());
CHECK_CONDITION(!right->isNewPersistenceUnit());
CHECK_INT_EQUAL(1, right->value().size());
// Left Node children
String leftName = dynamic_cast<String> (left->value().at(0));
CHECK_CONDITION(leftName);
CHECK_STR_EQUAL("Text", leftName->type() );
CHECK_STR_EQUAL("name", leftName->name());
CHECK_INT_EQUAL(3, leftName->id());
CHECK_CONDITION(!leftName->partialHint());
CHECK_CONDITION(!leftName->isNewPersistenceUnit());
CHECK_STR_EQUAL("Left child", leftName->value());
Composite leftleft = dynamic_cast<Composite> (left->value().at(1));
CHECK_CONDITION(leftleft);
CHECK_STR_EQUAL("BinaryNode", leftleft->type() );
CHECK_STR_EQUAL("left", leftleft->name());
CHECK_INT_EQUAL(4, leftleft->id());
CHECK_CONDITION(!leftleft->partialHint());
CHECK_CONDITION(!leftleft->isNewPersistenceUnit());
CHECK_INT_EQUAL(1, leftleft->value().size());
String leftleftName = dynamic_cast<String> (leftleft->value().at(0));
CHECK_CONDITION(leftleftName);
CHECK_STR_EQUAL("Text", leftleftName->type() );
CHECK_STR_EQUAL("name", leftleftName->name());
CHECK_INT_EQUAL(5, leftleftName->id());
CHECK_CONDITION(!leftleftName->partialHint());
CHECK_CONDITION(!leftleftName->isNewPersistenceUnit());
CHECK_STR_EQUAL("in a new unit", leftleftName->value());
// Right Node children
String rightName = dynamic_cast<String> (right->value().at(0));
CHECK_CONDITION(rightName);
CHECK_STR_EQUAL("Text", rightName->type() );
CHECK_STR_EQUAL("name", rightName->name());
CHECK_INT_EQUAL(7, rightName->id());
CHECK_CONDITION(!rightName->partialHint());
CHECK_CONDITION(!rightName->isNewPersistenceUnit());
CHECK_STR_EQUAL("Right child", rightName->value());
}
示例12: nClockfiles
/// Get number of clock files in FileStore.
int nClockfiles(void) throw()
{ return (useSP3clock ? SP3Files.size() : clkFiles.size()); }
示例13: throw
/// Get number of SP3 files in FileStore.
int nSP3files(void) throw()
{ return SP3Files.size(); }
示例14: addFile
/// add filename and header to FileStore
/// @param string filename file name to be added
/// @param Rinex3NavHeader Rhead header to be added
void addFile(const std::string& filename, Rinex3NavHeader& head) throw()
{ NavFiles.addFile(filename,head); }
示例15:
OutputBuffer *RepRap::GetConfigResponse()
{
// We need some resources to return a valid config response...
OutputBuffer *response;
if (!OutputBuffer::Allocate(response))
{
return nullptr;
}
// Axis minima
response->copy("{\"axisMins\":");
char ch = '[';
for (size_t axis = 0; axis < AXES; axis++)
{
response->catf("%c%.2f", ch, platform->AxisMinimum(axis));
ch = ',';
}
// Axis maxima
response->cat("],\"axisMaxes\":");
ch = '[';
for (size_t axis = 0; axis < AXES; axis++)
{
response->catf("%c%.2f", ch, platform->AxisMaximum(axis));
ch = ',';
}
// Accelerations
response->cat("],\"accelerations\":");
ch = '[';
for (size_t drive = 0; drive < DRIVES; drive++)
{
response->catf("%c%.2f", ch, platform->Acceleration(drive));
ch = ',';
}
// Motor currents
response->cat("],\"currents\":");
ch = '[';
for (size_t drive = 0; drive < DRIVES; drive++)
{
response->catf("%c%.2f", ch, platform->MotorCurrent(drive));
ch = ',';
}
// Firmware details
response->catf("],\"firmwareElectronics\":\"%s\"", ELECTRONICS);
response->catf(",\"firmwareName\":\"%s\"", NAME);
response->catf(",\"firmwareVersion\":\"%s\"", VERSION);
response->catf(",\"firmwareDate\":\"%s\"", DATE);
// Motor idle parameters
response->catf(",\"idleCurrentFactor\":%.1f", platform->GetIdleCurrentFactor() * 100.0);
response->catf(",\"idleTimeout\":%.1f", move->IdleTimeout());
// Minimum feedrates
response->cat(",\"minFeedrates\":");
ch = '[';
for (size_t drive = 0; drive < DRIVES; drive++)
{
response->catf("%c%.2f", ch, platform->ConfiguredInstantDv(drive));
ch = ',';
}
// Maximum feedrates
response->cat("],\"maxFeedrates\":");
ch = '[';
for (size_t drive = 0; drive < DRIVES; drive++)
{
response->catf("%c%.2f", ch, platform->MaxFeedrate(drive));
ch = ',';
}
// Configuration File (whitespaces are skipped, otherwise we easily risk overflowing the response buffer)
response->cat("],\"configFile\":\"");
FileStore *configFile = platform->GetFileStore(platform->GetSysDir(), platform->GetConfigFile(), false);
if (configFile == nullptr)
{
response->cat("not found");
}
else
{
char c, esc;
bool readingWhitespace = false;
size_t bytesWritten = 0, bytesLeft = OutputBuffer::GetBytesLeft(response);
while (configFile->Read(c) && bytesWritten + 4 < bytesLeft) // need 4 bytes to finish this response
{
if (!readingWhitespace || (c != ' ' && c != '\t'))
{
switch (c)
{
case '\r':
esc = 'r';
break;
case '\n':
esc = 'n';
break;
case '\t':
esc = 't';
break;
//.........这里部分代码省略.........