mqsdx  300.0.1
MQPluginSDK Extention Library / mqsdkをC++またはCLI(.Net)拡張するサポートライブラリ。
 全て クラス 関数 変数 プロパティ グループ ページ
K:/Dancer_iMac/mqsdkUVTransClone/mqsdk311/mqsdx/MQ0x.hpp
1 /*
2 First author tiritomato 2013.
3 
4 mqsdx is distributed under the GNU Lesser General Public License 3.0(LGPLv3).
5 
6 support blog (Japanese only)
7 http://d.hatena.ne.jp/tiri_tomato/
8 */
9 
10 #ifndef __MQSDKPlugIn0x_11_h__
11 #define __MQSDKPlugIn0x_11_h__
12 
13 #include <string.h>
14 #include <algorithm>
15 #include <functional>
16 #include <iomanip>
17 #include <regex>
18 #include <sstream>
19 #include <vector>
20 #define NOMINMAX
21 #define WIN32_LEAN_AND_MEAN
22 #include <windows.h>
23 #include <MQSetting.h>
24 #include <MQBasePlugin.h>
25 #include <MQPlugin.h>
26 
27 #include "impl/MQ0x_11.hpp"
28 
29 // Plugin Version Checker
30 #ifdef MQPLUGIN_VERSION
31  #if MQPLUGIN_VERSION < 0x0300
32  "MQx" need newer than mqsdk300
33  #endif
34 #else
35  "MQx" need newer than mqsdk300
36 #endif
37 
38 namespace MQ0x {
39 
69  template <typename T_OUT, const size_t default_seed = 17> struct CollectionHashCode {
70  public:
72  static const T_OUT defaultSeed = (T_OUT)default_seed;
74  CollectionHashCode( const T_OUT seed = defaultSeed ) : m_val( seed ) {}
80  template <typename T_IN> CollectionHashCode( const T_IN *pSrc, const size_t ct, const T_OUT seed = defaultSeed ) : m_val(seed) {
81  if ( pSrc != NULL ) for ( size_t i = 0; i < ct; i++ ) m_val = (m_val * (T_OUT)(sizeof(T_IN) * 8 - 1)) ^ pSrc[i];
82  }
87  CollectionHashCode( const char *pSrc, const T_OUT seed = defaultSeed ) : m_val(FromTrailCodeCollection(pSrc,'\0',seed)) {}
92  CollectionHashCode( const wchar_t *pSrc, const T_OUT seed = defaultSeed ) : m_val(FromTrailCodeCollection(pSrc,L'\0',seed)) {}
98  template <typename T_IN> static CollectionHashCode FromTrailCodeCollection( const T_IN *pSrc, const T_IN trailCode, const T_OUT seed = defaultSeed ) {
99  CollectionHashCode ret(seed);
100  if ( pSrc != NULL ) while ( (*pSrc) != trailCode ) ret.m_val = (ret.m_val * (T_OUT)(sizeof(T_IN) * 8 - 1)) ^ (*(pSrc++));
101  return ret;
102  }
104  operator T_OUT() { return m_val; }
105  private:
106  T_OUT m_val;
107  };
108 
122  struct SettingProxy {
123  public:
125  struct Handle {
126  friend struct SettingProxy;
127  template <typename T_MQPLUGIN> friend class PluginBase;
128  static Handle Empty() { return Handle(NULL); }
129  public:
130  Handle( MQBasePlugin* plugin ) { this->plugin = plugin; }
131  MQBasePlugin* plugin;
132  };
133  SettingProxy( Handle handle );
134  ~SettingProxy() { Close(); }
135  void Close();
136  bool Load(const char *name, bool& value, bool default_value=false);
137  bool Load(const char *name, int& value, int default_value=0);
138  bool Load(const char *name, unsigned int& value, unsigned int default_value=0);
139  bool Load(const char *name, float& value, float default_value=0.0f);
140  bool Load(const char *name, std::string& value, std::string default_value="");
141  bool Save(const char *name, const bool& value);
142  bool Save(const char *name, const int& value);
143  bool Save(const char *name, const unsigned int& value);
144  bool Save(const char *name, const float& value);
145  bool Save(const char *name, const char* value);
146  bool Save(const char *name, const std::string& value);
147  private:
148  SettingProxy(const SettingProxy&); // kill copy
149  SettingProxy& operator=(const SettingProxy&); // kill copy
150  MQBasePlugin* m_plugin;
151  MQSetting* m_setting;
152  };
153 
189  template <typename T_MQPLUGIN> class PluginBase : public T_MQPLUGIN {
190  public:
191  PluginBase( const char* productName, const char* pluginFullName, const char* pluginString ) :
192  m_productName( productName ),
193  m_pluginFullName( pluginFullName ),
194  m_pluginString( pluginString ),
195  m_idProduct( CollectionHashCode<DWORD>(productName) ),
196  m_idPlugin( CollectionHashCode<DWORD>(pluginFullName) )
197  {
198  }
199 
200  PluginBase( const char* productName, const char* pluginFullName, const char* pluginString,
201  const DWORD idProduct, const DWORD idPlugin ) :
202  m_productName( productName ),
203  m_pluginFullName( pluginFullName ),
204  m_pluginString( pluginString ),
205  m_idProduct( idProduct ),
206  m_idPlugin( idPlugin )
207  {
208  }
209 
211  virtual void GetPlugInID(DWORD *Product, DWORD *ID) {
212  *Product = m_idProduct;
213  *ID = m_idPlugin;
214  }
216  virtual const char *GetPlugInName() { return m_pluginFullName.c_str(); }
218  virtual const char *EnumString() { return m_pluginString.c_str(); }
220  const char* GetProductName() { return m_productName.c_str(); }
222  MQBasePlugin* BasePlugin() { return this; }
226  DWORD ProductID() { return m_idProduct; }
228  DWORD PluginID() { return m_idPlugin; }
229  protected:
230  const std::string m_productName;
231  const std::string m_pluginFullName;
232  const std::string m_pluginString;
233  const DWORD m_idProduct;
234  const DWORD m_idPlugin;
235  };
236 
240 
241 #ifdef _DEBUG
242  static const std::vector<char>::size_type GetNameInitialBufferSize = 2;
243 #else
244  static const std::vector<char>::size_type GetNameInitialBufferSize = 32;
245 #endif
246 
249  inline bool DeleteMaterial( const MQDocument doc, const MQMaterial mat ) {
250  int index = prv_impl::GetIdentifiedIndex(doc, mat);
251  if ( index < 0 ) return false;
252  doc->DeleteMaterial(index); return true;
253  }
256  inline bool DeleteObject( const MQDocument doc, const MQObject obj ) {
257  int index = prv_impl::GetIdentifiedIndex(doc, obj);
258  if ( index < 0 ) return false;
259  doc->DeleteObject(index); return true;
260  }
273  inline std::string GetCountUpCloneableUniqueName( const MQDocument doc, const MQMaterial src, std::vector<char>* const buf = NULL ) {
274  return prv_impl::GetCountUpCloneableUniqueName(doc,src,buf);
275  }
288  inline std::string GetCountUpCloneableUniqueName( const MQDocument doc, const MQObject src, std::vector<char>* const buf = NULL ) {
289  return prv_impl::GetCountUpCloneableUniqueName(doc,src,buf);
290  }
293  inline MQMaterial GetMaterial( const MQDocument doc, const char* name ) { return prv_impl::GetNamed<MQMaterial>( doc, name ); }
298  inline MQMaterial GetMaterial( const MQDocument doc, const UINT id ) {
299  // メタセコイア本体にバグの疑いがあり、旧実装をキープ。
300  /*
301  #if 0x0310 <= MQPLUGIN_VERSION
302  if ( doc != NULL ) return doc->GetMaterialFromUniqueID(id);
303  return NULL;
304  #else
305  return prv_impl::GetIdentified<MQMaterial>( doc, id );
306  #endif*/
307  return prv_impl::GetIdentified<MQMaterial>( doc, id );
308  }
309 
311  std::string GetMaterialTextureName( const MQMaterial, DWORD );
313 
315  inline std::string GetMaterialAlphaName( const MQMaterial mat ) { return GetMaterialTextureName(mat,MQMAPPING_ALPHA); }
317  inline std::string GetMaterialBumpName( const MQMaterial mat ) { return GetMaterialTextureName(mat,MQMAPPING_BUMP); }
320  inline int GetMaterialIndex( const MQDocument doc, const char* name ) { return prv_impl::GetNamedIndex<MQMaterial>( doc, name ); }
323  inline int GetMaterialIndex( const MQDocument doc, const UINT id ) { return prv_impl::GetIdentifiedIndex<MQMaterial>( doc, id ); }
333  inline std::string GetMaterialTextureName( const MQMaterial mat, const DWORD map_type = MQMAPPING_TEXTURE ) {
334  if ( mat != NULL )
335  {
336  std::vector<char> buf;
337  prv_impl::GetMaterialTextureName(&buf, mat, map_type);
338  return std::string(&buf[0]);
339  }
340  return "";
341  }
344  inline std::string GetName( const MQMaterial mat ){ return prv_impl::GetName( mat ); }
347  inline std::string GetName( const MQObject obj ){ return prv_impl::GetName( obj ); }
350  inline MQObject GetObject( const MQDocument doc, const char* name ) { return prv_impl::GetNamed<MQObject>( doc, name ); }
355  inline MQObject GetObject( const MQDocument doc, const UINT id ) {
356  #if 0x0310 <= MQPLUGIN_VERSION
357  if ( doc != NULL ) return doc->GetObjectFromUniqueID(id);
358  return NULL;
359  #else
360  return prv_impl::GetIdentified<MQObject>(doc, id );
361  #endif
362  }
365  inline int GetObjectIndex( const MQDocument doc, const char* name ) { return prv_impl::GetNamedIndex<MQObject>( doc, name ); }
368  inline int GetObjectIndex( const MQDocument doc, const UINT id ) { return prv_impl::GetIdentifiedIndex<MQObject>(doc, id ); }
369 
370 #if 0x0310 <= MQPLUGIN_VERSION
371 
375  inline std::string GetUnusedMaterialName( const MQDocument doc, const char* base_name = NULL ) {
376  return prv_impl::GetUnusedNameString<MQMaterial>( doc, base_name );
377  }
382  inline std::string GetUnusedMaterialName( const MQDocument doc, const MQMaterial base_name_material ) {
383  if ( base_name_material == NULL ) return prv_impl::GetUnusedNameString<MQMaterial>( doc );
384  return prv_impl::GetUnusedNameString<MQMaterial>( doc, GetName( base_name_material ).c_str() );
385  }
389  inline std::string GetUnusedObjectName( const MQDocument doc, const char* base_name = NULL ) {
390  return prv_impl::GetUnusedNameString<MQObject>( doc, base_name );
391  }
396  inline std::string GetUnusedObjectName( const MQDocument doc, const MQObject base_name_object ) {
397  if ( base_name_object == NULL ) return prv_impl::GetUnusedNameString<MQMaterial>( doc );
398  return prv_impl::GetUnusedNameString<MQMaterial>( doc, GetName( base_name_object ).c_str() );
399  }
400 
401 #endif
402 
404 
406 
407  namespace prv_impl {}; // kill prv_impl access ( to private header implement trap )
408 };
409 
410 #endif