Browse Source

putil: Add ParamBytes to allow passing vector_uchar through event system

rdb 3 years ago
parent
commit
ebdca44f6b

+ 2 - 0
dtool/src/dtoolbase/register_type.cxx

@@ -26,6 +26,7 @@ TypeHandle double_type_handle;
 TypeHandle float_type_handle;
 TypeHandle string_type_handle;
 TypeHandle wstring_type_handle;
+TypeHandle vector_uchar_type_handle;
 
 TypeHandle long_p_type_handle;
 TypeHandle int_p_type_handle;
@@ -59,6 +60,7 @@ void init_system_type_handles() {
     register_type(float_type_handle, "float");
     register_type(string_type_handle, "string");
     register_type(wstring_type_handle, "wstring");
+    register_type(vector_uchar_type_handle, "vector_uchar");
 
     register_type(int_p_type_handle, "int*");
     register_type(short_p_type_handle, "short*");

+ 1 - 0
dtool/src/dtoolbase/register_type.h

@@ -88,6 +88,7 @@ extern TypeHandle EXPCL_DTOOL_DTOOLBASE double_type_handle;
 extern TypeHandle EXPCL_DTOOL_DTOOLBASE float_type_handle;
 extern TypeHandle EXPCL_DTOOL_DTOOLBASE string_type_handle;
 extern TypeHandle EXPCL_DTOOL_DTOOLBASE wstring_type_handle;
+extern TypeHandle EXPCL_DTOOL_DTOOLBASE vector_uchar_type_handle;
 
 extern TypeHandle long_p_type_handle;
 extern TypeHandle int_p_type_handle;

+ 6 - 0
dtool/src/dtoolutil/vector_uchar.h

@@ -15,6 +15,7 @@
 #define VECTOR_UCHAR_H
 
 #include "dtoolbase.h"
+#include "register_type.h"
 
 /**
  * A vector of uchars.  This class is defined once here, and exported to
@@ -30,4 +31,9 @@
 
 #include "vector_src.h"
 
+template<>
+INLINE TypeHandle _get_type_handle(const vector_uchar *) {
+  return vector_uchar_type_handle;
+}
+
 #endif

+ 5 - 0
panda/src/event/eventParameter.I

@@ -63,6 +63,11 @@ EventParameter(const std::string &value) : _ptr(new EventStoreString(value)) { }
 INLINE EventParameter::
 EventParameter(const std::wstring &value) : _ptr(new EventStoreWstring(value)) { }
 
+/**
+ * Defines an EventParameter that stores a binary value.
+ */
+INLINE EventParameter::
+EventParameter(const vector_uchar &value) : _ptr(new ParamBytes(value)) { }
 
 /**
  *

+ 1 - 0
panda/src/event/eventParameter.h

@@ -41,6 +41,7 @@ PUBLISHED:
   INLINE EventParameter(double value);
   INLINE EventParameter(const std::string &value);
   INLINE EventParameter(const std::wstring &value);
+  INLINE EventParameter(const vector_uchar &value);
 
   INLINE EventParameter(const EventParameter &copy);
   INLINE EventParameter &operator = (const EventParameter &copy);

+ 2 - 0
panda/src/putil/config_putil.cxx

@@ -212,6 +212,7 @@ init_libputil() {
   FactoryParam::init_type();
   Namable::init_type();
   NodeCachedReferenceCount::init_type();
+  ParamBytes::init_type("ParamBytes");
   ParamMatrix3d::init_type("ParamMatrix3d");
   ParamMatrix3f::init_type("ParamMatrix3f");
   ParamMatrix4d::init_type("ParamMatrix4d");
@@ -245,6 +246,7 @@ init_libputil() {
 
   BamCacheIndex::register_with_read_factory();
   BamCacheRecord::register_with_read_factory();
+  ParamBytes::register_with_read_factory();
   ParamMatrix3d::register_with_read_factory();
   ParamMatrix3f::register_with_read_factory();
   ParamMatrix4d::register_with_read_factory();

+ 9 - 0
panda/src/putil/paramValue.I

@@ -120,6 +120,15 @@ output(std::ostream &out) const {
   out << _value;
 }
 
+/**
+ *
+ */
+template<>
+INLINE void ParamValue<vector_uchar>::
+output(std::ostream &out) const {
+  out << "uchar[" << _value.size() << "]";
+}
+
 /**
  * Tells the BamReader how to create objects of type ParamValue.
  */

+ 3 - 0
panda/src/putil/paramValue.h

@@ -22,6 +22,7 @@
 #include "bamReader.h"
 #include "bamWriter.h"
 #include "luse.h"
+#include "vector_uchar.h"
 
 /**
  * A non-template base class of ParamValue (below), which serves mainly to
@@ -152,6 +153,7 @@ private:
 
 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<std::string>);
 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<std::wstring>);
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<vector_uchar>);
 
 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase2d>);
 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase2f>);
@@ -173,6 +175,7 @@ EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LMatrix4f
 
 typedef ParamValue<std::string> ParamString;
 typedef ParamValue<std::wstring> ParamWstring;
+typedef ParamValue<vector_uchar> ParamBytes;
 
 typedef ParamValue<LVecBase2d> ParamVecBase2d;
 typedef ParamValue<LVecBase2f> ParamVecBase2f;