/* ASCII lowercase function (string version); See string.h */ ib_status_t ib_strlower(ib_strop_t op, ib_mpool_t *mp, char *str_in, char **str_out, ib_flags_t *result) { IB_FTRACE_INIT(); size_t len; ib_status_t rc = IB_OK; char *out = NULL; assert(mp != NULL); assert(str_in != NULL); assert(str_out != NULL); assert(result != NULL); len = strlen(str_in); switch(op) { case IB_STROP_INPLACE: out = str_in; rc = inplace(IB_STRFLAG_ALIAS, (uint8_t*)str_in, len, result); break; case IB_STROP_COPY: out = ib_mpool_strdup(mp, str_in); if (out == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } rc = inplace(IB_STRFLAG_NEWBUF, (uint8_t*)out, len, result); break; case IB_STROP_COW: { #if ((__GNUC__==4) && (__GNUC_MINOR__<3)) uint8_t *uint8ptr; rc = copy_on_write(mp, (uint8_t *)str_in, len+1, &uint8ptr, &len, result); out = (char *)uint8ptr; #else rc = copy_on_write(mp, (uint8_t *)str_in, len+1, (uint8_t **)&out, &len, result); #endif break; } default: IB_FTRACE_RET_STATUS(IB_EINVAL); } if (rc == IB_OK) { if (ib_flags_all(*result, IB_STRFLAG_MODIFIED)) { *(out+len) = '\0'; } *str_out = out; } IB_FTRACE_RET_STATUS(rc); }
// Renames a the file with the specified index to the new name. The new // filename is reflected by the ``file_storage`` returned by ``files()`` // but not by the one returned by ``orig_files()``. // // If you want to rename the base name of the torrent (for a multifile // torrent), you can copy the ``file_storage`` (see files() and // orig_files() ), change the name, and then use `remap_files()`_. // // The ``new_filename`` can both be a relative path, in which case the // file name is relative to the ``save_path`` of the torrent. If the // ``new_filename`` is an absolute path (i.e. ``is_complete(new_filename) // == true``), then the file is detached from the ``save_path`` of the // torrent. In this case the file is not moved when move_storage() is // invoked. void rename_file(int index, std::string const& new_filename) { TORRENT_ASSERT(is_loaded()); if (m_files.file_path(index) == new_filename) return; copy_on_write(); m_files.rename_file(index, new_filename); }
void BasicArray<T>::insert(std::size_t ndx, T value) { TIGHTDB_ASSERT(ndx <= m_size); // Check if we need to copy before modifying copy_on_write(); // Throws // Make room for the new value alloc(m_size+1, m_width); // Throws // Move values below insertion if (ndx != m_size) { char* base = reinterpret_cast<char*>(m_data); char* src_begin = base + ndx*m_width; char* src_end = base + m_size*m_width; char* dst_end = src_end + m_width; std::copy_backward(src_begin, src_end, dst_end); } // Set the value T* data = reinterpret_cast<T*>(m_data) + ndx; *data = value; ++m_size; }
inline void BasicArray<T>::set(std::size_t ndx, T value) { TIGHTDB_ASSERT(ndx < m_size); // Check if we need to copy before modifying copy_on_write(); // Throws // Set the value T* data = reinterpret_cast<T*>(m_data) + ndx; *data = value; }
template<class T> void BasicArray<T>::truncate(std::size_t size) { TIGHTDB_ASSERT(is_attached()); TIGHTDB_ASSERT(size <= m_size); copy_on_write(); // Throws // Update size in accessor and in header. This leaves the capacity // unchanged. m_size = size; set_header_size(size); }
/* Simple ASCII lowercase function (ex version); see string.h */ ib_status_t ib_strlower_ex(ib_strop_t op, ib_mpool_t *mp, uint8_t *data_in, size_t dlen_in, uint8_t **data_out, size_t *dlen_out, ib_flags_t *result) { IB_FTRACE_INIT(); ib_status_t rc = IB_OK; assert(mp != NULL); assert(data_in != NULL); assert(data_out != NULL); assert(dlen_out != NULL); assert(result != NULL); switch(op) { case IB_STROP_INPLACE: rc = inplace(IB_STRFLAG_ALIAS, data_in, dlen_in, result); *data_out = data_in; *dlen_out = dlen_in; break; case IB_STROP_COPY: *data_out = ib_mpool_alloc(mp, dlen_in); if (*data_out == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } *dlen_out = dlen_in; rc = inplace(IB_STRFLAG_NEWBUF, *data_out, dlen_in, result); break; case IB_STROP_COW: rc = copy_on_write(mp, data_in, dlen_in, data_out, dlen_out, result); break; default: IB_FTRACE_RET_STATUS(IB_EINVAL); } IB_FTRACE_RET_STATUS(rc); }
void BasicArray<T>::erase(std::size_t ndx) { TIGHTDB_ASSERT(ndx < m_size); // Check if we need to copy before modifying copy_on_write(); // Throws // move data under deletion up if (ndx < m_size-1) { char* base = reinterpret_cast<char*>(m_data); char* dst_begin = base + ndx*m_width; const char* src_begin = dst_begin + m_width; const char* src_end = base + m_size*m_width; std::copy(src_begin, src_end, dst_begin); } // Update size (also in header) --m_size; set_header_size(m_size); }
void rename_file(int index, std::wstring const& new_filename) { copy_on_write(); m_files.rename_file(index, new_filename); }
// Renames a the file with the specified index to the new name. The new // filename is reflected by the ``file_storage`` returned by ``files()`` // but not by the one returned by ``orig_files()``. // // If you want to rename the base name of the torrent (for a multifile // torrent), you can copy the ``file_storage`` (see files() and // orig_files() ), change the name, and then use `remap_files()`_. // // The ``new_filename`` can both be a relative path, in which case the // file name is relative to the ``save_path`` of the torrent. If the // ``new_filename`` is an absolute path (i.e. ``is_complete(new_filename) // == true``), then the file is detached from the ``save_path`` of the // torrent. In this case the file is not moved when move_storage() is // invoked. void rename_file(int index, std::string const& new_filename) { TORRENT_ASSERT(is_loaded()); copy_on_write(); m_files.rename_file(index, new_filename); }
void Pixmap::load_pixels( const void * p_pixels, const Size& p_size, PixmapFormat p_format ) { copy_on_write(); _pp->pixmap->load_pixels(p_pixels,p_size,p_format); }
Error Pixmap::load_file(const String& p_file) { copy_on_write(); return _pp->pixmap->load_file( p_file ); }
Error Pixmap::create(const Size& p_size,PixmapFormat p_format) { copy_on_write(); return _pp->pixmap->create(p_size,p_format); }