Adobe.com
Contents Suites Classes Class Index Member Index

IAIDictionary.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 "AIEntry.h"
00020 #include "AIArray.h"
00021 #include "AIDictionary.h"
00022 #include "IAILiteralString.h"
00023 #include "IAIRef.h"
00024 
00025 #include <memory>
00026 #include <vector>
00027 #include <utility>
00028 
00029 
00032 namespace ai
00033 {
00242         class Dictionary;
00243         class Array;
00244 
00245         class Entry
00246         {
00247         public:
00248                 using BinaryType = std::vector<char>;
00249 
00250                 explicit Entry(AIEntryRef entryRef);
00251                 Entry(bool boolVal);
00252                 Entry(ai::int32 intVal);
00253                 Entry(AIReal realVal);
00254                 Entry(const AIRealPoint& point);
00255                 Entry(const AIRealMatrix& matrix);
00256                 Entry(const std::string& strVal);
00257                 Entry(const ai::UnicodeString& value);
00258                 Entry(const BinaryType& value);
00259                 Entry(const Array& value);
00260                 Entry(const Dictionary& value);
00261                 Entry(const AIFillStyle& value);
00262                 Entry(const AIStrokeStyle& value);
00263 
00264                 //Static Entry Creators as the types are not overloadable in c'tor
00265                 static Entry FromPattern(AIPatternHandle pattern);
00266                 static Entry FromBrushPattern(AIPatternHandle pattern);
00267                 static Entry FromGradient(AIGradientHandle gradient);
00268                 static Entry FromCustomColor(AICustomColorHandle customColor);
00269                 static Entry FromPluginObject(AIObjectHandle obj);
00270                 static Entry FromSymbolPattern(AIPatternHandle symbolPattern);
00271                 static Entry FromArtStyle(AIArtStyleHandle artStyle);
00272                 static Entry FromBinary(void* data, size_t size);
00273 
00274                 Entry(const Entry& other);
00275                 ~Entry();
00276 
00277                 bool BoolVal() const;
00278                 operator bool() const
00279                 {
00280                         return BoolVal();
00281                 }
00282 
00283                 ai::int32 IntVal() const;
00284             operator ai::int32() const
00285                 {
00286                         return IntVal();
00287                 }
00288 
00289                 AIReal RealVal() const;
00290                 operator AIReal() const
00291                 {
00292                         return RealVal();
00293                 }
00294 
00295                 AIRealMatrix MatrixVal() const;
00296                 operator AIRealMatrix() const 
00297                 {
00298                         return MatrixVal();
00299                 }
00300 
00301                 AIRealPoint PointVal() const;
00302                 operator AIRealPoint () const
00303                 {
00304                         return PointVal();
00305                 }
00306 
00307                 BinaryType BinaryVal() const;
00308                 operator BinaryType() const
00309                 {
00310                         return BinaryVal();
00311                 }
00312 
00313                 std::string StringVal() const;
00314                 operator std::string() const
00315                 {
00316                         return StringVal();
00317                 }
00318 
00319                 ai::UnicodeString UnicodeStringVal() const;
00320                 operator ai::UnicodeString() const
00321                 {
00322                         return UnicodeStringVal();
00323                 }
00324 
00325                 AIArtHandle ArtHandleVal() const;
00326                 AIPatternHandle PatternVal() const;
00327                 AIPatternHandle BrushPatternVal() const;
00328                 AIGradientHandle GradientVal() const;
00329                 AICustomColorHandle CustomColorVal() const;
00330                 AIObjectHandle PluginObjectVal() const;
00331                 AIPatternHandle SymbolPatternVal() const;
00332                 std::unique_ptr<AIFillStyle> FillStyleVal() const;
00333                 std::unique_ptr<AIStrokeStyle> StrokeStyleVal() const;
00334                 AIArtStyleHandle ArtStyleVal() const;
00335                 void BinaryVal(void *value, size_t &size) const;
00336 
00337                 Array ArrayVal() const;
00338                 operator Array() const;
00339 
00340                 Dictionary DictionaryVal() const;
00341                 operator Dictionary () const;
00342 
00343                 AIEntryType GetType() const;
00344                 AIEntryRef get() const;
00345 
00346                 //Compare
00347                 bool operator == (const Entry& other) const;
00348 
00352                 ai::UnicodeString GetAsUnicodeString() const;
00353 
00354                 //swap
00355                 void swap(Entry& other) AINOEXCEPT;
00356 
00357                 //Move constructor and assignment
00358                 Entry(Entry&& other) AINOEXCEPT;
00359                 Entry& operator = (Entry other) AINOEXCEPT;
00360 
00361         private:
00362                 class Impl;
00363                 std::unique_ptr<Impl> pImpl;
00364                 Entry(std::unique_ptr<Impl>&& impl);
00365         };
00366 
00367 
00368         class Array
00369         {
00370         public:
00371                 //iterator
00372                 class iterator 
00373                 {
00374                 public:
00375                         using value_type = Entry;
00376                         explicit iterator(ai::int32 index, const Array& arr) :
00377                                 mIndex(index),
00378                                 mArray(arr)
00379                         {
00380                         }
00381 
00382                         iterator& operator++()
00383                         {
00384                                 if (mIndex < mArray.size())
00385                                 {
00386                                         ++mIndex;
00387                                 }
00388                                 return *this;
00389                         }
00390 
00391                         iterator operator++(int) { iterator retval = *this; ++(*this); return retval; }
00392                         bool operator==(iterator other) const { return mIndex == other.mIndex; }
00393                         bool operator!=(iterator other) const { return !(*this == other); }
00394                         value_type operator*() const
00395                         {
00396                                 return mArray.at(mIndex);
00397                         }
00398 
00399                 private:
00400                         ai::int32 mIndex = -1;
00401                         const Array& mArray;
00402                 };
00403 
00404                 Array();
00405                 explicit Array(AIArrayRef arrayRef);
00406 
00407                 ~Array(); //required for unique_ptr
00408 
00409                 //Copy and assignment
00410                 Array(const Array& other);
00411                 Array& operator = (Array other) AINOEXCEPT;//defines both move and non-move version
00412 
00413                 //Clone self
00414                 Array clone() const;
00415 
00416                 //Copy into self from other
00417                 void copy(const Array& other);
00418 
00419                 //query
00420                 ai::int32 size() const AINOEXCEPT;
00421                 Entry at(ai::int32 index) const;
00422 
00423                 //Helper class for operator[]
00424                 class ArrayEntryGetSet
00425                 {
00426                 public:
00427                         ArrayEntryGetSet(ai::int32 index, Array& arr) :mIndex(index), mArray(arr) {}
00428 
00429                         void operator = (Entry entry)
00430                         {
00431                                 //replace or insert 
00432                                 if (mArray.size() > mIndex)
00433                                         mArray.set(mIndex, entry);
00434                                 else
00435                                 {
00436                                         //Index out of range
00437                                         throw ai::Error(kBadParameterErr);
00438                                 }
00439                         }
00440 
00441                         operator Entry() const
00442                         {
00443                                 return mArray.at(mIndex);
00444                         }
00445 
00446                 private:
00447                         ai::int32 mIndex;
00448                         Array& mArray;
00449                 };
00450 
00451                 ArrayEntryGetSet operator[](ai::int32 index)
00452                 {
00453                         return ArrayEntryGetSet(index, *this);
00454                 }
00455 
00456                 //edit
00457                 void insert(ai::int32 index, const Entry& entry);
00458                 
00459                 //replace the entry at location
00460                 void set(ai::int32 index, const Entry& entry);
00461                 
00462                 //remove entry at location
00463                 void erase(ai::int32 index);
00464 
00465                 //add an entry at the end
00466                 void push_back(const Entry& entry);
00467 
00468                 //Reserves space upfront,
00469                 void reserve(ai::int32 size);
00470 
00471                 //get ArrayRef, not recommended to use it directly
00472                 AIArrayRef get() const;
00473 
00474                 //iterators
00475                 iterator begin() const;
00476                 iterator end() const;
00477 
00478                 //swap
00479                 void swap(Array& other) AINOEXCEPT;
00480 
00481                 //Move constructor and assignment
00482                 Array(Array&& other) AINOEXCEPT;
00483 
00484                 //Unit Test
00485                 static void Test();
00486         private:
00487                 class Impl;
00488                 std::unique_ptr<Impl> pImpl;
00489         };
00490 
00491 
00492         class Dictionary
00493         {
00494         public:
00495                 //iterator
00496                 class iterator 
00497                 {
00498                 public:
00499                         using value_type = std::pair<AIDictKey, Entry>;
00500 
00501                         explicit iterator(ai::Ref<AIDictionaryIterator> dict_iter) 
00502                                 : mDictIterator(std::move(dict_iter))
00503                         {
00504                         }
00505 
00506                         iterator& operator++();
00507                         iterator operator++(int) { iterator retval = *this; ++(*this); return retval; }
00508 
00509                         bool operator==(iterator other) const;
00510                         bool operator!=(iterator other) const { return !(*this == other); }
00511 
00512                         value_type operator*() const;
00513 
00514                         void swap(iterator& other) AINOEXCEPT
00515                         {
00516                                 mDictIterator.swap(other.mDictIterator);
00517                         }
00518 
00519                         iterator(const iterator&) = default;
00520                         iterator(iterator&&) = default;
00521                         iterator& operator = (iterator other)
00522                         {
00523                                 swap(other);
00524                                 return *this;
00525                         }
00526 
00527                 private:
00528                         ai::Ref<AIDictionaryIterator> mDictIterator;
00529                 };
00530 
00531                 using KeyType = AIDictKey;
00532 
00533                 enum Type
00534                 {
00535                         kCreateEmpty,
00536                         kCurrentDocument,
00537                         kCurrentDocumentNonRecorded,
00538                 };
00539 
00540                 explicit Dictionary(Type type = Type::kCreateEmpty); //construct an Dictionary of specific type
00541 
00542                 //Get ArtObject's dictionary
00543                 explicit Dictionary(AIArtHandle art); 
00544 
00545                 //Create a dictionary from AIDictionaryRef, 
00546                 //increments ref count in c'tor, and decrements in d'tor
00547                 explicit Dictionary(AIDictionaryRef dictRef);
00548 
00549                 //required for unique_ptr
00550                 ~Dictionary(); 
00551 
00552                 //Ref counted Copy and assignment
00553                 Dictionary(const Dictionary& other);
00554                 Dictionary& operator = (Dictionary other) AINOEXCEPT;
00555 
00556                 //Deep Copy/Clone 
00557                 Dictionary clone() const;
00558                 void copy(const Dictionary& other);
00559 
00560                 //get/set Unicode
00561                 ai::UnicodeString GetUnicodeString(KeyType key) const; //throws error if not found
00562                 AIErr GetUnicodeString(KeyType key, ai::UnicodeString& value) const AINOEXCEPT;
00563                 void SetUnicodeString(KeyType key, const ai::UnicodeString& value);
00564 
00565                 //get/set c string
00566                 std::string GetString(KeyType key) const; //throws error if not found
00567                 AIErr GetString(KeyType key, std::string& value) const AINOEXCEPT;
00568                 void SetString(KeyType key, const std::string& value);
00569 
00570                 //get/set real
00571                 AIReal GetReal(KeyType key) const;
00572                 AIErr GetReal(KeyType key, AIReal& value) const AINOEXCEPT;
00573                 void SetReal(KeyType key, AIReal value);
00574 
00575                 //get/set bool
00576                 AIBoolean GetBoolean(KeyType key) const;
00577                 AIErr GetBoolean(KeyType key, AIBoolean& value) const AINOEXCEPT;
00578                 void SetBoolean(KeyType key, AIBoolean value);
00579 
00580                 //get set integer
00581                 ai::int32 GetInteger(KeyType key) const;
00582                 AIErr GetInteger(KeyType key, ai::int32& value) const AINOEXCEPT;
00583                 void SetInteger(KeyType key, ai::int32 value);
00584 
00585                 //get/set pointer
00586                 ai::intptr GetPointer(KeyType key) const;
00587                 AIErr GetPointer(KeyType key, ai::intptr& value) const AINOEXCEPT;
00588                 void SetPointer(KeyType key, ai::intptr value);
00589 
00590                 //get/set binary
00591                 using BinaryType = Entry::BinaryType;
00592                 BinaryType GetBinary(KeyType key) const;
00593                 AIErr GetBinary(KeyType key, BinaryType& value) const AINOEXCEPT;
00594                 void SetBinary(KeyType key, const BinaryType& value);
00595 
00596                 //get/set Dictionary
00597                 Dictionary GetDictionary(KeyType key) const;
00598                 AIErr GetDictionary(KeyType key, Dictionary& value) const AINOEXCEPT;
00599                 void SetDictionary(KeyType key, const Dictionary& value);
00600 
00601                 //get/set array
00602                 Array GetArray(KeyType key) const;
00603                 AIErr GetArray(KeyType key, Array& value) const AINOEXCEPT;
00604                 void SetArray(KeyType key, const Array& value);
00605 
00606                 //get/set entry
00607                 Entry Get(KeyType key) const;
00608                 void Set(KeyType key, const Entry& entry);
00609 
00610                 //Helper class for operator[]
00611                 class DictEntryGetSet
00612                 {
00613                 public: 
00614                         DictEntryGetSet(KeyType key, Dictionary& dict):mKey(key), mDict(dict){}
00615                         void operator = (Entry entry)
00616                         {
00617                                 mDict.Set(mKey, entry);
00618                         }
00619 
00620                         operator Entry() const
00621                         {
00622                                 return mDict.Get(mKey);
00623                         }
00624 
00625                 private:
00626                         KeyType mKey;
00627                         Dictionary& mDict;
00628                 };
00629 
00630                 DictEntryGetSet operator[](KeyType key)
00631                 {
00632                         return DictEntryGetSet(key, *this);
00633                 }
00634 
00635                 const char* GetKeyString(KeyType key) const;
00636         
00637         KeyType GetKey(const char* string) const;
00638 
00639                 //Query
00640                 bool IsKnown(KeyType key) const;
00641                 AIEntryType GetEntryType(KeyType key) const;
00642                 
00643                 iterator find(KeyType key);
00644 
00645                 //Deletes/erases an entry
00646                 void erase(KeyType key);
00647                 
00648                 //Mark art as changed
00649                 void TouchArt();
00650 
00651                 //get DictionaryRef, recommended not to use it
00652                 AIDictionaryRef get() const AINOEXCEPT;
00653                 
00654                 iterator begin() const;
00655                 iterator end() const;
00656 
00657                 //swap
00658                 void swap(Dictionary& other) AINOEXCEPT;
00659 
00660                 //Move constructor and assignment
00661                 Dictionary(Dictionary&& other) AINOEXCEPT;
00662 
00663                 //Unit Test
00664                 static void Test();
00665         private:
00666                 class Impl;
00667                 std::unique_ptr<Impl> pImpl;
00668         };
00669 
00670         // Utility functions
00671 
00672         // True if a dictionary is associated with the art object, false otherwise.
00673         bool HasDictionary(AIArtHandle art) AINOEXCEPT;
00674 
00675         // True if a dictionary exists and is empty or if no dictionary exists.
00676         // False if a dictionary associated with the art object contains any entries.
00677         bool IsDictionaryEmpty(AIArtHandle art) AINOEXCEPT;
00678 }


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