Adobe.com
Contents Suites Classes Class Index Member Index

IAIArtMatcher.hpp

Go to the documentation of this file.
00001 /*************************************************************************
00002 *
00003 * ADOBE CONFIDENTIAL
00004 * 
00005 * Copyright 2017 Adobe
00006 * 
00007 * All Rights Reserved.
00008 *
00009 * NOTICE: Adobe permits you to use, modify, and distribute this file in
00010 * accordance with the terms of the Adobe license agreement accompanying
00011 * it. If you have received this file from a source other than Adobe,
00012 * then your use, modification, or distribution of it requires the prior
00013 * written permission of Adobe.
00014 *
00015 **************************************************************************/
00016 
00017 #pragma once
00018 
00019 #include "AIArt.h"
00020 #include "AIMatchingArt.h"
00021 #include "IAIArtSet.hpp"
00022 
00023 #include <vector>
00024 #include <iterator>
00025 
00026 
00029 namespace ai
00030 {
00031         
00119 class ArtMatcher
00120 {
00121 public:
00122         using iterator = AIArtHandle*;
00123         using reverse_iterator = std::reverse_iterator<iterator>;
00124 
00127         explicit ArtMatcher(size_t iNumSpecs = 0, AIBoolean matchArtInDictionaries = false) :
00128                 m_pSpecs(iNumSpecs), m_MatchArtInDictionaries{matchArtInDictionaries}
00129         {
00130         }
00131 
00134         ArtMatcher(const AIMatchingArtSpec& spec, AIBoolean matchArtInDictionaries = false) :
00135                 m_pSpecs{spec}, m_MatchArtInDictionaries{matchArtInDictionaries}
00136         {
00137                 if (m_MatchArtInDictionaries)
00138                 {
00139                         m_pSpecs[0].whichAttr |= kMatchDictionaryArt;
00140                 }
00141         }
00142         
00145         template<std::size_t N>
00146         ArtMatcher(const AIMatchingArtSpec(&specs)[N], AIBoolean matchArtInDictionaries = false):
00147                 m_pSpecs{ specs, specs + N }, m_MatchArtInDictionaries{matchArtInDictionaries}
00148         {
00149                 if (m_MatchArtInDictionaries)
00150                 {
00151                         for (auto& spec : m_pSpecs)
00152                         {
00153                                 spec.whichAttr |= kMatchDictionaryArt;
00154                         }
00155                 }
00156         }
00157 
00160         ~ArtMatcher();
00161 
00164         ArtMatcher(const ArtMatcher&) = delete;
00165         
00168         ArtMatcher& operator=(const ArtMatcher&) = delete;
00169         
00172         ArtMatcher(ArtMatcher&& other) AINOEXCEPT;
00173         
00176         ArtMatcher& operator= (ArtMatcher&& other) AINOEXCEPT;
00177         
00180         AIErr SetSpec(size_t iX, ai::int16 shType, ai::int32 lWhichAttr, ai::int32 lAttr);
00181         
00184         AIErr PushSpec(ai::int16 shType, ai::int32 lWhichAttr, ai::int32 lAttr);
00185         
00188         AIErr GetMatchingArt();
00189         
00192         AIErr GetSelectedArt();
00193         
00196         AIErr GetMatchingArtFromLayerList(AILayerList layerList);
00197         
00200         AIErr GetMatchingArtFromArt(AIArtHandle art);
00201         
00204         AIErr GetArtForCurrentPathStyle();
00205         
00208         AIErr GetSelectedArtFromLayerList(AILayerList layerList);
00209 
00212         ai::int32 GetNumMatches() const;
00213         
00216         AIArtHandle GetMatchedArt(size_t iX) const;
00217 
00218         //Operator version of GetMatchedArt()
00219 
00220         AIArtHandle operator[](size_t iX) const;
00221 
00224         ai::ArtSet GetArtSet() const;
00225 
00228         AIErr GetLastError() const AINOEXCEPT { return m_LastError; }
00229 
00230         // The ClearMatchedArt method is for legacy usage, you can directly change the content in your loop with auto& 
00231         /* 
00232                 for (auto& art : matcher)
00233                 {
00234                         // if you want to change the content based on some condition
00235                         if(myCond(art))
00236                                 art = nullptr; // it will set the value of the content to nullptr 
00237                 }
00238         */
00239         void ClearMatchedArt(size_t iX);        // to enable multi-pass algorithms to filter out some of the matches
00240         
00242         enum eArtMatcherErrors
00243         {
00244                 AM_OK = kNoErr,
00245                 AM_InvalidIndex,
00246                 AM_InvalidSuite,
00247                 AM_UnknownException,
00248                 AM_NumErrs,
00249                 AM_NoResult
00250         };
00251 
00253         explicit operator bool() const AINOEXCEPT
00254         {
00255                 return (m_hMatches != nullptr && m_lNumMatches > 0);
00256         }
00257 
00259         iterator begin () const AINOEXCEPT
00260         { 
00261                 if (m_hMatches)
00262                         return *m_hMatches;
00263                 return nullptr;
00264         }
00265 
00267         iterator end() const AINOEXCEPT
00268         {
00269                 if (m_hMatches)
00270                         return (*m_hMatches) + m_lNumMatches;
00271                 return nullptr;
00272         }
00273 
00274         reverse_iterator rbegin() const AINOEXCEPT
00275         {
00276                 return reverse_iterator(end());
00277         }
00278 
00279         reverse_iterator rend() const AINOEXCEPT
00280         {
00281                 return reverse_iterator(begin());
00282         }
00283 
00285         void clear() AINOEXCEPT; 
00286 
00288         AIArtHandle** release() AINOEXCEPT;
00289 
00290 private:
00291         // swaps with other ArtMatcher
00292         void swap(ArtMatcher& other) AINOEXCEPT;
00293         
00294         enum QueryType 
00295         {
00296                 kQueryMatchingArt,
00297                 kQuerySelection,
00298                 kQueryFromLayerList,
00299                 kQuerySelectedArtFromLayerList,
00300                 kQueryFromArt,
00301                 kQueryFromCurrentPathStyle,
00302         };
00303 
00304         AIErr LoadMatchingArt(QueryType qryType = kQueryMatchingArt, void* cookie = nullptr);
00305 
00306         std::vector<AIMatchingArtSpec> m_pSpecs;
00307         AIBoolean m_MatchArtInDictionaries      = false;
00308         ai::int32 m_lNumMatches                         = 0;
00309         AIArtHandle **m_hMatches                        = nullptr;
00310         AIErr m_LastError                                       = kNoErr;
00311 };
00312 
00313 }


Contents Suites Classes Class Index Member Index
Adobe Solutions Network
 
Copyright © 2014 Adobe Systems Incorporated. All rights reserved.
Terms of Use Online Privacy Policy Adobe and accessibility Avoid software piracy Permissions and Trademarks