[beast: 34/49] BSE: add undo_stack_to_descriptor and undo_stack_from_descriptor for Impl classes



commit b4fb654d6bf1013654e21db61f81c56150716aba
Author: Tim Janik <timj gnu org>
Date:   Wed Jun 24 17:11:39 2015 +0200

    BSE: add undo_stack_to_descriptor and undo_stack_from_descriptor for Impl classes

 bse/bseundostack.cc |   23 +++++++++++++++++++++++
 bse/bseundostack.hh |   14 +++++++++++++-
 2 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/bse/bseundostack.cc b/bse/bseundostack.cc
index fd8b2bb..f43c7c5 100644
--- a/bse/bseundostack.cc
+++ b/bse/bseundostack.cc
@@ -401,3 +401,26 @@ bse_undo_pointer_unpack (const gchar  *packed_pointer,
 
   return item;
 }
+
+namespace Bse {
+
+/// Create a string descriptor for a project's item that survivses future deletion + undo.
+String
+undo_stack_to_descriptor (BseUndoStack *ustack, Bse::ItemImpl &item)
+{
+  BseItem *bitem = item.as<BseItem*>();
+  gchar *dp = bse_undo_pointer_pack (bitem, ustack);
+  String descriptor = dp;
+  g_free (dp);
+  return descriptor;
+}
+
+/// Find an item from an undo descriptor.
+ItemImpl*
+undo_stack_item_from_descriptor (BseUndoStack *ustack, const String &descriptor)
+{
+  BseItem *bitem = (BseItem*) bse_undo_pointer_unpack (descriptor.c_str(), ustack);
+  return bitem ? bitem->as<ItemImpl*>(): NULL;
+}
+
+} // Bse
diff --git a/bse/bseundostack.hh b/bse/bseundostack.hh
index b800241..da16d43 100644
--- a/bse/bseundostack.hh
+++ b/bse/bseundostack.hh
@@ -87,10 +87,22 @@ gchar*             bse_undo_pointer_pack         (gpointer        item,
                                                   BseUndoStack   *ustack);
 gpointer           bse_undo_pointer_unpack       (const gchar    *packed_pointer,
                                                   BseUndoStack   *ustack);
-
 const BseUndoStep* bse_undo_group_peek_last_atom (BseUndoStack   *self,
                                                   SfiTime        *stamp_p);
 
 G_END_DECLS
 
+namespace Bse {
+
+template<bool value> using REQUIRES = typename ::std::enable_if<value, bool>::type;
+template<class T> using DERIVES_ItemImpl = typename std::is_base_of<::Bse::ItemImpl, T>;
+
+String    undo_stack_to_descriptor        (BseUndoStack *ustack, Bse::ItemImpl &item);
+ItemImpl* undo_stack_item_from_descriptor (BseUndoStack *ustack, const String &descriptor);
+template<class Item, REQUIRES< DERIVES_ItemImpl<Item>::value > = true>
+Item&     undo_stack_from_descriptor      (BseUndoStack *ustack, const String &descriptor)
+{ return *dynamic_cast<Item*> (undo_stack_item_from_descriptor (ustack, descriptor)); }
+
+} // Bse
+
 #endif /* __BSE_UNDO_STACK_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]