From 33d13ff81c27f6ddfb14f59e8679a40302cff85a Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Mon, 20 Jul 2015 15:03:04 -0500 Subject: [PATCH 1/2] Hide datapack positions behind an opaque handle. --- plugins/include/datapack.inc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/include/datapack.inc b/plugins/include/datapack.inc index ee9daa4b..ecdd5cd3 100644 --- a/plugins/include/datapack.inc +++ b/plugins/include/datapack.inc @@ -35,6 +35,13 @@ #endif #define _datapack_included + +/** + * Opaque handle to a datapack position. + */ + enum DataPackPos: {}; + + /** * Creates a new data pack. * @@ -137,7 +144,7 @@ native void ResetPack(Handle pack, bool clear=false); * @return Numerical position in the data pack. * @error Invalid handle. */ -native int GetPackPosition(Handle pack); +native DataPackPos GetPackPosition(Handle pack); /** * Sets the read/write position in a data pack. @@ -147,7 +154,7 @@ native int GetPackPosition(Handle pack); * @noreturn * @error Invalid handle, or position is beyond the pack bounds. */ -native void SetPackPosition(Handle pack, int position); +native void SetPackPosition(Handle pack, DataPackPos position); /** * Returns whether or not a specified number of bytes from the data pack @@ -174,7 +181,7 @@ methodmap DataPack < Handle public Reset() = ResetPack; public IsReadable() = IsPackReadable; - property int Position { + property DataPackPos Position { public get() = GetPackPosition; public set() = SetPackPosition; } From 86b04e36b528fea9a585a4234b19aa0828b76bdb Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Mon, 20 Jul 2015 15:03:57 -0500 Subject: [PATCH 2/2] Clarify the Get/SetPackPosition documentation. --- plugins/include/datapack.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/include/datapack.inc b/plugins/include/datapack.inc index ecdd5cd3..e623b77a 100644 --- a/plugins/include/datapack.inc +++ b/plugins/include/datapack.inc @@ -141,7 +141,7 @@ native void ResetPack(Handle pack, bool clear=false); * Returns the read or write position in a data pack. * * @param pack Handle to the data pack. - * @return Numerical position in the data pack. + * @return Position in the data pack, only usable with calls to SetPackPosition. * @error Invalid handle. */ native DataPackPos GetPackPosition(Handle pack); @@ -150,7 +150,7 @@ native DataPackPos GetPackPosition(Handle pack); * Sets the read/write position in a data pack. * * @param pack Handle to the data pack. - * @param position New position to set. + * @param position New position to set. Must have been previously retrieved from a call to GetPackPosition. * @noreturn * @error Invalid handle, or position is beyond the pack bounds. */