|
Katana Plug-in APIs 0.1
|
00001 // Copyright (c) 2011 The Foundry Visionmongers Ltd. All Rights Reserved. 00002 00003 #ifndef FoundryKatanaGroupBuilder_H 00004 #define FoundryKatanaGroupBuilder_H 00005 00006 #include <FnAttribute/FnAttribute.h> 00007 #include <FnAttribute/FnAttributeAPI.h> 00008 #include <FnAttribute/ns.h> 00009 #include <FnPlatform/StringView.h> 00010 00011 FNATTRIBUTE_NAMESPACE_ENTER 00012 { 00013 00056 class FNATTRIBUTE_API GroupBuilder 00057 { 00058 public: 00065 GroupBuilder() : _handle(0) {} 00066 00073 enum BuilderMode 00074 { 00079 BuilderModeNormal = kFnKatGroupBuilderModeNormal, 00080 00092 BuilderModeStrict = kFnKatGroupBuilderModeStrict 00093 }; 00094 00095 // @cond FN_INTERNAL_DEV 00096 typedef enum BuilderMode BuilderMode; 00097 // @endcond 00098 00104 GroupBuilder(BuilderMode builderMode) : _handle(getSuite()->createGroupBuilder2((BuilderModeType) builderMode)) {} 00105 00106 ~GroupBuilder() { 00107 if (_handle != 0x0) 00108 getSuite()->releaseGroupBuilder(_handle); 00109 } 00110 00111 void reset() 00112 { 00113 if (_handle != 0x0) { 00114 getSuite()->releaseGroupBuilder(_handle); 00115 _handle = NULL; 00116 } 00117 } 00118 00119 bool isValid() const { 00120 return _handle != 0x0; 00121 } 00122 00143 GroupBuilder& set(FnPlatform::StringView path, 00144 const Attribute& attr, 00145 bool groupInherit = true) 00146 { 00147 return set(path.data(), static_cast<int32_t>(path.size()), 00148 attr.getHandle(), groupInherit); 00149 } 00150 00151 GroupBuilder& set(const char* path, 00152 int32_t length, 00153 const Attribute& attr, 00154 bool groupInherit = true) 00155 { 00156 return set(path, length, attr.getHandle(), groupInherit); 00157 } 00158 00159 GroupBuilder& set(const char* path, 00160 int32_t length, 00161 FnAttributeHandle attr, 00162 bool groupInherit = true) 00163 { 00164 lazyCreate(); 00165 getSuite()->setGroupBuilder(_handle, path, length, attr, 00166 static_cast<uint8_t>(groupInherit)); 00167 return *this; 00168 } 00169 00185 GroupBuilder& setWithUniqueName(FnPlatform::StringView path, 00186 const Attribute& attr, 00187 bool groupInherit = true) 00188 { 00189 lazyCreate(); 00190 getSuite()->setGroupBuilderUnique( 00191 _handle, path.data(), static_cast<int32_t>(path.size()), 00192 attr.getHandle(), uint8_t(groupInherit)); 00193 return (*this); 00194 } 00195 00203 GroupBuilder& del(FnPlatform::StringView path) 00204 { 00205 lazyCreate(); 00206 getSuite()->delGroupBuilder(_handle, path.data(), 00207 static_cast<int32_t>(path.size())); 00208 return (*this); 00209 } 00210 00211 00226 GroupBuilder & update(const GroupAttribute &attr) 00227 { 00228 if (attr.isValid()) { 00229 lazyCreate(); 00230 getSuite()->updateGroupBuilder(_handle, attr.getHandle()); 00231 } 00232 return (*this); 00233 } 00234 00245 GroupBuilder & deepUpdate(const GroupAttribute &attr) 00246 { 00247 if (attr.isValid()) { 00248 lazyCreate(); 00249 getSuite()->deepUpdateGroupBuilder(_handle, attr.getHandle()); 00250 } 00251 return (*this); 00252 } 00253 00262 GroupBuilder & reserve(int64_t n) 00263 { 00264 if (n > 0) { 00265 lazyCreate(); 00266 getSuite()->reserveGroupBuilder(_handle, n); 00267 } 00268 return (*this); 00269 } 00270 00281 GroupBuilder & setGroupInherit(bool groupInherit) 00282 { 00283 if (_handle || !groupInherit) { 00284 lazyCreate(); 00285 getSuite()->setGroupBuilderInherit(_handle, (uint8_t) groupInherit); 00286 } 00287 return (*this); 00288 } 00289 00295 GroupBuilder & sort() 00296 { 00297 if (_handle) 00298 getSuite()->sortGroupBuilder(_handle); 00299 return (*this); 00300 } 00301 00306 enum BuilderBuildMode 00307 { 00312 BuildAndFlush = kFnKatGroupBuilderBuildAndFlush, 00313 00318 BuildAndRetain = kFnKatGroupBuilderBuildAndRetain 00319 }; 00320 00321 // @cond FN_INTERNAL_DEV 00322 typedef enum BuilderBuildMode BuilderBuildMode; 00323 // @endcond 00324 00340 GroupAttribute build(BuilderBuildMode builderMode = BuildAndFlush) 00341 { 00342 if (_handle) 00343 return Attribute::CreateAndSteal(getSuite()->buildGroupBuilder( 00344 _handle, (int32_t) builderMode)); 00345 else 00346 return GroupAttribute(true); 00347 } 00348 00350 00351 FnGroupBuilderHandle getHandle() { 00352 // this function is used to hand over GroupBuilders through C APIs 00353 // so we need to make sure we do not return NULL 00354 lazyCreate(); 00355 return _handle; 00356 } 00357 00358 static const FnAttributeHostSuite *getSuite() 00359 { 00360 return _attrSuite; 00361 } 00362 00363 static void setSuite(const FnAttributeHostSuite *suite); 00364 00365 static FnPlugStatus setHost(FnPluginHost *host); 00366 00367 00368 private: 00369 // no copy/assign 00370 GroupBuilder(const GroupBuilder& rhs); 00371 GroupBuilder& operator=(const GroupBuilder& rhs); 00372 00373 void lazyCreate() { 00374 if (_handle == 0x0) 00375 _handle = getSuite()->createGroupBuilder(); 00376 } 00377 00378 static const FnAttributeHostSuite *_attrSuite; 00379 00380 FnGroupBuilderHandle _handle; 00381 00382 //@endcond 00383 }; 00384 } 00385 FNATTRIBUTE_NAMESPACE_EXIT 00386 00387 #endif // FoundryKatanaGroupBuilder_H
1.7.3