本文整理汇总了C++中StringRef::copy方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::copy方法的具体用法?C++ StringRef::copy怎么用?C++ StringRef::copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringRef
的用法示例。
在下文中一共展示了StringRef::copy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Configure
GCodeResult Display::Configure(GCodeBuffer& gb, const StringRef& reply)
{
bool seen = false;
if (gb.Seen('P'))
{
seen = true;
switch (gb.GetUIValue())
{
case 1: // 12864 display
if (lcd == nullptr)
{
lcd = new Lcd7920(LcdCSPin, fonts, ARRAY_SIZE(fonts));
}
lcd->Init();
IoPort::SetPinMode(LcdBeepPin, OUTPUT_PWM_LOW);
lcd->SetFont(SmallFontNumber);
if (encoder == nullptr)
{
encoder = new RotaryEncoder(EncoderPinA, EncoderPinB, EncoderPinSw);
encoder->Init(DefaultPulsesPerClick);
}
if (menu == nullptr)
{
menu = new Menu(*lcd);
}
menu->Load("main");
break;
default:
reply.copy("Unknown display type");
return GCodeResult::error;
}
}
if (gb.Seen('E') && encoder != nullptr)
{
seen = true;
encoder->Init(gb.GetIValue()); // configure encoder pulses per click and direction
}
if (!seen)
{
if (lcd != nullptr)
{
reply.printf("12864 display is configured, pulses-per-click is %d", encoder->GetPulsesPerClick());
}
else
{
reply.copy("12864 display is not present or not configured");
}
}
return GCodeResult::ok;
}
示例2:
/*static*/ void MassStorage::CombineName(const StringRef& outbuf, const char* directory, const char* fileName)
{
outbuf.Clear();
size_t outIndex = 0;
size_t inIndex = 0;
// DC 2015-11-25 Only prepend the directory if the filename does not have an absolute path or volume specifier
if (directory != nullptr && fileName[0] != '/' && (strlen(fileName) < 2 || !isdigit(fileName[0]) || fileName[1] != ':'))
{
while (directory[inIndex] != 0 && directory[inIndex] != '\n')
{
outbuf.Pointer()[outIndex] = directory[inIndex];
inIndex++;
outIndex++;
if (outIndex >= outbuf.Capacity())
{
reprap.GetPlatform().MessageF(ErrorMessage, "CombineName() buffer overflow");
outbuf.copy("?????");
return;
}
}
if (inIndex > 0 && directory[inIndex - 1] != '/')
{
outbuf.Pointer()[outIndex] = '/';
outIndex++;
}
inIndex = 0;
}
while (fileName[inIndex] != 0 && fileName[inIndex] != '\n')
{
if (outIndex >= outbuf.Capacity())
{
reprap.GetPlatform().Message(ErrorMessage, "file name too long");
outbuf.copy("?????");
return;
}
outbuf.Pointer()[outIndex] = fileName[inIndex];
inIndex++;
outIndex++;
}
outbuf.Pointer()[outIndex] = 0;
}
示例3: PrintTool
void RepRap::PrintTool(int toolNumber, StringRef& reply) const
{
Tool* tool = GetTool(toolNumber);
if (tool != nullptr)
{
tool->Print(reply);
}
else
{
reply.copy("Error: Attempt to print details of non-existent tool.\n");
}
}
示例4: addInsert
void Commit::addInsert(SourceLocation OrigLoc, FileOffset Offs, StringRef text,
bool beforePreviousInsertions) {
if (text.empty())
return;
Edit data;
data.Kind = Act_Insert;
data.OrigLoc = OrigLoc;
data.Offset = Offs;
data.Text = text.copy(StrAlloc);
data.BeforePrev = beforePreviousInsertions;
CachedEdits.push_back(data);
}
示例5: Unmount
// Unmount the specified SD card, returning true if done, false if needs to be called again.
// If an error occurs, return true with the error message in 'reply'.
GCodeResult MassStorage::Unmount(size_t card, const StringRef& reply)
{
if (card >= NumSdCards)
{
reply.copy("SD card number out of range");
return GCodeResult::error;
}
reply.printf("SD card %u may now be removed", card);
const unsigned int numFilesClosed = InternalUnmount(card, true);
if (numFilesClosed != 0)
{
reply.catf(" (%u file(s) were closed)", numFilesClosed);
}
return GCodeResult::ok;
}
示例6: copyIntoContext
static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
return str.copy(C);
}
示例7: Mount
// Mount the specified SD card, returning true if done, false if needs to be called again.
// If an error occurs, return true with the error message in 'reply'.
// This may only be called to mount one card at a time.
GCodeResult MassStorage::Mount(size_t card, const StringRef& reply, bool reportSuccess)
{
if (card >= NumSdCards)
{
reply.copy("SD card number out of range");
return GCodeResult::error;
}
SdCardInfo& inf = info[card];
MutexLocker lock1(fsMutex);
MutexLocker lock2(inf.volMutex);
if (!inf.mounting)
{
if (inf.isMounted)
{
if (AnyFileOpen(&inf.fileSystem))
{
// Don't re-mount the card if any files are open on it
reply.copy("SD card has open file(s)");
return GCodeResult::error;
}
(void)InternalUnmount(card, false);
}
inf.mountStartTime = millis();
inf.mounting = true;
delay(2);
}
if (inf.cardState == CardDetectState::notPresent)
{
reply.copy("No SD card present");
inf.mounting = false;
return GCodeResult::error;
}
if (inf.cardState != CardDetectState::present)
{
return GCodeResult::notFinished; // wait for debounce to finish
}
const sd_mmc_err_t err = sd_mmc_check(card);
if (err != SD_MMC_OK && millis() - inf.mountStartTime < 5000)
{
delay(2);
return GCodeResult::notFinished;
}
inf.mounting = false;
if (err != SD_MMC_OK)
{
reply.printf("Cannot initialise SD card %u: %s", card, TranslateCardError(err));
return GCodeResult::error;
}
// Mount the file systems
const char path[3] = { (char)('0' + card), ':', 0 };
const FRESULT mounted = f_mount(&inf.fileSystem, path, 1);
if (mounted != FR_OK)
{
reply.printf("Cannot mount SD card %u: code %d", card, mounted);
return GCodeResult::error;
}
inf.isMounted = true;
if (reportSuccess)
{
float capacity = ((float)sd_mmc_get_capacity(card) * 1024) / 1000000; // get capacity and convert from Kib to Mbytes
const char* capUnits;
if (capacity >= 1000.0)
{
capacity /= 1000;
capUnits = "Gb";
}
else
{
capUnits = "Mb";
}
reply.printf("%s card mounted in slot %u, capacity %.2f%s", TranslateCardType(sd_mmc_get_type(card)), card, (double)capacity, capUnits);
}
return GCodeResult::ok;
}