本文整理汇总了C++中MemChunk::write方法的典型用法代码示例。如果您正苦于以下问题:C++ MemChunk::write方法的具体用法?C++ MemChunk::write怎么用?C++ MemChunk::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemChunk
的用法示例。
在下文中一共展示了MemChunk::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getIndexedData
/* SImage::getIndexedData
* Loads the image as index data into <mc>. Returns false if image is
* invalid, true otherwise
*******************************************************************/
bool SImage::getIndexedData(MemChunk& mc)
{
// Check the image is valid
if (!isValid())
return false;
// Init rgb data
mc.reSize(width * height, false);
// Cannot do this for trucolor graphics.
if (type == RGBA)
return false;
else if (type == PALMASK)
{
mc.write(data, width * height);
return true;
}
else if (type == ALPHAMAP)
{
mc.write(data, width * height);
return true;
}
return false; // Invalid image type
}
示例2: onAnnouncement
// -----------------------------------------------------------------------------
// Called when an announcement is recieved from one of the archives in the list
// -----------------------------------------------------------------------------
void ArchiveManager::onAnnouncement(Announcer* announcer, const string& event_name, MemChunk& event_data)
{
// Reset event data for reading
event_data.seek(0, SEEK_SET);
// Check that the announcement came from an archive in the list
int32_t index = archiveIndex((Archive*)announcer);
if (index >= 0)
{
// If the archive was saved
if (event_name == "saved")
{
MemChunk mc;
mc.write(&index, 4);
announce("archive_saved", mc);
}
// If the archive was modified
if (event_name == "modified" || event_name == "entry_modified")
{
MemChunk mc;
mc.write(&index, 4);
announce("archive_modified", mc);
}
}
}
示例3: saveEntry
/* AnimatedEntryPanel::saveEntry
* Saves any changes made to the entry
*******************************************************************/
bool AnimatedEntryPanel::saveEntry()
{
MemChunk mc;
mc.seek(0, SEEK_SET);
animated_t anim;
for (uint32_t a = 0; a < animated.nEntries(); a++)
{
AnimatedEntry* ent = animated.getEntry(a);
for (size_t i = 0; i < 9; ++i)
{
if (ent->getFirst().length() > i)
anim.first[i] = ent->getFirst()[i];
else anim.first[i] = 0;
if (ent->getLast().length() > i)
anim.last[i] = ent->getLast()[i];
else anim.last[i] = 0;
}
anim.speed = ent->getSpeed();
anim.type = ent->getType();
if (ent->getDecals()) anim.type |= ANIM_DECALS;
mc.write(&anim, 23);
}
anim.type = 255;
mc.write(&anim, 1);
bool success = entry->importMemChunk(mc);
if (success)
{
for (uint32_t a = 0; a < animated.nEntries(); a++)
list_entries->setItemStatus(a, LV_STATUS_NORMAL);
}
return success;
}
示例4: saveEntry
/* SwitchesEntryPanel::saveEntry
* Saves any changes made to the entry
*******************************************************************/
bool SwitchesEntryPanel::saveEntry()
{
MemChunk mc;
mc.seek(0, SEEK_SET);
switches_t swch;
for (uint32_t a = 0; a < switches.nEntries(); a++)
{
SwitchesEntry* ent = switches.getEntry(a);
for (size_t i = 0; i < 9; ++i)
{
if (ent->getOff().length() > i)
swch.off[i] = ent->getOff()[i];
else swch.off[i] = 0;
if (ent->getOn().length() > i)
swch.on[i] = ent->getOn()[i];
else swch.on[i] = 0;
}
swch.type = ent->getType();
mc.write(&swch, 20);
}
memset(&swch, 0, 20);
mc.write(&swch, 20);
bool success = entry->importMemChunk(mc);
if (success)
{
for (uint32_t a = 0; a < switches.nEntries(); a++)
list_entries->setItemStatus(a, LV_STATUS_NORMAL);
}
return success;
}
示例5: entryAt
// -----------------------------------------------------------------------------
// Writes the wad archive to a MemChunk
// Returns true if successful, false otherwise
// -----------------------------------------------------------------------------
bool Wad2Archive::write(MemChunk& mc, bool update)
{
// Determine directory offset & individual lump offsets
uint32_t dir_offset = 12;
ArchiveEntry* entry = nullptr;
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = entryAt(l);
entry->exProp("Offset") = (int)dir_offset;
dir_offset += entry->size();
}
// Clear/init MemChunk
mc.clear();
mc.seek(0, SEEK_SET);
mc.reSize(dir_offset + numEntries() * 32);
// Setup wad type
char wad_type[4] = { 'W', 'A', 'D', '2' };
if (wad3_)
wad_type[3] = '3';
// Write the header
uint32_t num_lumps = numEntries();
mc.write(wad_type, 4);
mc.write(&num_lumps, 4);
mc.write(&dir_offset, 4);
// Write the lumps
for (uint32_t l = 0; l < num_lumps; l++)
{
entry = entryAt(l);
mc.write(entry->rawData(), entry->size());
}
// Write the directory
for (uint32_t l = 0; l < num_lumps; l++)
{
entry = entryAt(l);
// Setup directory entry
Wad2Entry info;
memset(info.name, 0, 16);
memcpy(info.name, CHR(entry->name()), entry->name().Len());
info.cmprs = (bool)entry->exProp("W2Comp");
info.dsize = entry->size();
info.size = entry->size();
info.offset = (int)entry->exProp("Offset");
info.type = (int)entry->exProp("W2Type");
// Write it
mc.write(&info, 32);
if (update)
entry->setState(ArchiveEntry::State::Unmodified);
}
return true;
}
示例6: getRGBAData
/* SImage::getRGBAData
* Loads the image as RGBA data into <mc>. Returns false if image is
* invalid, true otherwise
*******************************************************************/
bool SImage::getRGBAData(MemChunk& mc, Palette8bit* pal)
{
// Check the image is valid
if (!isValid())
return false;
// Init rgba data
mc.reSize(width * height * 4, false);
// If data is already in RGBA format just return a copy
if (type == RGBA)
{
mc.importMem(data, width * height * 4);
return true;
}
// Convert paletted
else if (type == PALMASK)
{
// Get palette to use
if (has_palette || !pal)
pal = &palette;
uint8_t rgba[4];
for (int a = 0; a < width * height; a++)
{
// Get colour
rgba_t col = pal->colour(data[a]);
// Set alpha
if (mask)
col.a = mask[a];
else
col.a = 255;
col.write(rgba); // Write colour to array
mc.write(rgba, 4); // Write array to MemChunk
}
return true;
}
// Convert if alpha map
else if (type == ALPHAMAP)
{
uint8_t rgba[4];
rgba_t col;
for (int a = 0; a < width * height; a++)
{
// Get pixel as colour (greyscale)
col.set(data[a], data[a], data[a], data[a]);
col.write(rgba); // Write colour to array
mc.write(rgba, 4); // Write array to MemChunk
}
}
return false; // Invalid image type
}
示例7: openDirArchive
// -----------------------------------------------------------------------------
// Opens [dir] as a DirArchive and adds it to the list.
// Returns a pointer to the archive or nullptr if an error occurred.
// -----------------------------------------------------------------------------
Archive* ArchiveManager::openDirArchive(const string& dir, bool manage, bool silent)
{
auto new_archive = getArchive(dir);
LOG_MESSAGE(1, "Opening directory %s as archive", dir);
// If the archive is already open, just return it
if (new_archive)
{
// Announce open
if (!silent)
{
MemChunk mc;
uint32_t index = archiveIndex(new_archive);
mc.write(&index, 4);
announce("archive_opened", mc);
}
return new_archive;
}
new_archive = new DirArchive();
// If it opened successfully, add it to the list if needed & return it,
// Otherwise, delete it and return nullptr
if (new_archive->open(dir))
{
if (manage)
{
// Add the archive
addArchive(new_archive);
// Announce open
if (!silent)
{
MemChunk mc;
uint32_t index = archiveIndex(new_archive);
mc.write(&index, 4);
announce("archive_opened", mc);
}
// Add to recent files
addRecentFile(dir);
}
// Return the opened archive
return new_archive;
}
else
{
LOG_MESSAGE(1, "Error: " + Global::error);
delete new_archive;
return nullptr;
}
}
示例8: removeEntry
/* Archive::removeEntry
* Removes [entry] from the archive. If [delete_entry] is true, the
* entry will also be deleted. Returns true if the removal succeeded
*******************************************************************/
bool Archive::removeEntry(ArchiveEntry* entry, bool delete_entry)
{
// Abort if read only
if (read_only)
return false;
// Check entry
if (!checkEntry(entry))
return false;
// Check if entry is locked
if (entry->isLocked())
return false;
// Get its directory
ArchiveTreeNode* dir = entry->getParentDir();
// Error if entry has no parent directory
if (!dir)
return false;
// Create undo step
if (UndoRedo::currentlyRecording())
UndoRedo::currentManager()->recordUndoStep(new EntryCreateDeleteUS(false, entry));
// Get the entry index
int index = dir->entryIndex(entry);
// Announce (before actually removing in case entry is still needed)
MemChunk mc;
wxUIntPtr ptr = wxPtrToUInt(entry);
mc.write(&index, sizeof(int));
mc.write(&ptr, sizeof(wxUIntPtr));
announce("entry_removing", mc);
// Remove it from its directory
bool ok = dir->removeEntry(index);
// If it was removed ok
if (ok)
{
// Announce removed
announce("entry_removed", mc);
// Delete if necessary
if (delete_entry)
delete entry;
// Update variables etc
setModified(true);
}
return ok;
}
示例9: getRGBData
/* SImage::getRGBData
* Loads the image as RGB data into <mc>. Returns false if image is
* invalid, true otherwise
*******************************************************************/
bool SImage::getRGBData(MemChunk& mc, Palette8bit* pal)
{
// Check the image is valid
if (!isValid())
return false;
// Init rgb data
mc.reSize(width * height * 3, false);
if (type == RGBA)
{
// RGBA format, remove alpha information
for (int a = 0; a < width * height * 4; a += 4)
mc.write(&data[a], 3);
return true;
}
else if (type == PALMASK)
{
// Paletted, convert to RGB
// Get palette to use
if (has_palette || !pal)
pal = &palette;
// Build RGB data
uint8_t rgba[4];
for (int a = 0; a < width * height; a ++)
{
pal->colour(data[a]).write(rgba);
mc.write(rgba, 3);
}
return true;
}
else if (type == ALPHAMAP)
{
// Alpha map, convert to RGB
uint8_t rgba[4];
rgba_t col;
for (int a = 0; a < width * height; a++)
{
// Get pixel as colour (greyscale)
col.set(data[a], data[a], data[a], data[a]);
col.write(rgba); // Write colour to array
mc.write(rgba, 3); // Write array to MemChunk
}
}
return false; // Invalid image type
}
示例10: write
/* HogArchive::write
* Writes the hog archive to a MemChunk
* Returns true if successful, false otherwise
*******************************************************************/
bool HogArchive::write(MemChunk& mc, bool update)
{
// Determine individual lump offsets
uint32_t offset = 3;
ArchiveEntry* entry = NULL;
for (uint32_t l = 0; l < numEntries(); l++)
{
offset += 17;
entry = getEntry(l);
setEntryOffset(entry, offset);
if (update)
{
entry->setState(0);
entry->exProp("Offset") = (int)offset;
}
offset += entry->getSize();
}
// Clear/init MemChunk
mc.clear();
mc.seek(0, SEEK_SET);
mc.reSize(offset);
// Write the header
char header[3] = { 'D', 'H', 'F' };
mc.write(header, 3);
// Write the lumps
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
mc.write(entry->getData(), entry->getSize());
}
// Write the directory
for (uint32_t l = 0; l < numEntries(); l++)
{
entry = getEntry(l);
char name[13] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
long size = wxINT32_SWAP_ON_BE(entry->getSize());
for (size_t c = 0; c < entry->getName().length() && c < 13; c++)
name[c] = entry->getName()[c];
mc.write(name, 13);
mc.write(&size, 4);
mc.write(entry->getData(), entry->getSize());
}
return true;
}
示例11: createDir
/* Archive::createDir
* Creates a directory at [path], starting from [base]. If
* [base] is NULL, the root directory is used. Returns the created
* directory. If the directory requested to be created already
* exists, it will be returned
*******************************************************************/
ArchiveTreeNode* Archive::createDir(string path, ArchiveTreeNode* base)
{
// Abort if read only
if (read_only)
return dir_root;
// If no base dir specified, set it to root
if (!base)
base = dir_root;
if (path.IsEmpty())
return base;
// Create the directory
ArchiveTreeNode* dir = (ArchiveTreeNode*)((STreeNode*)base)->addChild(path);
// Record undo step
if (UndoRedo::currentlyRecording())
UndoRedo::currentManager()->recordUndoStep(new DirCreateDeleteUS(true, dir));
// Set the archive state to modified
setModified(true);
// Announce
MemChunk mc;
wxUIntPtr ptr = wxPtrToUInt(dir);
mc.write(&ptr, sizeof(wxUIntPtr));
announce("directory_added", mc);
return dir;
}
示例12: renameDir
// -----------------------------------------------------------------------------
// Renames [dir] to [new_name].
// Returns false if [dir] isn't part of the archive, true otherwise
// -----------------------------------------------------------------------------
bool Archive::renameDir(ArchiveTreeNode* dir, string_view new_name)
{
// Abort if read only
if (read_only_)
return false;
// Check the directory is part of this archive
if (!dir || dir->archive() != this)
return false;
// Rename the directory if needed
if (dir->name() == new_name)
{
if (UndoRedo::currentlyRecording())
UndoRedo::currentManager()->recordUndoStep(std::make_unique<DirRenameUS>(dir, new_name));
dir->setName(new_name);
dir->dirEntry()->setState(ArchiveEntry::State::Modified);
}
else
return true;
// Announce
MemChunk mc;
wxUIntPtr ptr = wxPtrToUInt(dir);
mc.write(&ptr, sizeof(wxUIntPtr));
announce("directory_modified", mc);
// Update variables etc
setModified(true);
return true;
}
示例13: renameDir
/* Archive::renameDir
* Renames [dir] to [new_name]. Returns false if [dir] isn't part of
* the archive, true otherwise
*******************************************************************/
bool Archive::renameDir(ArchiveTreeNode* dir, string new_name)
{
// Abort if read only
if (read_only)
return false;
// Check the directory is part of this archive
if (dir->getArchive() != this)
return false;
// Rename the directory if needed
if (!(S_CMPNOCASE(dir->getName(), new_name)))
{
if (UndoRedo::currentlyRecording())
UndoRedo::currentManager()->recordUndoStep(new DirRenameUS(dir, new_name));
dir->setName(new_name);
dir->getDirEntry()->setState(1);
}
else
return true;
// Announce
MemChunk mc;
wxUIntPtr ptr = wxPtrToUInt(dir);
mc.write(&ptr, sizeof(wxUIntPtr));
announce("directory_modified", mc);
// Update variables etc
setModified(true);
return true;
}
示例14: write
// -----------------------------------------------------------------------------
// Writes the grp archive to a MemChunk
// Returns true if successful, false otherwise
// -----------------------------------------------------------------------------
bool GrpArchive::write(MemChunk& mc, bool update)
{
// Clear/init MemChunk
mc.clear();
mc.seek(0, SEEK_SET);
mc.reSize((1 + numEntries()) * 16);
ArchiveEntry* entry;
// Write the header
uint32_t num_lumps = numEntries();
mc.write("KenSilverman", 12);
mc.write(&num_lumps, 4);
// Write the directory
for (uint32_t l = 0; l < num_lumps; l++)
{
entry = entryAt(l);
char name[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
long size = entry->size();
for (size_t c = 0; c < entry->name().length() && c < 12; c++)
name[c] = entry->name()[c];
mc.write(name, 12);
mc.write(&size, 4);
if (update)
{
long offset = getEntryOffset(entry);
entry->setState(ArchiveEntry::State::Unmodified);
entry->exProp("Offset") = (int)offset;
}
}
// Write the lumps
for (uint32_t l = 0; l < num_lumps; l++)
{
entry = entryAt(l);
mc.write(entry->rawData(), entry->size());
}
return true;
}
示例15: renameEntry
// -----------------------------------------------------------------------------
// Renames [entry] with [name].
// Returns false if the entry was invalid, true otherwise
// -----------------------------------------------------------------------------
bool Archive::renameEntry(ArchiveEntry* entry, string_view name)
{
// Abort if read only
if (read_only_)
return false;
// Check entry
if (!checkEntry(entry))
return false;
// Check if entry is locked
if (entry->isLocked())
return false;
// Check for directory
if (entry->type() == EntryType::folderType())
return renameDir(dir(entry->path(true)), name);
// Announce (before actually renaming in case old name is still needed)
MemChunk mc;
int index = entryIndex(entry);
wxUIntPtr ptr = wxPtrToUInt(entry);
mc.write(&index, sizeof(int));
mc.write(&ptr, sizeof(wxUIntPtr));
announce("entry_renaming", mc);
// Create undo step
if (UndoRedo::currentlyRecording())
UndoRedo::currentManager()->recordUndoStep(std::make_unique<EntryRenameUS>(entry, name));
// Rename the entry
entry->setName(name);
entry->formatName(formatDesc());
entry->setState(ArchiveEntry::State::Modified, true);
// Announce modification
entryStateChanged(entry);
return true;
}