diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
commit | e38d2351b83fa65c66ccde443777647ef5cb6cff (patch) | |
tree | 1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/translators/pilotdb/libpalm | |
download | tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.tar.gz tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.zip |
Added KDE3 version of Tellico
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/translators/pilotdb/libpalm')
-rw-r--r-- | src/translators/pilotdb/libpalm/Block.cpp | 85 | ||||
-rw-r--r-- | src/translators/pilotdb/libpalm/Block.h | 186 | ||||
-rw-r--r-- | src/translators/pilotdb/libpalm/Database.cpp | 43 | ||||
-rw-r--r-- | src/translators/pilotdb/libpalm/Database.h | 181 | ||||
-rw-r--r-- | src/translators/pilotdb/libpalm/Makefile.am | 15 | ||||
-rw-r--r-- | src/translators/pilotdb/libpalm/Record.h | 168 | ||||
-rw-r--r-- | src/translators/pilotdb/libpalm/Resource.h | 85 | ||||
-rw-r--r-- | src/translators/pilotdb/libpalm/palmtypes.h | 117 |
8 files changed, 880 insertions, 0 deletions
diff --git a/src/translators/pilotdb/libpalm/Block.cpp b/src/translators/pilotdb/libpalm/Block.cpp new file mode 100644 index 0000000..c58f6f1 --- /dev/null +++ b/src/translators/pilotdb/libpalm/Block.cpp @@ -0,0 +1,85 @@ +/* + * palm-db-tools: Encapsulate "blocks" of data. + * Copyright (C) 2000 by Tom Dyas (tdyas@users.sourceforge.net) + * + * The PalmLib::Block class represents a generic block of data. It is + * used to simplify passing arrays of pi_char_t around. + */ + +#include <cstring> + +#include "Block.h" + +void PalmLib::Block::reserve(PalmLib::Block::size_type new_size) +{ + if (new_size > capacity()) { + // Allocate a new buffer containing a copy of the old with the + // remainder zero'ed out. + pointer new_data = new pi_char_t[new_size]; + memcpy(new_data, m_data, m_size); + memset(new_data + m_size, 0, new_size - m_size); + + // Replace the existing buffer. + delete [] m_data; + m_data = new_data; + m_size = new_size; + } +} + +void PalmLib::Block::resize(size_type new_size) +{ + if (new_size < m_size) { + // Copy the data that will remain to a new buffer and switch to it. + pointer new_data = new pi_char_t[new_size]; + memcpy(new_data, m_data, new_size); + + // Replace the existing buffer. + delete [] m_data; + m_data = new_data; + m_size = new_size; + } else if (new_size > m_size) { + // Copy the data that will remain to a new buffer and switch to it. + pointer new_data = new pi_char_t[new_size]; + memcpy(new_data, m_data, m_size); + memset(new_data + m_size, 0, new_size - m_size); + + // Replace the existing buffer. + delete [] m_data; + m_data = new_data; + m_size = new_size; + } +} + +void PalmLib::Block::assign(PalmLib::Block::const_pointer data, + const PalmLib::Block::size_type size) +{ + clear(); + if (data && size > 0) { + m_size = size; + m_data = new pi_char_t[m_size]; + memcpy(m_data, data, m_size); + } +} + +void PalmLib::Block::assign(const PalmLib::Block::size_type size, + const PalmLib::Block::value_type value) +{ + clear(); + if (size > 0) { + m_size = size; + m_data = new pi_char_t[m_size]; + memset(m_data, value, m_size); + } +} + +bool operator == (const PalmLib::Block& lhs, const PalmLib::Block& rhs) +{ + if (lhs.size() == rhs.size()) { + if (lhs.data()) { + if (memcmp(lhs.data(), rhs.data(), lhs.size()) != 0) + return false; + } + return true; + } + return false; +} diff --git a/src/translators/pilotdb/libpalm/Block.h b/src/translators/pilotdb/libpalm/Block.h new file mode 100644 index 0000000..6ed6069 --- /dev/null +++ b/src/translators/pilotdb/libpalm/Block.h @@ -0,0 +1,186 @@ +/* + * palm-db-tools: Encapsulate "blocks" of data. + * Copyright (C) 2000 by Tom Dyas (tdyas@users.sourceforge.net) + * + * The PalmLib::Block class represents a generic block of data. It is + * used to make passing pi_char_t buffers around very easy. The Record + * and Resource classes both inherit from this class. A STL interface + * is also attempted though it is probably not complete. + */ + +#ifndef __PALMLIB_BLOCK_H__ +#define __PALMLIB_BLOCK_H__ + +#include <algorithm> +#include <iterator> + +#include "palmtypes.h" + +namespace PalmLib { + + class Block { + public: + // STL: container type definitions + typedef PalmLib::pi_char_t value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + // STL: reverisible container type definitions +#ifdef __GNUG__ + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + typedef std::reverse_iterator<iterator> reverse_iterator; +#endif + + /** + * Default constructor. + */ + Block() : m_data(0), m_size(0) { } + + /** + * Constructor which fills the block from buffer "raw" with + * length "len". + */ + Block(const_pointer raw, const size_type len) : m_data(0), m_size(0) { + assign(raw, len); + } + + /** + * Constructor which takes a size and allocates a zero'ed out + * buffer of that size. (STL: Sequence: default fill + * constructor) + */ + Block(const size_type size, const value_type value = 0) + : m_data(0), m_size(0) { + assign(size, value); + } + + /** + * Constructor which takes two iterators and builds the block + * from the region between the iterators. (STL: Sequence: + * range constructor) + */ + Block(const_iterator a, const_iterator b) : m_data(0), m_size(0) { + assign(a, b - a); + } + + /** + * Copy constructor. Just copies the data from the other block + * into this block. + */ + Block(const Block& rhs) : m_data(0), m_size(0) { + assign(rhs.data(), rhs.size()); + } + + /** + * Destructor. Just frees the buffer if it exists. + */ + virtual ~Block() { clear(); } + + /** + * Assignment operator. + * + * @param rhs The block whose contents should be copied. + */ + Block& operator = (const Block& rhs) { + assign(rhs.data(), rhs.size()); + return *this; + } + + // STL: Container + iterator begin() { return m_data; } + const_iterator begin() const { return m_data; } + iterator end() { return (m_data != 0) ? (m_data + m_size) : (0); } + const_iterator end() const + { return (m_data != 0) ? (m_data + m_size) : (0); } + size_type size() const { return m_size; } + size_type max_size() const { + return size_type(-1) / sizeof(value_type); + } + bool empty() const { return m_size == 0; } + + // STL: Reversible Container +#ifdef __GNUG__ + reverse_iterator rbegin() { return reverse_iterator(end()); } + const_reverse_iterator rbegin() const { + return const_reverse_iterator(end()); + } + reverse_iterator rend() { return reverse_iterator(begin()); } + const_reverse_iterator rend() const { + return const_reverse_iterator(begin()); + } +#endif + + // STL: Random Access Container + reference operator [] (size_type index) { return m_data[index]; } + const_reference operator [] (size_type index) const + { return m_data[index]; } + + // STL: Sequence (not complete) + void clear() { + if (m_data) { + delete [] m_data; + m_data = 0; + m_size = 0; + } + } + void resize(size_type n); + reference front() { return m_data[0]; } + const_reference front() const { return m_data[0]; } + + // STL: (present in vector but not part of a interface spec) + size_type capacity() const { return m_size; } + void reserve(size_type size); + + /** + * Return a pointer to the data area. If there are no + * contents, then the return value will be NULL. This is not + * an STL method but goes with this class as a singular data + * block and not a container (even though it is). + */ + iterator data() { return m_data; } + const_iterator data() const { return m_data; } + + /** + * Replace the existing contents of the Block with the buffer + * that starts at raw of size len. + * + * @param raw Pointer to the new contents. + * @param len Size of the new contents. + */ + void assign(const_pointer data, const size_type size); + + /** + * Replace the existing contents of the Block with a buffer + * consisting of size elements equal to fill. + * + * @param size The size of the new contents. + * @param value Value to fill the contents with. + */ + void assign(const size_type size, const value_type value = 0); + + // compatiblity functions (remove before final 0.3.0 release) + const_pointer raw_data() const { return data(); } + pointer raw_data() { return data(); } + size_type raw_size() const { return size(); } + void set_raw(const_pointer raw, const size_type len) + { assign(raw, len); } + + private: + pointer m_data; + size_type m_size; + }; + +} + +bool operator == (const PalmLib::Block& lhs, const PalmLib::Block& rhs); + +inline bool operator != (const PalmLib::Block& lhs, const PalmLib::Block& rhs) +{ return ! (lhs == rhs); } + +#endif diff --git a/src/translators/pilotdb/libpalm/Database.cpp b/src/translators/pilotdb/libpalm/Database.cpp new file mode 100644 index 0000000..38d896f --- /dev/null +++ b/src/translators/pilotdb/libpalm/Database.cpp @@ -0,0 +1,43 @@ +/* + * palm-db-tools: General interface to a PalmOS database. + * Copyright (C) 2000 by Tom Dyas (tdyas@users.sourceforge.net) + * + * This file implens an abstract interface to PalmOS + * databases. Subclasses would include the class that reads/writes PDB + * files and possibly databases that can be accessed over the HotSync + * protocols. + */ + +#include "palmtypes.h" +#include "Record.h" +#include "Database.h" + +#ifndef __GNUG__ + +// MSVC: Visual C++ doesn't like initializers in the header ... +const PalmLib::pi_uint16_t PalmLib::Database::FLAG_HDR_RESOURCE = 0x0001; +const PalmLib::pi_uint16_t PalmLib::Database::FLAG_HDR_READ_ONLY = 0x0002; +const PalmLib::pi_uint16_t PalmLib::Database::FLAG_HDR_APPINFO_DIRTY = 0x0004; +const PalmLib::pi_uint16_t PalmLib::Database::FLAG_HDR_BACKUP = 0x0008; +const PalmLib::pi_uint16_t PalmLib::Database::FLAG_HDR_OK_TO_INSTALL_NEWER = 0x0010; +const PalmLib::pi_uint16_t PalmLib::Database::FLAG_HDR_RESET_AFTER_INSTALL = 0x0020; +const PalmLib::pi_uint16_t PalmLib::Database::FLAG_HDR_COPY_PREVENTION = 0x0040; +const PalmLib::pi_uint16_t PalmLib::Database::FLAG_HDR_STREAM = 0x0080; +const PalmLib::pi_uint16_t PalmLib::Database::FLAG_HDR_HIDDEN = 0x0100; +const PalmLib::pi_uint16_t PalmLib::Database::FLAG_HDR_LAUNCHABLE_DATA = 0x0200; +const PalmLib::pi_uint16_t PalmLib::Database::FLAG_HDR_OPEN = 0x8000; +const PalmLib::pi_char_t PalmLib::Record::FLAG_ATTR_DELETED = 0x80; +const PalmLib::pi_char_t PalmLib::Record::FLAG_ATTR_DIRTY = 0x40; +const PalmLib::pi_char_t PalmLib::Record::FLAG_ATTR_BUSY = 0x20; +const PalmLib::pi_char_t PalmLib::Record::FLAG_ATTR_SECRET = 0x10; + +#endif + +PalmLib::Database::Database(bool resourceDB) + : m_name(""), m_version(0), m_time_created(0), m_time_modified(0), + m_time_backup(0), m_modification(0), m_unique_id_seed(0) +{ + m_flags = resourceDB ? FLAG_HDR_RESOURCE : 0; + m_type = PalmLib::mktag(' ', ' ', ' ', ' '); + m_creator = PalmLib::mktag(' ', ' ', ' ', ' '); +} diff --git a/src/translators/pilotdb/libpalm/Database.h b/src/translators/pilotdb/libpalm/Database.h new file mode 100644 index 0000000..bcde8c0 --- /dev/null +++ b/src/translators/pilotdb/libpalm/Database.h @@ -0,0 +1,181 @@ +/* + * palm-db-tools: General interface to a PalmOS database. + * Copyright (C) 2000 by Tom Dyas (tdyas@users.sourceforge.net) + * + * This header defines an abstract interface to PalmOS + * databases. Subclasses would include the class that reads/writes PDB + * files and possibly databases that can be accessed over the HotSync + * protocols. + */ + +#ifndef __PALMLIB_DATABASE_H__ +#define __PALMLIB_DATABASE_H__ + +#include <string> + +#include "palmtypes.h" +#include "Block.h" +#include "Record.h" +#include "Resource.h" + +namespace PalmLib { + + class Database { + public: + // Constants for bits in the flags field of a PalmOS database. +#ifdef __GNUG__ + static const pi_uint16_t FLAG_HDR_RESOURCE = 0x0001; + static const pi_uint16_t FLAG_HDR_READ_ONLY = 0x0002; + static const pi_uint16_t FLAG_HDR_APPINFO_DIRTY = 0x0004; + static const pi_uint16_t FLAG_HDR_BACKUP = 0x0008; + static const pi_uint16_t FLAG_HDR_OK_TO_INSTALL_NEWER = 0x0010; + static const pi_uint16_t FLAG_HDR_RESET_AFTER_INSTALL = 0x0020; + static const pi_uint16_t FLAG_HDR_COPY_PREVENTION = 0x0040; + static const pi_uint16_t FLAG_HDR_STREAM = 0x0080; + static const pi_uint16_t FLAG_HDR_HIDDEN = 0x0100; + static const pi_uint16_t FLAG_HDR_LAUNCHABLE_DATA = 0x0200; + static const pi_uint16_t FLAG_HDR_OPEN = 0x8000; +#else + static const pi_uint16_t FLAG_HDR_RESOURCE; + static const pi_uint16_t FLAG_HDR_READ_ONLY; + static const pi_uint16_t FLAG_HDR_APPINFO_DIRTY; + static const pi_uint16_t FLAG_HDR_BACKUP; + static const pi_uint16_t FLAG_HDR_OK_TO_INSTALL_NEWER; + static const pi_uint16_t FLAG_HDR_RESET_AFTER_INSTALL; + static const pi_uint16_t FLAG_HDR_COPY_PREVENTION; + static const pi_uint16_t FLAG_HDR_STREAM; + static const pi_uint16_t FLAG_HDR_HIDDEN; + static const pi_uint16_t FLAG_HDR_LAUNCHABLE_DATA; + static const pi_uint16_t FLAG_HDR_OPEN; +#endif + + Database(bool resourceDB = false); + virtual ~Database() { } + + bool isResourceDB() const {return (m_flags & FLAG_HDR_RESOURCE) != 0;} + + virtual pi_uint32_t type() const { return m_type; } + virtual void type(pi_uint32_t new_type) { m_type = new_type; } + + virtual pi_uint32_t creator() const { return m_creator; } + virtual void creator(pi_uint32_t new_creator) + { m_creator = new_creator; } + + virtual pi_uint16_t version() const { return m_version; } + virtual void version(pi_uint16_t v) { m_version = v; } + + virtual pi_int32_t creation_time() const { return m_time_created; } + virtual void creation_time(pi_int32_t ct) { m_time_created = ct; } + + virtual pi_uint32_t modification_time() const + { return m_time_modified; } + virtual void modification_time(pi_uint32_t mt) + { m_time_modified = mt; } + + virtual pi_uint32_t backup_time() const { return m_time_backup; } + virtual void backup_time(pi_uint32_t bt) { m_time_backup = bt; } + + virtual pi_uint32_t modnum() const { return m_modification; } + virtual void modnum(pi_uint32_t new_modnum) + { m_modification = new_modnum; } + + virtual pi_uint32_t unique_id_seed() const + { return m_unique_id_seed; } + virtual void unique_id_seed(pi_uint32_t uid_seed) + { m_unique_id_seed = uid_seed; } + + virtual pi_uint16_t flags() const { return m_flags; } + virtual void flags(pi_uint16_t flags) + { m_flags = flags & ~(FLAG_HDR_RESOURCE | FLAG_HDR_OPEN); } + + virtual std::string name() const { return m_name; } + virtual void name(const std::string& new_name) { m_name = new_name; } + + virtual bool backup() const + { return (m_flags & FLAG_HDR_BACKUP) != 0; } + virtual void backup(bool state) { + if (state) + m_flags |= FLAG_HDR_BACKUP; + else + m_flags &= ~(FLAG_HDR_BACKUP); + } + + virtual bool readonly() const + { return (m_flags & FLAG_HDR_READ_ONLY) != 0; } + virtual void readonly(bool state) { + if (state) + m_flags |= FLAG_HDR_READ_ONLY; + else + m_flags &= ~(FLAG_HDR_READ_ONLY); + } + + virtual bool copy_prevention() const + { return (m_flags & FLAG_HDR_COPY_PREVENTION) != 0; } + virtual void copy_prevention(bool state) { + if (state) + m_flags |= FLAG_HDR_COPY_PREVENTION; + else + m_flags &= ~(FLAG_HDR_COPY_PREVENTION); + } + + // Return the total number of records/resources in this + // database. + virtual unsigned getNumRecords() const = 0; + + // Return the database's application info block as a Block + // object. + virtual Block getAppInfoBlock() const { return Block(); } + + // Set the database's app info block to the contents of the + // passed Block object. + virtual void setAppInfoBlock(const Block &) { } + + // Return the database's sort info block as a Block object. + virtual Block getSortInfoBlock() const { return Block(); } + + // Set the database's sort info block to the contents of the + // passed Block object. + virtual void setSortInfoBlock(const Block &) { } + + // Return the record identified by the given index. The caller + // owns the returned RawRecord object. + virtual Record getRecord(unsigned index) const = 0; + + // Set the record identified by the given index to the given + // record. + virtual void setRecord(unsigned index, const Record& rec) = 0; + + // Append the given record to the database. + virtual void appendRecord(const Record& rec) = 0; + + // returned if the specified (type, ID) combination is not + // present in the database. The caller owns the returned + // RawRecord object. + virtual Resource getResourceByType(pi_uint32_t type, + pi_uint32_t id) const = 0; + + // Return the resource present at the given index. NULL is + // returned if the index is invalid. The caller owns the + // returned RawRecord object. + virtual Resource getResourceByIndex(unsigned index) const = 0; + + // Set the resouce at given index to passed Resource object. + virtual void setResource(unsigned index, const Resource& rsrc) = 0; + + private: + std::string m_name; + pi_uint16_t m_flags; + pi_uint16_t m_version; + pi_uint32_t m_time_created; + pi_uint32_t m_time_modified; + pi_uint32_t m_time_backup; + pi_uint32_t m_modification; + pi_uint32_t m_type; + pi_uint32_t m_creator; + pi_uint32_t m_unique_id_seed; + + }; + +} // namespace PalmLib + +#endif diff --git a/src/translators/pilotdb/libpalm/Makefile.am b/src/translators/pilotdb/libpalm/Makefile.am new file mode 100644 index 0000000..ea92331 --- /dev/null +++ b/src/translators/pilotdb/libpalm/Makefile.am @@ -0,0 +1,15 @@ +####### kdevelop will overwrite this part!!! (begin)########## +noinst_LIBRARIES = liblibpalm.a + +AM_CPPFLAGS = $(all_includes) + +liblibpalm_a_METASOURCES = AUTO + +liblibpalm_a_SOURCES = Database.cpp Block.cpp + + +EXTRA_DIST = Block.cpp Block.h palmtypes.h Record.h Resource.h Database.h Database.cpp + +####### kdevelop will overwrite this part!!! (end)############ + +KDE_OPTIONS = noautodist diff --git a/src/translators/pilotdb/libpalm/Record.h b/src/translators/pilotdb/libpalm/Record.h new file mode 100644 index 0000000..ecf19e3 --- /dev/null +++ b/src/translators/pilotdb/libpalm/Record.h @@ -0,0 +1,168 @@ +/* + * palm-db-tools: Raw PalmOS Records + * Copyright (C) 2000 by Tom Dyas (tdyas@users.sourceforge.net) + */ + +#ifndef __PALMLIB_RECORD_H__ +#define __PALMLIB_RECORD_H__ + +#include "Block.h" + +namespace PalmLib { + + class Record : public Block { + public: +#ifdef __GNUG__ + static const pi_char_t FLAG_ATTR_DELETED = 0x80; + static const pi_char_t FLAG_ATTR_DIRTY = 0x40; + static const pi_char_t FLAG_ATTR_BUSY = 0x20; + static const pi_char_t FLAG_ATTR_SECRET = 0x10; +#else + static const pi_char_t FLAG_ATTR_DELETED; + static const pi_char_t FLAG_ATTR_DIRTY; + static const pi_char_t FLAG_ATTR_BUSY; + static const pi_char_t FLAG_ATTR_SECRET; +#endif + + /** + * Default constructor. + */ + Record() : Block(), m_attrs(0), m_unique_id(0) { } + + /** + * Copy constructor. + */ + Record(const Record& rhs) : Block(rhs.data(), rhs.size()) { + m_attrs = rhs.attrs(); + m_unique_id = rhs.unique_id(); + } + + /** + * Destructor. + */ + virtual ~Record() { } + + /** + * Constructor which lets the caller specify all the + * parameters. + * + * @param attrs Attribute byte (flags + category). + * @param unique_id Unique ID for this record. + * @param data Start of buffer to copy (or 0 for empty). + * @param size Size of the buffer to copy. + */ + Record(pi_char_t attrs, pi_uint32_t unique_id, + Block::const_pointer data, const Block::size_type size) + : Block(data, size), m_attrs(attrs), m_unique_id(unique_id) { } + + /** + * Constructor which lets the caller use the default fill + * constructor. + * @param attrs Attribute byte (flags + category). + * @param unique_id Unique ID for this record. + * @param size Size of buffer to generate. + * @param value Value to fill buffer with. + */ + Record(pi_char_t attrs, pi_uint32_t unique_id, + const size_type size, const value_type value = 0) + : Block(size, value), m_attrs(attrs), m_unique_id(unique_id) { } + + /** + * Assignment operator. + * + * @param rhs The PalmLib::Record we should become. */ + Record& operator = (const Record& rhs) { + Block::operator = (rhs); + m_attrs = rhs.attrs(); + m_unique_id = rhs.unique_id(); + return *this; + } + + /** + * Return the attributes byte which contains the category and + * flags. + */ + pi_char_t attrs() const { return m_attrs; } + + /** + * Return the state of the record's "deleted" flag. + */ + bool deleted() const { return (m_attrs & FLAG_ATTR_DELETED) != 0; } + + /** + * Set the state of the record's "deleted" flag. + * + * @param state New state of the "deleted" flag. + */ + void deleted(bool state) { + if (state) + m_attrs |= FLAG_ATTR_DELETED; + else + m_attrs &= ~(FLAG_ATTR_DELETED); + } + + /** + * Return the state of the record's "dirty" flag. + */ + bool dirty() const { return (m_attrs & FLAG_ATTR_DIRTY) != 0; } + + /** + * Set the state of the record's "dirty" flag. + * + * @param state New state of the "dirty" flag. + */ + void dirty(bool state) { + if (state) + m_attrs |= FLAG_ATTR_DIRTY; + else + m_attrs &= ~(FLAG_ATTR_DIRTY); + } + + /** + * Return the state of the record's "secret" flag. + */ + bool secret() const { return (m_attrs & FLAG_ATTR_SECRET) != 0; } + + /** + * Set the state of the record's "secret" flag. + * + * @param state New state of the "secret" flag. + */ + void secret(bool state) { + if (state) + m_attrs |= FLAG_ATTR_SECRET; + else + m_attrs &= ~(FLAG_ATTR_SECRET); + } + + /** + * Return the category of this record. + */ + pi_char_t category() const { return (m_attrs & 0x0F); } + + /** + * Set the category of this record. + */ + void category(pi_char_t cat) + { m_attrs &= ~(0x0F); m_attrs |= (cat & 0x0F); } + + /** + * Return the unique ID of this record. + */ + pi_uint32_t unique_id() const { return m_unique_id; } + + /** + * Set the unique ID of this record to uid. + * + * @param uid New unique ID for this record. + */ + void unique_id(pi_uint32_t uid) { m_unique_id = uid; } + + private: + pi_char_t m_attrs; + pi_uint32_t m_unique_id; + }; + +} + +#endif diff --git a/src/translators/pilotdb/libpalm/Resource.h b/src/translators/pilotdb/libpalm/Resource.h new file mode 100644 index 0000000..b98f718 --- /dev/null +++ b/src/translators/pilotdb/libpalm/Resource.h @@ -0,0 +1,85 @@ +/* + * palm-db-tools: PalmOS Resources + * Copyright (C) 2000 by Tom Dyas (tdyas@users.sourceforge.net) + */ + +#ifndef __PALMLIB_RESOURCE_H__ +#define __PALMLIB_RESOURCE_H__ + +#include "Block.h" +#include "palmtypes.h" + +namespace PalmLib { + + class Resource : public Block { + public: + /** + * Default constructor. + */ + Resource() : Block(), m_type(0), m_id(0) { } + + /** + * Copy constructor. + */ + Resource(const Resource& rhs) : Block(rhs.data(), rhs.size()) { + m_type = rhs.type(); + m_id = rhs.id(); + } + + /** + * Destructor. + */ + virtual ~Resource() { } + + /** + * Constructor which lets the caller specify all the + * parameters. + * + * @param type Resource type + * @param id Resource ID + * @param data Start of buffer to copy. + * @param size Size of the buffer to copy. + */ + Resource(pi_uint32_t type, pi_uint32_t id, + const_pointer data, const size_type size) + : Block(data, size), m_type(type), m_id(id) { } + + /** + * Constructor which lets the caller use the default fill + * constructor. + * + * @param type Resource type + * @param id Resource ID + * @param size Size of buffer to generate. + * @param value Value to fill buffer with. + */ + Resource(pi_uint32_t type, pi_uint32_t id, + const size_type size, const value_type value = 0) + : Block(size, value), m_type(type), m_id(id) { } + + /** + * Assignment operator. + */ + Resource& operator = (const Resource& rhs) { + Block::operator = (rhs); + m_type = rhs.type(); + m_id = rhs.id(); + return *this; + } + + // Accessor functions for the resource type. + pi_uint32_t type() const { return m_type; } + void type(const pi_uint32_t _type) { m_type = _type; } + + // Accessor functions for the resource ID. + pi_uint32_t id() const { return m_id; } + void id(const pi_uint32_t _id) { m_id = _id; } + + private: + pi_uint32_t m_type; + pi_uint32_t m_id; + }; + +} + +#endif diff --git a/src/translators/pilotdb/libpalm/palmtypes.h b/src/translators/pilotdb/libpalm/palmtypes.h new file mode 100644 index 0000000..5c12262 --- /dev/null +++ b/src/translators/pilotdb/libpalm/palmtypes.h @@ -0,0 +1,117 @@ +/* + * This file contains type definitions and helper functions to make + * access to data in Palm Pilot order easier. + */ + +#ifndef __LIBPALM_PALMTYPES_H__ +#define __LIBPALM_PALMTYPES_H__ + +#include <stdexcept> + +#include "../portability.h" + +namespace PalmLib { + +#if SIZEOF_UNSIGNED_CHAR == 1 + typedef unsigned char pi_char_t; +#else +#error Unable to determine the size of pi_char_t. +#endif + +#if SIZEOF_UNSIGNED_LONG == 2 + typedef unsigned long pi_uint16_t; +#elif SIZEOF_UNSIGNED_INT == 2 + typedef unsigned int pi_uint16_t; +#elif SIZEOF_UNSIGNED_SHORT == 2 + typedef unsigned short pi_uint16_t; +#else +#error Unable to determine the size of pi_uint16_t. +#endif + +#if SIZEOF_LONG == 2 + typedef long pi_int16_t; +#elif SIZEOF_INT == 2 + typedef int pi_int16_t; +#elif SIZEOF_SHORT == 2 + typedef short pi_int16_t; +#else +#error Unable to determine the size of pi_int16_t. +#endif + +#if SIZEOF_UNSIGNED_LONG == 4 + typedef unsigned long pi_uint32_t; +#elif SIZEOF_UNSIGNED_INT == 4 + typedef unsigned int pi_uint32_t; +#elif SIZEOF_UNSIGNED_SHORT == 4 + typedef unsigned short pi_uint32_t; +#else +#error Unable to determine the size of pi_uint32_t. +#endif + +#if SIZEOF_LONG == 4 + typedef long pi_int32_t; +#elif SIZEOF_INT == 4 + typedef int pi_int32_t; +#elif SIZEOF_SHORT == 4 + typedef short pi_int32_t; +#else +#error Unable to determine the size of pi_int32_t. +#endif + +typedef union { + double number; +#ifdef WORDS_BIGENDIAN + struct { + PalmLib::pi_uint32_t hi; + PalmLib::pi_uint32_t lo; + } words; +#else + struct { + PalmLib::pi_uint32_t lo; + PalmLib::pi_uint32_t hi; + } words; +#endif +} pi_double_t; + + inline pi_int32_t get_long(const pi_char_t* p) { + return ( (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3] ); + } + + inline pi_int32_t get_treble(const pi_char_t* p) { + return ( (p[0] << 16) || (p[1] << 8) || p[0]); + } + + inline pi_int16_t get_short(const pi_char_t* p) { + return ( (p[0] << 8) | p[1] ); + } + + inline void set_long(pi_char_t *p, pi_int32_t v) { + p[0] = (v >> 24) & 0xFF; + p[1] = (v >> 16) & 0xFF; + p[2] = (v >> 8 ) & 0xFF; + p[3] = (v ) & 0xFF; + } + + inline void set_treble(pi_char_t *p, pi_int32_t v) { + p[0] = (v >> 16) & 0xFF; + p[1] = (v >> 8 ) & 0xFF; + p[2] = (v ) & 0xFF; + } + + inline void set_short(pi_char_t *p, pi_int16_t v) { + p[0] = (v >> 8) & 0xFF; + p[1] = (v ) & 0xFF; + } + + inline pi_uint32_t mktag(pi_char_t c1, pi_char_t c2, + pi_char_t c3, pi_char_t c4) + { return (((c1)<<24)|((c2)<<16)|((c3)<<8)|(c4)); } + + class error : public std::runtime_error { + public: + error(const std::string & what_arg) : std::runtime_error(what_arg) { } + }; + +} // namespace PalmLib + +#endif |