本文整理汇总了C++中BNode::WriteAttr方法的典型用法代码示例。如果您正苦于以下问题:C++ BNode::WriteAttr方法的具体用法?C++ BNode::WriteAttr怎么用?C++ BNode::WriteAttr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BNode
的用法示例。
在下文中一共展示了BNode::WriteAttr方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
status_t
write_read_attr(BNode& node, read_flags flag)
{
if (node.WriteAttr(B_MAIL_ATTR_READ, B_INT32_TYPE, 0, &flag, sizeof(int32))
< 0)
return B_ERROR;
#if R5_COMPATIBLE
// manage the status string only if it currently has a "read" status
BString currentStatus;
if (node.ReadAttrString(B_MAIL_ATTR_STATUS, ¤tStatus) == B_OK) {
if (currentStatus.ICompare("New") != 0
&& currentStatus.ICompare("Read") != 0
&& currentStatus.ICompare("Seen") != 0)
return B_OK;
}
const char* statusString = (flag == B_READ) ? "Read"
: (flag == B_SEEN) ? "Seen" : "New";
if (node.WriteAttr(B_MAIL_ATTR_STATUS, B_STRING_TYPE, 0, statusString,
strlen(statusString)) < 0)
return B_ERROR;
#endif
return B_OK;
}
示例2:
void
BepdfApplication::UpdateAttr(BNode &node, const char *name, type_code type, off_t offset, void *buffer, size_t length) {
char dummy[10];
if (B_ENTRY_NOT_FOUND == node.ReadAttr(name, type, offset, (char*)dummy, sizeof(dummy))) {
node.WriteAttr(name, type, offset, buffer, length);
}
}
示例3: while
/* copy atribytes */
bool
BF_GUI_FilesPanel_CopyTask::Copy_Atributes(BNode & o_NodeSrc,BNode & o_NodeDest)
{
char pcName[B_ATTR_NAME_LENGTH];
attr_info uAttrInfo;
uint32 iBufMaxSize=255;
char *pcBuf = (char*)malloc(iBufMaxSize);
o_NodeSrc.RewindAttrs();
//
while(B_OK==o_NodeSrc.GetNextAttrName(pcName)) {
if(B_OK==o_NodeSrc.GetAttrInfo(pcName,&uAttrInfo)) {
/* check buffer size */
if(uAttrInfo.size>iBufMaxSize) {
DELETE(pcBuf);
iBufMaxSize = uAttrInfo.size;
pcBuf = (char*)malloc(iBufMaxSize);
}
/* read attr */
o_NodeSrc.ReadAttr(pcName,uAttrInfo.type,0,
(void*)pcBuf,uAttrInfo.size);
/* write attr */
o_NodeDest.WriteAttr(pcName,uAttrInfo.type,
0,(void*)pcBuf,uAttrInfo.size);
/* check for cancel_process */
if(Canceled()) return false;
}
}
DELETE(pcBuf);
return true;
}/* end of atributes */
示例4: sizeof
status_t
IMAPFolder::_WriteUInt32(BNode& node, const char* attribute, uint32 value) const
{
ssize_t bytesWritten = node.WriteAttr(attribute, B_UINT32_TYPE, 0,
&value, sizeof(uint32));
if (bytesWritten == (ssize_t)sizeof(uint32))
return B_OK;
return bytesWritten < 0 ? bytesWritten : B_IO_ERROR;
}
示例5:
status_t
IMAPStorage::_WriteUniqueID(BNode& node, int32 uid)
{
BString uidString;
uidString << uid;
ssize_t written = node.WriteAttr("MAIL:unique_id", B_STRING_TYPE, 0,
uidString.String(), uidString.Length());
if (written < 0)
return written;
return B_OK;
}
示例6: WriteSetting
/* WriteSetting
* this method writes a setting to the settings file (boolean)
*/
void IOSettings::WriteSetting(const char* Setting, bool SettCont)
{
if(!SettingsFileExists())
CreateSettingsFile();
BNode objNode;
objNode.SetTo(fSettingsFile.String());
if(objNode.WriteAttr(Setting, B_BOOL_TYPE, 0, (void*)&SettCont, sizeof(SettCont)) == B_FILE_ERROR)
throw new IOSettingsException(new BString("can't write attr. to settings file (IOSettings::WriteSetting(const char* Setting, bool SettCont))"));
}
示例7: sizeof
status_t
IMAPStorage::_WriteFlags(int32 flags, BNode& node)
{
if ((flags & kSeen) != 0)
write_read_attr(node, B_READ);
else
write_read_attr(node, B_UNREAD);
ssize_t writen = node.WriteAttr("MAIL:server_flags", B_INT32_TYPE, 0,
&flags, sizeof(int32));
if (writen != sizeof(int32))
return writen;
return B_OK;
}
示例8: ModifyRestoreAttribute
// Add or Remove OpenTracker's Restore attribute
void SFileWorker::ModifyRestoreAttribute(const SFileList *fileList, bool add)
{
SFile *file;
BNode node;
for(int32 i=0; i<fileList->CountItems();i++)
{
file=(SFile*)fileList->ItemAt(i);
if(!file)
continue;
if(node.SetTo(file->Ref())!=B_OK)
continue;
if(add)
{
node.WriteAttr("_trk/original_path",B_STRING_TYPE,0,
file->PathDesc(),strlen(file->PathDesc())+1);
}
else
node.RemoveAttr("_trk/original_path");
}
}
示例9: if
/*
* this method is not currently being used, but it may be useful in the
* future...
*/
status_t
DefaultCatalog::WriteToAttribute(entry_ref *appOrAddOnRef)
{
BNode node;
status_t res = node.SetTo(appOrAddOnRef);
if (res != B_OK)
return res;
BMallocIO mallocIO;
mallocIO.SetBlockSize(max(fCatMap.Size() * 20, 256L));
// set a largish block-size in order to avoid reallocs
res = Flatten(&mallocIO);
if (res == B_OK) {
ssize_t wsz;
wsz = node.WriteAttr(BLocaleRoster::kEmbeddedCatAttr, B_MESSAGE_TYPE, 0,
mallocIO.Buffer(), mallocIO.BufferLength());
if (wsz < B_OK)
res = wsz;
else if (wsz != (ssize_t)mallocIO.BufferLength())
res = B_ERROR;
}
return res;
}
示例10: lock
/*
iterate over add-on-folders and collect information about each
catalog-add-ons (types of catalogs) into fCatalogAddOnInfos.
*/
status_t
LocaleRosterData::_InitializeCatalogAddOns()
{
BAutolock lock(fLock);
if (!lock.IsLocked())
return B_ERROR;
// add info about embedded default catalog:
CatalogAddOnInfo* defaultCatalogAddOnInfo
= new(std::nothrow) CatalogAddOnInfo("Default", "",
DefaultCatalog::kDefaultCatalogAddOnPriority);
if (!defaultCatalogAddOnInfo)
return B_NO_MEMORY;
defaultCatalogAddOnInfo->fInstantiateFunc = DefaultCatalog::Instantiate;
defaultCatalogAddOnInfo->fCreateFunc = DefaultCatalog::Create;
fCatalogAddOnInfos.AddItem((void*)defaultCatalogAddOnInfo);
directory_which folders[] = {
B_USER_ADDONS_DIRECTORY,
B_COMMON_ADDONS_DIRECTORY,
B_SYSTEM_ADDONS_DIRECTORY,
};
BPath addOnPath;
BDirectory addOnFolder;
char buf[4096];
status_t err;
for (uint32 f = 0; f < sizeof(folders) / sizeof(directory_which); ++f) {
find_directory(folders[f], &addOnPath);
BString addOnFolderName(addOnPath.Path());
addOnFolderName << "/locale/catalogs";
system_info info;
if (get_system_info(&info) == B_OK
&& (info.abi & B_HAIKU_ABI_MAJOR)
!= (B_HAIKU_ABI & B_HAIKU_ABI_MAJOR)) {
switch (B_HAIKU_ABI & B_HAIKU_ABI_MAJOR) {
case B_HAIKU_ABI_GCC_2:
addOnFolderName << "/gcc2";
break;
case B_HAIKU_ABI_GCC_4:
addOnFolderName << "/gcc4";
break;
}
}
err = addOnFolder.SetTo(addOnFolderName.String());
if (err != B_OK)
continue;
// scan through all the folder's entries for catalog add-ons:
int32 count;
int8 priority;
entry_ref eref;
BNode node;
BEntry entry;
dirent* dent;
while ((count = addOnFolder.GetNextDirents((dirent*)buf, 4096)) > 0) {
dent = (dirent*)buf;
while (count-- > 0) {
if (strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")
&& strcmp(dent->d_name, "gcc2")
&& strcmp(dent->d_name, "gcc4")) {
// we have found (what should be) a catalog-add-on:
eref.device = dent->d_pdev;
eref.directory = dent->d_pino;
eref.set_name(dent->d_name);
entry.SetTo(&eref, true);
// traverse through any links to get to the real thang!
node.SetTo(&entry);
priority = -1;
if (node.ReadAttr(kPriorityAttr, B_INT8_TYPE, 0,
&priority, sizeof(int8)) <= 0) {
// add-on has no priority-attribute yet, so we load it
// to fetch the priority from the corresponding
// symbol...
BString fullAddOnPath(addOnFolderName);
fullAddOnPath << "/" << dent->d_name;
image_id image = load_add_on(fullAddOnPath.String());
if (image >= B_OK) {
uint8* prioPtr;
if (get_image_symbol(image, "gCatalogAddOnPriority",
B_SYMBOL_TYPE_DATA,
(void**)&prioPtr) == B_OK) {
priority = *prioPtr;
node.WriteAttr(kPriorityAttr, B_INT8_TYPE, 0,
&priority, sizeof(int8));
}
unload_add_on(image);
}
}
if (priority >= 0) {
// add-ons with priority < 0 will be ignored
CatalogAddOnInfo* addOnInfo
//.........这里部分代码省略.........
示例11: lock
/*
iterate over add-on-folders and collect information about each
catalog-add-ons (types of catalogs) into fCatalogAddOnInfos.
*/
status_t
LocaleRosterData::_InitializeCatalogAddOns()
{
BAutolock lock(fLock);
if (!lock.IsLocked())
return B_ERROR;
// add info about embedded default catalog:
CatalogAddOnInfo* defaultCatalogAddOnInfo
= new(std::nothrow) CatalogAddOnInfo("Default", "",
DefaultCatalog::kDefaultCatalogAddOnPriority);
if (!defaultCatalogAddOnInfo)
return B_NO_MEMORY;
defaultCatalogAddOnInfo->fInstantiateFunc = DefaultCatalog::Instantiate;
defaultCatalogAddOnInfo->fCreateFunc = DefaultCatalog::Create;
fCatalogAddOnInfos.AddItem((void*)defaultCatalogAddOnInfo);
BStringList folders;
BPathFinder::FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, "locale/catalogs/",
B_FIND_PATH_EXISTING_ONLY, folders);
BPath addOnPath;
BDirectory addOnFolder;
char buf[4096];
status_t err;
for (int32 f = 0; f < folders.CountStrings(); f++) {
BString addOnFolderName = folders.StringAt(f);
err = addOnFolder.SetTo(addOnFolderName.String());
if (err != B_OK)
continue;
// scan through all the folder's entries for catalog add-ons:
int32 count;
int8 priority;
entry_ref eref;
BNode node;
BEntry entry;
dirent* dent;
while ((count = addOnFolder.GetNextDirents((dirent*)buf, sizeof(buf)))
> 0) {
dent = (dirent*)buf;
while (count-- > 0) {
if (strcmp(dent->d_name, ".") != 0
&& strcmp(dent->d_name, "..") != 0
&& strcmp(dent->d_name, "x86") != 0
&& strcmp(dent->d_name, "x86_gcc2") != 0) {
// we have found (what should be) a catalog-add-on:
eref.device = dent->d_pdev;
eref.directory = dent->d_pino;
eref.set_name(dent->d_name);
entry.SetTo(&eref, true);
// traverse through any links to get to the real thang!
node.SetTo(&entry);
priority = -1;
if (node.ReadAttr(kPriorityAttr, B_INT8_TYPE, 0,
&priority, sizeof(int8)) <= 0) {
// add-on has no priority-attribute yet, so we load it
// to fetch the priority from the corresponding
// symbol...
BString fullAddOnPath(addOnFolderName);
fullAddOnPath << "/" << dent->d_name;
image_id image = load_add_on(fullAddOnPath.String());
if (image >= B_OK) {
uint8* prioPtr;
if (get_image_symbol(image, "gCatalogAddOnPriority",
B_SYMBOL_TYPE_DATA,
(void**)&prioPtr) == B_OK) {
priority = *prioPtr;
node.WriteAttr(kPriorityAttr, B_INT8_TYPE, 0,
&priority, sizeof(int8));
}
unload_add_on(image);
}
}
if (priority >= 0) {
// add-ons with priority < 0 will be ignored
CatalogAddOnInfo* addOnInfo
= new(std::nothrow) CatalogAddOnInfo(dent->d_name,
addOnFolderName, priority);
if (addOnInfo)
fCatalogAddOnInfos.AddItem((void*)addOnInfo);
}
}
// Bump the dirent-pointer by length of the dirent just handled:
dent = (dirent*)((char*)dent + dent->d_reclen);
}
}
}
fCatalogAddOnInfos.SortItems(CompareInfos);
return B_OK;
}
示例12: if
//.........这里部分代码省略.........
// If we are auto-training, feed back the message to the server as a
// training example (don't train if it is uncertain). Also redo the
// evaluation after training.
if (fAutoTraining) {
if (spamRatio >= fSpamCutoffRatio || spamRatio < fGenuineCutoffRatio) {
scriptingMessage.MakeEmpty ();
scriptingMessage.what = B_SET_PROPERTY;
scriptingMessage.AddSpecifier ((spamRatio >= fSpamCutoffRatio)
? "SpamString" : "GenuineString");
errorCode = scriptingMessage.AddData ("data", B_STRING_TYPE,
stringBuffer, dataSize + 1, false /* fixed size */);
if (errorCode != B_OK)
goto ErrorExit;
replyMessage.MakeEmpty ();
errorCode = fMessengerToServer.SendMessage (&scriptingMessage,
&replyMessage);
if (errorCode != B_OK
|| replyMessage.FindInt32 ("error", &errorCode) != B_OK)
goto ErrorExit; // Unable to read the return code.
if (errorCode != B_OK)
goto ErrorExit; // Failed to set a good example.
}
// Note the kind of example made so that the user doesn't reclassify
// the message twice (the spam server looks for this attribute).
classificationString =
(spamRatio >= fSpamCutoffRatio)
? "Spam"
: ((spamRatio < fGenuineCutoffRatio) ? "Genuine" : "Uncertain");
if (nodeForOutputFileInitialised)
nodeForOutputFile.WriteAttr ("MAIL:classification", B_STRING_TYPE,
0 /* offset */, classificationString,
strlen (classificationString) + 1);
// Now that the database has changed due to training, recompute the
// spam ratio. Hopefully it will have become more extreme in the
// correct direction (not switched from being spam to being genuine).
// Code copied from above.
scriptingMessage.MakeEmpty ();
scriptingMessage.what = B_SET_PROPERTY;
scriptingMessage.AddSpecifier ("EvaluateString");
errorCode = scriptingMessage.AddData ("data", B_STRING_TYPE,
stringBuffer, dataSize + 1, false /* fixed size */);
if (errorCode != B_OK)
goto ErrorExit;
replyMessage.MakeEmpty ();
errorCode = fMessengerToServer.SendMessage (&scriptingMessage,
&replyMessage);
if (errorCode != B_OK
|| replyMessage.FindInt32 ("error", &errorCode) != B_OK)
goto ErrorExit; // Unable to read the return code.
if (errorCode == ENOMSG && fNoWordsMeansSpam)
spamRatio = fSpamCutoffRatio; // Yes, no words and that means spam.
else if (errorCode != B_OK
|| replyMessage.FindFloat ("result", &spamRatio) != B_OK)
goto ErrorExit; // Classification failed in one of many ways.
}
// Store the spam ratio in an attribute called MAIL:ratio_spam,
// attached to the eventual output file.
if (nodeForOutputFileInitialised)
示例13: Buffer
/*!
Convert the plain text (UTF8) from inSource to plain or
styled text in outDestination
*/
status_t
translate_from_text(BPositionIO* source, const char* encoding, bool forceEncoding,
BPositionIO* destination, uint32 outType)
{
if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT)
return B_BAD_VALUE;
// find the length of the text
off_t size = source->Seek(0, SEEK_END);
if (size < 0)
return (status_t)size;
if (size > UINT32_MAX && outType == B_STYLED_TEXT_FORMAT)
return B_NOT_SUPPORTED;
status_t status = source->Seek(0, SEEK_SET);
if (status < B_OK)
return status;
if (outType == B_STYLED_TEXT_FORMAT) {
// output styled text headers
status = output_headers(destination, (uint32)size);
if (status != B_OK)
return status;
}
class MallocBuffer {
public:
MallocBuffer() : fBuffer(NULL), fSize(0) {}
~MallocBuffer() {
free(fBuffer);
}
void* Buffer() {
return fBuffer;
}
size_t Size() const {
return fSize;
}
status_t
Allocate(size_t size)
{
fBuffer = malloc(size);
if (fBuffer != NULL) {
fSize = size;
return B_OK;
}
return B_NO_MEMORY;
}
private:
void* fBuffer;
size_t fSize;
} encodingBuffer;
BMallocIO encodingIO;
uint32 encodingID = 0;
// defaults to UTF-8 or no encoding
BNode* node = dynamic_cast<BNode*>(source);
if (node != NULL) {
// determine encoding, if available
const BCharacterSet* characterSet = NULL;
bool hasAttribute = false;
if (encoding != NULL && !forceEncoding) {
BString name;
if (node->ReadAttrString("be:encoding", &name) == B_OK) {
encoding = name.String();
hasAttribute = true;
} else {
int32 value;
ssize_t bytesRead = node->ReadAttr("be:encoding", B_INT32_TYPE, 0,
&value, sizeof(value));
if (bytesRead == (ssize_t)sizeof(value)) {
hasAttribute = true;
if (value != 65535)
characterSet = BCharacterSetRoster::GetCharacterSetByConversionID(value);
}
}
} else {
hasAttribute = true;
// we don't write the encoding in this case
}
if (characterSet == NULL && encoding != NULL)
characterSet = BCharacterSetRoster::FindCharacterSetByName(encoding);
if (characterSet != NULL) {
encodingID = characterSet->GetConversionID();
encodingBuffer.Allocate(READ_BUFFER_SIZE * 4);
}
if (!hasAttribute && encoding != NULL) {
// add encoding attribute, so that someone opening the file can
// retrieve it for persistance
node->WriteAttr("be:encoding", B_STRING_TYPE, 0, encoding,
strlen(encoding));
}
//.........这里部分代码省略.........