InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DigitalPublishingDictionary.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Adobe Systems Inc.
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // ADOBE CONFIDENTIAL
16 //
17 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
18 //
19 // NOTICE: All information contained herein is, and remains
20 // the property of Adobe Systems Incorporated and its suppliers,
21 // if any. The intellectual and technical concepts contained
22 // herein are proprietary to Adobe Systems Incorporated and its
23 // suppliers and may be covered by U.S. and Foreign Patents,
24 // patents in process, and are protected by trade secret or copyright law.
25 // Dissemination of this information or reproduction of this material
26 // is strictly forbidden unless prior written permission is obtained
27 // from Adobe Systems Incorporated.
28 //
29 //========================================================================================
30 
31 
32 #include "PMRect.h"
33 #include "IDFile.h"
34 
35 #include <boost/shared_ptr.hpp>
36 
37 namespace id_digpub
38 {
39 
43 class Object;
44 typedef boost::shared_ptr<Object> ObjectPtr;
45 
46 class Object
47 {
48 public:
52  enum Type
53  {
54  kBoolean, // bool16
55  kInteger, // int32
56  kLongInteger, // int64
57  kReal, // PMReal
58  kString, // WideString
59  kFile, // IDFile
60  kDate, // IDTime
61  kDictionary, // Object
62  kArray, // Object
63 
64  kInvalidType = 0xffffffff
65  };
66 
67  virtual ~Object() {}
68 
72  virtual Type GetType() const = 0;
73 
80  virtual ObjectPtr CreateBoolean(bool16 value) const = 0;
81 
88  virtual ObjectPtr CreateInteger(int32 value) const = 0;
89 
96  virtual ObjectPtr CreateLongInteger(int64 value) const = 0;
97 
104  virtual ObjectPtr CreateReal(PMReal const &value) const = 0;
105 
112  virtual ObjectPtr CreateString(WideString const &value) const = 0;
113 
120  virtual ObjectPtr CreateFile(IDFile const &value) const = 0;
121 
128  virtual ObjectPtr CreateDate(IDTime const &value) const = 0;
129 
135  virtual ObjectPtr CreateDictionary() const = 0;
136 
143  virtual ObjectPtr CreateArray(size_t size = 0) const = 0;
144 
151  virtual bool GetBoolean(bool16 &value) const = 0;
152 
159  virtual bool SetBoolean(bool16 value) = 0;
160 
167  virtual bool GetInteger(int32 &value) const = 0;
168 
175  virtual bool SetInteger(int32 value) = 0;
176 
183  virtual bool GetLongInteger(int64 &value) const = 0;
184 
191  virtual bool SetLongInteger(int64 value) = 0;
192 
199  virtual bool GetReal(PMReal &value) const = 0;
200 
207  virtual bool SetReal(PMReal const &value) = 0;
208 
215  virtual bool GetString(WideString &value) const = 0;
216 
223  virtual bool SetString(WideString const &value) = 0;
224 
231  virtual bool GetFile(IDFile &value) const = 0;
232 
239  virtual bool SetFile(IDFile const &value) = 0;
240 
247  virtual bool GetDate(IDTime &value) const = 0;
248 
255  virtual bool SetDate(IDTime const &value) = 0;
256 
264  virtual bool GetDictionaryKeys(K2Vector<WideString> &keys) const = 0;
265 
274  virtual bool GetDictionaryValue(WideString const &key, ObjectPtr &value) const = 0;
275 
285  virtual bool SetDictionaryValue(WideString const &key, ObjectPtr const &value) = 0;
286 
296  virtual bool RemoveDictionaryValue(WideString const &key) = 0;
297 
303  virtual bool ClearDictionary() = 0;
304 
311  virtual bool GetArraySize(size_t &size) const = 0;
312 
324  virtual bool SetArraySize(size_t size) = 0;
325 
334  virtual bool GetNthArrayValue(size_t index, ObjectPtr &value) const = 0;
335 
344  virtual bool SetNthArrayValue(size_t index, ObjectPtr const &value) = 0;
345 
353  virtual bool AppendArrayValue(ObjectPtr const &value) = 0;
354 
355  // Convenience methods for working with dictionaries
356 
365  bool GetBooleanValue(WideString const &key, bool16 &value) const
366  {
367  ObjectPtr valueObj;
368 
369  return GetDictionaryValue(key, valueObj) && valueObj->GetBoolean(value);
370  }
371 
382  bool SetBooleanValue(WideString const &key, bool16 value)
383  {
384  ObjectPtr valueObj;
385 
386  return
387  (GetDictionaryValue(key, valueObj) && valueObj->SetBoolean(value)) ||
388  SetDictionaryValue(key, CreateBoolean(value))
389  ;
390  }
391 
400  bool GetIntegerValue(WideString const &key, int32 &value) const
401  {
402  ObjectPtr valueObj;
403 
404  return GetDictionaryValue(key, valueObj) && valueObj->GetInteger(value);
405  }
406 
417  bool SetIntegerValue(WideString const &key, int32 value)
418  {
419  ObjectPtr valueObj;
420 
421  return
422  (GetDictionaryValue(key, valueObj) && valueObj->SetInteger(value)) ||
423  SetDictionaryValue(key, CreateInteger(value))
424  ;
425  }
426 
435  bool GetLongIntegerValue(WideString const &key, int64 &value) const
436  {
437  ObjectPtr valueObj;
438 
439  return GetDictionaryValue(key, valueObj) && valueObj->GetLongInteger(value);
440  }
441 
452  bool SetLongIntegerValue(WideString const &key, int64 value)
453  {
454  ObjectPtr valueObj;
455 
456  return
457  (GetDictionaryValue(key, valueObj) && valueObj->SetLongInteger(value)) ||
459  ;
460  }
461 
470  bool GetRealValue(WideString const &key, PMReal &value) const
471  {
472  ObjectPtr valueObj;
473 
474  return GetDictionaryValue(key, valueObj) && valueObj->GetReal(value);
475  }
476 
487  bool SetRealValue(WideString const &key, PMReal const &value)
488  {
489  ObjectPtr valueObj;
490 
491  return
492  (GetDictionaryValue(key, valueObj) && valueObj->SetReal(value)) ||
493  SetDictionaryValue(key, CreateReal(value))
494  ;
495  }
496 
505  bool GetStringValue(WideString const &key, WideString &value) const
506  {
507  ObjectPtr valueObj;
508 
509  return GetDictionaryValue(key, valueObj) && valueObj->GetString(value);
510  }
511 
522  bool SetStringValue(WideString const &key, WideString const &value)
523  {
524  ObjectPtr valueObj;
525 
526  return
527  (GetDictionaryValue(key, valueObj) && valueObj->SetString(value)) ||
528  SetDictionaryValue(key, CreateString(value))
529  ;
530  }
531 
540  bool GetFileValue(WideString const &key, IDFile &value) const
541  {
542  ObjectPtr valueObj;
543 
544  return GetDictionaryValue(key, valueObj) && valueObj->GetFile(value);
545  }
546 
557  bool SetFileValue(WideString const &key, IDFile const &value)
558  {
559  ObjectPtr valueObj;
560 
561  return
562  (GetDictionaryValue(key, valueObj) && valueObj->SetFile(value)) ||
563  SetDictionaryValue(key, CreateFile(value))
564  ;
565  }
566 
575  bool GetDateValue(WideString const &key, IDTime &value) const
576  {
577  ObjectPtr valueObj;
578 
579  return GetDictionaryValue(key, valueObj) && valueObj->GetDate(value);
580  }
581 
592  bool SetDateValue(WideString const &key, IDTime const &value)
593  {
594  ObjectPtr valueObj;
595 
596  return
597  (GetDictionaryValue(key, valueObj) && valueObj->SetDate(value)) ||
598  SetDictionaryValue(key, CreateDate(value))
599  ;
600  }
601 
611  bool GetNthArrayRealValue(size_t index, PMReal &value) const
612  {
613  ObjectPtr nthValue;
614 
615  return GetNthArrayValue(index, nthValue) && nthValue->GetReal(value);
616  }
617 
626  bool GetNthArrayFileValue(size_t index, IDFile &value) const
627  {
628  ObjectPtr nthValue;
629 
630  return GetNthArrayValue(index, nthValue) && nthValue->GetFile(value);
631  }
632 
640  ObjectPtr CreatePointObject(PMReal const &x, PMReal const &y) const
641  {
642  ObjectPtr pointArray = CreateArray(2);
643 
644  if (pointArray)
645  {
646  pointArray->SetNthArrayValue(0, CreateReal(x));
647  pointArray->SetNthArrayValue(1, CreateReal(y));
648  }
649 
650  return pointArray;
651  }
652 
659  ObjectPtr CreatePMPointObject(PMPoint const &p) const
660  {
661  return CreatePointObject(p.X(), p.Y());
662  }
663 
673  bool GetPMPointValue(WideString const &key, PMPoint &point) const
674  {
675  ObjectPtr pointArray;
676 
677  return
678  GetDictionaryValue(key, pointArray) &&
679  pointArray->GetNthArrayRealValue(0, point.X()) &&
680  pointArray->GetNthArrayRealValue(1, point.Y())
681  ;
682  }
683 
693  ObjectPtr CreateRectObject(PMReal const &left, PMReal const &top, PMReal const &right, PMReal const &bottom) const
694  {
695  ObjectPtr rectArray = CreateArray(4);
696 
697  if (rectArray)
698  {
699  rectArray->SetNthArrayValue(0, CreateReal(left));
700  rectArray->SetNthArrayValue(1, CreateReal(top));
701  rectArray->SetNthArrayValue(2, CreateReal(right));
702  rectArray->SetNthArrayValue(3, CreateReal(bottom));
703  }
704 
705  return rectArray;
706  }
707 
714  ObjectPtr CreatePMRectObject(PMRect const &r) const
715  {
716  return CreateRectObject(r.Left(), r.Top(), r.Right(), r.Bottom());
717  }
718 
728  bool GetPMRectValue(WideString const &key, PMRect &bounds) const
729  {
730  ObjectPtr rectArray;
731 
732  return
733  GetDictionaryValue(key, rectArray) &&
734  rectArray->GetNthArrayRealValue(0, bounds.Left()) &&
735  rectArray->GetNthArrayRealValue(1, bounds.Top()) &&
736  rectArray->GetNthArrayRealValue(2, bounds.Right()) &&
737  rectArray->GetNthArrayRealValue(3, bounds.Bottom())
738  ;
739  }
740 
751  ObjectPtr CreateAssetObject(IDFile const &file, WideString const &id, WideString const &tag = WideString()) const
752  {
753  ObjectPtr assetObject = CreateDictionary();
754 
755  if (assetObject)
756  {
757  assetObject->SetFileValue(WideString("File"), file);
758  assetObject->SetStringValue(WideString("ID"), id);
759 
760  if (!tag.empty())
761  {
762  assetObject->SetStringValue(WideString("Tag"), tag);
763  }
764  }
765 
766  return assetObject;
767  }
768 
782  bool GetAssetObjectValues(IDFile &file, WideString &id, WideString &tag) const
783  {
784  if (GetFileValue(WideString("File"), file) && GetStringValue(WideString("ID"), id))
785  {
786  if (!GetStringValue(WideString("Tag"), tag))
787  {
788  tag = WideString();
789  }
790 
791  return true;
792  }
793 
794  return false;
795  }
796 };
797 
798 }