00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
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
00347 bool operator == (const Entry& other) const;
00348
00352 ai::UnicodeString GetAsUnicodeString() const;
00353
00354
00355 void swap(Entry& other) AINOEXCEPT;
00356
00357
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
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();
00408
00409
00410 Array(const Array& other);
00411 Array& operator = (Array other) AINOEXCEPT;
00412
00413
00414 Array clone() const;
00415
00416
00417 void copy(const Array& other);
00418
00419
00420 ai::int32 size() const AINOEXCEPT;
00421 Entry at(ai::int32 index) const;
00422
00423
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
00432 if (mArray.size() > mIndex)
00433 mArray.set(mIndex, entry);
00434 else
00435 {
00436
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
00457 void insert(ai::int32 index, const Entry& entry);
00458
00459
00460 void set(ai::int32 index, const Entry& entry);
00461
00462
00463 void erase(ai::int32 index);
00464
00465
00466 void push_back(const Entry& entry);
00467
00468
00469 void reserve(ai::int32 size);
00470
00471
00472 AIArrayRef get() const;
00473
00474
00475 iterator begin() const;
00476 iterator end() const;
00477
00478
00479 void swap(Array& other) AINOEXCEPT;
00480
00481
00482 Array(Array&& other) AINOEXCEPT;
00483
00484
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
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);
00541
00542
00543 explicit Dictionary(AIArtHandle art);
00544
00545
00546
00547 explicit Dictionary(AIDictionaryRef dictRef);
00548
00549
00550 ~Dictionary();
00551
00552
00553 Dictionary(const Dictionary& other);
00554 Dictionary& operator = (Dictionary other) AINOEXCEPT;
00555
00556
00557 Dictionary clone() const;
00558 void copy(const Dictionary& other);
00559
00560
00561 ai::UnicodeString GetUnicodeString(KeyType key) const;
00562 AIErr GetUnicodeString(KeyType key, ai::UnicodeString& value) const AINOEXCEPT;
00563 void SetUnicodeString(KeyType key, const ai::UnicodeString& value);
00564
00565
00566 std::string GetString(KeyType key) const;
00567 AIErr GetString(KeyType key, std::string& value) const AINOEXCEPT;
00568 void SetString(KeyType key, const std::string& value);
00569
00570
00571 AIReal GetReal(KeyType key) const;
00572 AIErr GetReal(KeyType key, AIReal& value) const AINOEXCEPT;
00573 void SetReal(KeyType key, AIReal value);
00574
00575
00576 AIBoolean GetBoolean(KeyType key) const;
00577 AIErr GetBoolean(KeyType key, AIBoolean& value) const AINOEXCEPT;
00578 void SetBoolean(KeyType key, AIBoolean value);
00579
00580
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
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
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
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
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
00607 Entry Get(KeyType key) const;
00608 void Set(KeyType key, const Entry& entry);
00609
00610
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
00640 bool IsKnown(KeyType key) const;
00641 AIEntryType GetEntryType(KeyType key) const;
00642
00643 iterator find(KeyType key);
00644
00645
00646 void erase(KeyType key);
00647
00648
00649 void TouchArt();
00650
00651
00652 AIDictionaryRef get() const AINOEXCEPT;
00653
00654 iterator begin() const;
00655 iterator end() const;
00656
00657
00658 void swap(Dictionary& other) AINOEXCEPT;
00659
00660
00661 Dictionary(Dictionary&& other) AINOEXCEPT;
00662
00663
00664 static void Test();
00665 private:
00666 class Impl;
00667 std::unique_ptr<Impl> pImpl;
00668 };
00669
00670
00671
00672
00673 bool HasDictionary(AIArtHandle art) AINOEXCEPT;
00674
00675
00676
00677 bool IsDictionaryEmpty(AIArtHandle art) AINOEXCEPT;
00678 }