All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Obj.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------
2 // Copyright (c) 2001-2018 by PDFTron Systems Inc. All Rights Reserved.
3 // Consult legal.txt regarding legal and license information.
4 //---------------------------------------------------------------------------------------
5 #ifndef PDFTRON_H_CPPSDFSDFObj
6 #define PDFTRON_H_CPPSDFSDFObj
7 
8 #include <Common/Exception.h>
9 #include <Common/UString.h>
10 #include <Common/Matrix2D.h>
11 #include <Filters/FilterWriter.h>
12 #include <Filters/Filter.h>
13 
14 
15 namespace pdftron {
16  namespace SDF {
17 
18 class DictIterator;
19 
40 class Obj
41 {
42 public:
43 
44  // Common methods for all objects -----------------------------------------------
45 
49  enum Type
50  {
59  };
60 
65  Type GetType () const;
66 
71  bool IsBool () const;
72 
77  bool IsNumber () const;
78 
83  bool IsNull () const;
84 
89  bool IsString () const;
90 
95  bool IsName () const;
96 
102  bool IsIndirect () const;
103 
109  bool IsContainer () const;
110 
115  bool IsDict () const;
116 
121  bool IsArray () const;
122 
127  bool IsStream () const;
128 
133  class SDFDoc& GetDoc () const;
134 
140  void Write(Filters::FilterWriter& stream);
141 
155  size_t Size () const;
156 
157  // Indirect Methods -------------------------------------------------------------
158 
164  UInt32 GetObjNum () const;
165 
171  UInt16 GetGenNum () const;
172 
178  size_t GetOffset () const;
179 
184  bool IsFree () const;
185 
193  void SetMark (bool mark);
194 
199  bool IsMarked () const;
200 
205  bool IsLoaded () const;
206 
211  bool IsValid () const;
212 
213  // Boolean Specific Methods ----------------------------------------------------
214 
219  bool GetBool () const;
220 
225  void SetBool (bool b);
226 
227  // Number Specific Methods -----------------------------------------------------
228 
233  double GetNumber () const;
234 
239  void SetNumber (double n);
240 
241 
242  // String Specific Methods -----------------------------------------------------
243 
258 #ifdef SWIG
259  std::vector<unsigned char> GetBuffer () const;
260 #else
261  const UChar* GetBuffer () const;
262 #endif
263 
279  UString GetAsPDFText() const;
280 
281 #ifndef SWIG
282  void GetAsPDFText(UString& out_str) const;
283 #endif
284 
292  void SetString(const UChar* value, size_t size);
293 
299  void SetString(const UString& str);
300 
301  // Name Specific Methods -------------------------------------------------------
302 
307  const char* GetName () const;
308 
313  void SetName (const char* name);
314 
315 
316  // Dictionary Specific Methods -------------------------------------------------
317 
334 
356  DictIterator Find (const char* key);
357 
367  Obj FindObj (const char* key);
368 
378  DictIterator Get (const char* key);
379 
392  Obj PutName (const char* key, const char* name);
393 
405  Obj PutArray (const char* key);
406 
419  Obj PutBool (const char* key, bool value);
420 
431  Obj PutDict (const char* key);
432 
445  Obj PutNumber (const char* key, double value);
446 
459  Obj PutString (const char* key, const char* value);
460 
474  Obj PutString (const char* key, const char* value, int size);
475 
489  Obj PutText(const char* key, const UString& value);
490 
497  void PutNull (const char* key);
498 
508  Obj Put(const char* key, Obj obj);
509 
524  Obj PutRect (const char* key, double x1, double y1, double x2, double y2);
525 
538  Obj PutMatrix(const char* key, const Common::Matrix2D& value);
539 
545  void Erase (const char* key);
546 
552  void Erase (DictIterator pos);
553 
562  bool Rename (const char* old_key, const char* new_key);
563 
564 
565  // Array Specific Methods ------------------------------------------------------
566 
573  Obj GetAt (size_t index) const;
574 
586  Obj InsertName (size_t pos, const char* name);
587 
598  Obj InsertArray (size_t pos);
599 
611  Obj InsertBool (size_t pos, bool value);
612 
623  Obj InsertDict (size_t pos);
624 
636  Obj InsertNumber (size_t pos, double value);
637 
649  Obj InsertString (size_t pos, const char* value);
650 
664  Obj InsertString (size_t pos, const char* value, int size);
665 
678  Obj InsertText(size_t pos, const UString& value);
679 
688  Obj InsertNull(size_t pos);
689 
701  Obj Insert(size_t pos, Obj obj);
702 
716  Obj InsertRect (size_t pos, double x1, double y1, double x2, double y2);
717 
729  Obj InsertMatrix(size_t pos, Common::Matrix2D& value);
730 
737  Obj PushBackName (const char* name);
738 
744  Obj PushBackArray ();
745 
752  Obj PushBackBool (bool value);
753 
759  Obj PushBackDict ();
760 
767  Obj PushBackNumber (double value);
768 
775  Obj PushBackString (const char* value);
776 
785  Obj PushBackString (const char* value, int size);
786 
794  Obj PushBackText (const UString& value);
795 
801  Obj PushBackNull ();
802 
811  Obj PushBack(Obj obj);
812 
822  Obj PushBackRect (double x1, double y1, double x2, double y2);
823 
832 
842  void EraseAt (size_t pos);
843 
844 
845  // Stream Specific Methods -----------------------------------------------------
846 
851  size_t GetRawStreamLength () const;
852 
858  Filters::Filter GetRawStream (bool decrypt) const;
859 
865 
870  void SetStreamData(
871  const char* data,
872  const size_t data_size,
873  Filters::Filter filter_chain = Filters::Filter() );
874 
875  // Support methods ----------------------------------------------------------------
876 
877  Obj() : mp_obj(0) {}
878  Obj(const Obj& c) : mp_obj(c.mp_obj) {}
879  Obj& operator=(const Obj& c) {mp_obj=c.mp_obj; return *this;}
880 
884  operator bool () { return mp_obj!=0;}
885 
892  bool IsEqual(const Obj& to) const;
893  bool operator ==(const Obj& to) const;
894  bool operator <(const Obj& to) const { return mp_obj < to.mp_obj; }
895 
896  //for xamarin use only
897  static Obj* CreateInternal(ptrdiff_t impl);
898  ptrdiff_t GetHandleInternal();
899 
901  #ifndef SWIGHIDDEN
902  Obj(TRN_Obj impl);
903  TRN_Obj mp_obj;
904 private:
905  mutable TRN_SDFDoc temp_doc;
906  #endif
907 };
909 
910 
911 
912  }; // namespace SDF
913 }; // namespace pdftron
914 
915 
916 
917 #include <Impl/SDFDoc.inl>
918 
919 #endif // PDFTRON_H_CPPSDFSDFObj
Type GetType() const
UString GetAsPDFText() const
bool IsContainer() const
void Erase(const char *key)
bool IsIndirect() const
TRN_UInt16 UInt16
Definition: BasicTypes.h:14
Obj PutBool(const char *key, bool value)
Obj PushBackString(const char *value)
UInt16 GetGenNum() const
Obj PutNumber(const char *key, double value)
Obj PushBackRect(double x1, double y1, double x2, double y2)
bool IsDict() const
void PutNull(const char *key)
bool Rename(const char *old_key, const char *new_key)
Obj Put(const char *key, Obj obj)
Obj InsertDict(size_t pos)
Obj InsertArray(size_t pos)
bool IsNumber() const
void SetName(const char *name)
bool IsFree() const
bool operator<(const Obj &to) const
Definition: Obj.h:894
bool IsLoaded() const
ptrdiff_t GetHandleInternal()
Obj PutText(const char *key, const UString &value)
DictIterator Get(const char *key)
const char * GetName() const
DictIterator Find(const char *key)
Obj(const Obj &c)
Definition: Obj.h:878
Obj InsertNull(size_t pos)
bool IsName() const
DictIterator GetDictIterator()
Filters::Filter GetDecodedStream() const
Obj PushBack(Obj obj)
Obj PutDict(const char *key)
UInt32 GetObjNum() const
bool IsString() const
Obj PushBackBool(bool value)
TRN_UInt32 UInt32
Definition: BasicTypes.h:13
void Write(Filters::FilterWriter &stream)
Obj InsertBool(size_t pos, bool value)
Obj InsertRect(size_t pos, double x1, double y1, double x2, double y2)
Filters::Filter GetRawStream(bool decrypt) const
Obj PutString(const char *key, const char *value)
Obj InsertMatrix(size_t pos, Common::Matrix2D &value)
TRN_UChar UChar
Definition: BasicTypes.h:12
size_t GetRawStreamLength() const
bool IsStream() const
Obj InsertNumber(size_t pos, double value)
Obj PushBackNumber(double value)
Obj InsertString(size_t pos, const char *value)
bool IsArray() const
Obj PutRect(const char *key, double x1, double y1, double x2, double y2)
Obj PutMatrix(const char *key, const Common::Matrix2D &value)
bool GetBool() const
bool IsBool() const
Obj PushBackText(const UString &value)
void SetMark(bool mark)
Obj InsertName(size_t pos, const char *name)
bool IsNull() const
void SetString(const UChar *value, size_t size)
Obj PutArray(const char *key)
void EraseAt(size_t pos)
Obj Insert(size_t pos, Obj obj)
Obj PutName(const char *key, const char *name)
bool IsMarked() const
Obj FindObj(const char *key)
Obj PushBackMatrix(Common::Matrix2D &value)
bool operator==(const Obj &to) const
void SetNumber(double n)
Obj InsertText(size_t pos, const UString &value)
bool IsValid() const
Obj PushBackName(const char *name)
size_t Size() const
size_t GetOffset() const
Obj GetAt(size_t index) const
void SetBool(bool b)
double GetNumber() const
Obj & operator=(const Obj &c)
Definition: Obj.h:879
const UChar * GetBuffer() const
static Obj * CreateInternal(ptrdiff_t impl)
void SetStreamData(const char *data, const size_t data_size, Filters::Filter filter_chain=Filters::Filter())
bool IsEqual(const Obj &to) const
class SDFDoc & GetDoc() const

© 2002-2014 PDFTron Systems Inc.