User-Defined Function API  7.0-6
 All Classes Functions Enumerations Enumerator
MarkLogic.h
1 /* -*- mode: c++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  *
3  * Copyright 2002-2015 MarkLogic Corporation. All Rights Reserved.
4  *
5  */
29 #ifndef _MARKLOGIC_MARKLOGIC_H_
30 #define _MARKLOGIC_MARKLOGIC_H_
31 
32 #include <stddef.h>
33 
34 #ifdef _MSC_VER
35 typedef __int32 int32_t;
36 typedef unsigned __int32 uint32_t;
37 typedef __int64 int64_t;
38 typedef unsigned __int64 uint64_t;
39 #ifndef MLDLL
40 #define MLDLL __declspec(dllimport)
41 #endif
42 #else // !_MSC_VER
43 #include <stdint.h>
44 #define MLDLL
45 #endif
46 
47 #define MARKLOGIC_API_VERSION 1
48 
49 namespace marklogic
50 {
51 
52 class Map;
53 class MapImpl;
54 class SequenceImpl;
55 class StringImpl;
56 
58 class MLDLL RangeIndex
59 {
60 public:
69  enum Type {
70  INT,
72  LONG,
78  TIME,
79  DATE,
88  POINT
89  };
90 
92  enum Order {
93  ASCENDING,
94  DESCENDING
95  };
96 };
97 
98 template<class T, typename PT>
99 class MLDLL CTypeWrapperBase
100 {
101 protected:
102  PT val;
103 
104 public:
105  CTypeWrapperBase(): val(0) {}
106  CTypeWrapperBase(PT v): val(v) {}
107 
108  operator PT&() { return val; }
109  operator const PT&() const { return val; }
110 
111  bool operator<(T o) const { return val < o.val; }
112  bool operator<=(T o) const { return val <= o.val; }
113  bool operator>(T o) const { return val > o.val; }
114  bool operator>=(T o) const { return val >= o.val; }
115  bool operator==(T o) const { return val == o.val; }
116  bool operator!=(T o) const { return val != o.val; }
117 
118  T operator-(T o) const { return val - o.val; }
119  T operator+(T o) const { return val + o.val; }
120  T operator*(T o) const { return val * o.val; }
121  T operator/(T o) const { return val / o.val; }
122 
123  T operator--(int) { return val--; }
124  T operator++(int) { return val++; }
125  T& operator--() { --val; return (T&)*this; }
126  T& operator++() { ++val; return (T&)*this; }
127  T& operator-=(T o) { val -= o.val; return (T&)*this; }
128  T& operator+=(T o) { val += o.val; return (T&)*this; }
129  T& operator*=(T o) { val *= o.val; return (T&)*this; }
130  T& operator/=(T o) { val /= o.val; return (T&)*this; }
131 };
132 
133 template<class T, typename PT>
134 class MLDLL CTypeWrapperF : public CTypeWrapperBase<T,PT>
135 {
136 protected:
137  typedef CTypeWrapperF<T,PT> Base;
138 
139 public:
140  CTypeWrapperF() {}
142 
143  T operator-() const { return -this->val; }
144  T operator+() const { return +this->val; }
145 };
146 
147 template<class T, typename PT>
148 class MLDLL CTypeWrapperU : public CTypeWrapperBase<T,PT>
149 {
150 protected:
151  typedef CTypeWrapperU<T,PT> Base;
152 
153 public:
154  CTypeWrapperU() {}
156 
157  T operator%(T o) const { return this->val % o.val; }
158  T& operator%=(T o) { this->val %= o.val; return (T&)*this; }
159 };
160 
161 template<class T, typename PT>
162 class MLDLL CTypeWrapper : public CTypeWrapperU<T,PT>
163 {
164 protected:
165  typedef CTypeWrapper<T,PT> Base;
166 
167 public:
168  CTypeWrapper() {}
169  CTypeWrapper(PT v): CTypeWrapperU<T,PT>(v) {}
170 
171  T operator-() const { return -this->val; }
172  T operator+() const { return +this->val; }
173 };
174 
175 
176 #ifdef _MSC_VER
177 typedef double DecimalType;
178 #else
179 typedef long double DecimalType;
180 #endif
181 
182 class MLDLL Decimal : public CTypeWrapperF<Decimal,DecimalType>
183 {
184 public:
185  Decimal(): Base() {}
186  Decimal(DecimalType v): Base(v) {}
187 };
188 
190 class MLDLL DateTime : public CTypeWrapper<DateTime,int64_t>
191 {
192 public:
193  DateTime(): Base() {}
194  DateTime(int64_t v): Base(v) {}
195 };
196 
198 class MLDLL Date : public CTypeWrapper<Date,int64_t>
199 {
200 public:
201  Date(): Base() {}
202  Date(int64_t v): Base(v) {}
203 };
204 
206 class MLDLL Time : public CTypeWrapper<Time,int64_t>
207 {
208 public:
209  Time(): Base() {}
210  Time(int64_t v): Base(v) {}
211 };
212 
214 class MLDLL GYearMonth : public CTypeWrapper<GYearMonth,int>
215 {
216 public:
217  GYearMonth(): Base() {}
218  GYearMonth(int v): Base(v) {}
219 };
220 
222 class MLDLL GYear : public CTypeWrapper<GYear,int>
223 {
224 public:
225  GYear(): Base() {}
226  GYear(int v): Base(v) {}
227 };
228 
230 class MLDLL GMonth : public CTypeWrapperU<GMonth,unsigned>
231 {
232 public:
233  GMonth(): Base() {}
234  GMonth(unsigned v): Base(v) {}
235 };
236 
238 class MLDLL GDay : public CTypeWrapperU<GDay,unsigned>
239 {
240 public:
241  GDay(): Base() {}
242  GDay(unsigned v): Base(v) {}
243 };
244 
246 class MLDLL YearMonthDuration : public CTypeWrapper<YearMonthDuration,int>
247 {
248 public:
249  YearMonthDuration(): Base() {}
250  YearMonthDuration(int v): Base(v) {}
251 };
252 
254 class MLDLL DayTimeDuration : public CTypeWrapper<DayTimeDuration,int64_t>
255 {
256 public:
257  DayTimeDuration(): Base() {}
258  DayTimeDuration(int64_t v): Base(v) {}
259 };
260 
263 class MLDLL String
264 {
265 public:
266  String(StringImpl* =0);
267  String(const char* _str, const char* _collation = 0);
268  String(const String& o);
269  String& operator=(const String& o);
270  ~String();
271 
272  operator bool() const { return str!=0; }
273 
274  operator const char*() const;
275  const char* get() const;
276  size_t length() const;
277  const char* collation() const;
278 
279  bool operator<(const String& o) const;
280  bool operator<=(const String& o) const;
281  bool operator>(const String& o) const;
282  bool operator>=(const String& o) const;
283  bool operator==(const String& o) const;
284  bool operator!=(const String& o) const;
285 
286 protected:
287  StringImpl* str;
288 };
289 
291 class MLDLL Point
292 {
293 protected:
294  float lat;
295  float lng;
296  const void* coord;
297 
298 public:
299  Point();
300  Point(float _lat, float _lng, const char* _coordinateSystem = "wgs84");
301 
302  float latitude() const;
303  float longitude() const;
304  const char* coordinateSystem() const;
305 
306  bool operator<(const Point& o) const;
307  bool operator<=(const Point& o) const;
308  bool operator>(const Point& o) const;
309  bool operator>=(const Point& o) const;
310  bool operator==(const Point& o) const;
311  bool operator!=(const Point& o) const;
312 };
313 
339 class MLDLL TupleIterator
340 {
341 public:
343  virtual void next() =0;
345  virtual bool done() const =0;
346 
347  // Information about this tuple iterator
349  virtual bool descending() const =0;
351  virtual size_t width() const =0;
353  virtual RangeIndex::Type type(size_t i) const =0;
357  virtual const char* collation(size_t i) const =0;
361  virtual const char* coordinateSystem(size_t i) const =0;
362 
363  // Information about the current tuple
370  virtual uint64_t frequency() const =0;
374  virtual bool null(size_t i) const =0;
375 
388  virtual void value(size_t i, int&) const =0;
389  virtual void value(size_t i, unsigned&) const =0;
390  virtual void value(size_t i, int64_t&) const =0;
391  virtual void value(size_t i, uint64_t&) const =0;
392  virtual void value(size_t i, float&) const =0;
393  virtual void value(size_t i, double&) const =0;
394  virtual void value(size_t i, Decimal&) const =0;
395  virtual void value(size_t i, DateTime&) const =0;
396  virtual void value(size_t i, Date&) const =0;
397  virtual void value(size_t i, Time&) const =0;
398  virtual void value(size_t i, GYearMonth&) const =0;
399  virtual void value(size_t i, GYear&) const =0;
400  virtual void value(size_t i, GMonth&) const =0;
401  virtual void value(size_t i, GDay&) const =0;
402  virtual void value(size_t i, YearMonthDuration&) const =0;
403  virtual void value(size_t i, DayTimeDuration&) const =0;
404  virtual void value(size_t i, String&) const =0;
405  virtual void value(size_t i, Point&) const =0;
408 protected:
409  TupleIterator();
410  virtual ~TupleIterator();
411 private:
413  TupleIterator &operator=(const TupleIterator&);
414 };
415 
429 class MLDLL OutputSequence
430 {
431 public:
435  virtual void writeValue(int) =0;
436  virtual void writeValue(unsigned) =0;
437  virtual void writeValue(int64_t) =0;
438  virtual void writeValue(uint64_t) =0;
439  virtual void writeValue(float) =0;
440  virtual void writeValue(double) =0;
441  virtual void writeValue(Decimal) =0;
442  virtual void writeValue(DateTime) =0;
443  virtual void writeValue(Date) =0;
444  virtual void writeValue(Time) =0;
445  virtual void writeValue(GYearMonth) =0;
446  virtual void writeValue(GYear) =0;
447  virtual void writeValue(GMonth) =0;
448  virtual void writeValue(GDay) =0;
449  virtual void writeValue(YearMonthDuration) =0;
450  virtual void writeValue(DayTimeDuration) =0;
451  virtual void writeValue(const String&) =0;
452  virtual void writeValue(Point) =0;
453  virtual void writeValue(bool) =0;
481  virtual void startMap() =0;
485  virtual void writeMapKey(const char*) =0;
487  virtual void endMap() =0;
490 protected:
491  OutputSequence();
492  virtual ~OutputSequence();
493 private:
495  OutputSequence &operator=(const OutputSequence&);
496 };
497 
504 class MLDLL Encoder
505 {
506 public:
507  virtual void encode(const void*, size_t) =0;
508 
509  virtual void encode(int) =0;
510  virtual void encode(unsigned) =0;
511  virtual void encode(int64_t) =0;
512  virtual void encode(uint64_t) =0;
513  virtual void encode(float) =0;
514  virtual void encode(double) =0;
515  virtual void encode(Decimal) =0;
516  virtual void encode(DateTime) =0;
517  virtual void encode(Date) =0;
518  virtual void encode(Time) =0;
519  virtual void encode(GYearMonth) =0;
520  virtual void encode(GYear) =0;
521  virtual void encode(GMonth) =0;
522  virtual void encode(GDay) =0;
523  virtual void encode(YearMonthDuration) =0;
524  virtual void encode(DayTimeDuration) =0;
525  virtual void encode(const String&) =0;
526  virtual void encode(Point) =0;
527  virtual void encode(bool) =0;
528 
529 protected:
530  Encoder();
531  virtual ~Encoder();
532 private:
533  Encoder(const Encoder&);
534  Encoder &operator=(const Encoder&);
535 };
536 
543 class MLDLL Decoder
544 {
545 public:
546  virtual void decode(const void*&, size_t&) =0;
547  virtual void decode(void*, size_t) =0;
548 
549  virtual void decode(int&) =0;
550  virtual void decode(unsigned&) =0;
551  virtual void decode(int64_t&) =0;
552  virtual void decode(uint64_t&) =0;
553  virtual void decode(float&) =0;
554  virtual void decode(double&) =0;
555  virtual void decode(Decimal&) =0;
556  virtual void decode(DateTime&) =0;
557  virtual void decode(Date&) =0;
558  virtual void decode(Time&) =0;
559  virtual void decode(GYearMonth&) =0;
560  virtual void decode(GYear&) =0;
561  virtual void decode(GMonth&) =0;
562  virtual void decode(GDay&) =0;
563  virtual void decode(YearMonthDuration&) =0;
564  virtual void decode(DayTimeDuration&) =0;
565  virtual void decode(String&) =0;
566  virtual void decode(Point&) =0;
567  virtual void decode(bool&) =0;
568 
569 protected:
570  Decoder();
571  virtual ~Decoder();
572 private:
573  Decoder(const Decoder&);
574  Decoder &operator=(const Decoder&);
575 };
576 
588 class MLDLL Reporter
589 {
590 public:
592  enum LogLevel {
593  None,
594  Finest,
595  Finer,
596  Fine,
597  Debug,
598  Config,
599  Info,
600  Notice,
601  Warning,
602  Error,
603  Critical,
604  Alert,
605  Emergency
606  };
607 
612  virtual LogLevel logLevel() const =0;
614  virtual void log(LogLevel level, const char* message) =0;
621  virtual void error(const char* message) =0;
622 
623 protected:
624  Reporter();
625  virtual ~Reporter();
626 private:
627  Reporter(const Reporter&);
628  Reporter &operator=(const Reporter&);
629 };
630 
632 class MLDLL Item
633 {
634 public:
642  enum Type {
643  // Atomic types
644  INT,
663 
664  // QNAME,
665  // NOTATION,
666  // DURATION,
667  // G_MONTH_DAY,
668  // BASE_64_BINARY,
669  // HEX_BINARY,
670  // UNTYPED_ATOMIC,
671 
672  // MarkLogic types
674  MAP,
675 
676  // BOX,
677  // CIRCLE,
678  // POLYGON,
679  // LINESTRING,
680  // COMPLEX_POLYGON,
681  // ARRAY,
682 
683  // // Nodes
684  // DOCUMENT,
685  // ELEMENT,
686  // ATTRIBUTE,
687  // TEXT,
688  // PROCESSING_INSTRUCTION,
689  // COMMENT,
690  // NAMESPACE,
691  // BINARY,
692 
693  // FUNCTION,
694 
695  OTHER
696  };
697 };
698 
709 class MLDLL Sequence
710 {
711 public:
712  Sequence(SequenceImpl* =0);
713  Sequence(const Sequence&);
714  Sequence& operator=(const Sequence&);
715  ~Sequence();
716 
718  operator bool() const { return seq!=0; }
719 
723  void next();
725  bool done() const;
726 
728  Item::Type type() const;
732  uint64_t frequency() const;
733 
737  void value(int&) const;
738  void value(unsigned&) const;
739  void value(int64_t&) const;
740  void value(uint64_t&) const;
741  void value(float&) const;
742  void value(double&) const;
743  void value(Decimal&) const;
744  void value(DateTime&) const;
745  void value(Date&) const;
746  void value(Time&) const;
747  void value(GYearMonth&) const;
748  void value(GYear&) const;
749  void value(GMonth&) const;
750  void value(GDay&) const;
751  void value(YearMonthDuration&) const;
752  void value(DayTimeDuration&) const;
753  void value(String&) const;
754  void value(bool&) const;
755 
756  void value(Point&) const;
757  void value(Map&) const;
760 private:
761  SequenceImpl* seq;
762 };
763 
765 class MLDLL Map
766 {
767 public:
768  Map(MapImpl* =0);
769  Map(const Map&);
770  Map& operator=(const Map&);
771  ~Map();
772 
774  operator bool() const { return map!=0; }
775 
777  Sequence get(const char* key) const;
778 
779 private:
780  MapImpl* map;
781 };
782 
814 class MLDLL AggregateUDF
815 {
816 public:
817  // Management methods
830  virtual AggregateUDF* clone() const =0;
836  virtual void close() =0;
837 
850  virtual void start(Sequence& arg, Reporter& r) =0;
862  virtual void finish(OutputSequence& os, Reporter& r) =0;
863 
864  // Map/reduce methods
876  virtual void map(TupleIterator& values, Reporter& r) =0;
892  virtual void reduce(const AggregateUDF* o, Reporter& r) =0;
893 
894  // Serialize/deserialize
906  virtual void encode(Encoder& e, Reporter& r) =0;
918  virtual void decode(Decoder& d, Reporter& r) =0;
919 
928  virtual RangeIndex::Order getOrder() const;
929 
930 protected:
931  // Detect DLLs compiled against a different API version
945  AggregateUDF(unsigned version = MARKLOGIC_API_VERSION);
946  virtual ~AggregateUDF();
947 };
948 
960 typedef AggregateUDF*(*AggregateFunction)();
961 
985 class MLDLL Registry
986 {
987 public:
1004  void version(unsigned pluginVersion = makeVersion(__DATE__,__TIME__),
1005  unsigned marklogicVersion = MARKLOGIC_API_VERSION);
1006 
1023  template<class T> void registerAggregate(const char* name);
1043  virtual void registerAggregate(const char* name, AggregateFunction f) =0;
1044 
1045 protected:
1046  Registry();
1047  virtual ~Registry();
1048 private:
1049  Registry(const Registry&);
1050  Registry &operator=(const Registry&);
1051  static unsigned makeVersion(const char*,const char*);
1052 protected:
1053  unsigned pluginVersion;
1054 };
1055 
1056 template<class T>
1057 inline AggregateUDF*
1058 construct()
1059 {
1060  return new T();
1061 }
1062 
1063 template<class T>
1064 inline void Registry::
1065 registerAggregate(const char* name)
1066 {
1067  registerAggregate(name, marklogic::construct<T>);
1068 }
1069 
1070 }
1071 
1072 #endif
Encapsulation of XQuery sequence item value type.
Definition: MarkLogic.h:632
xs:gYearMonth
Definition: MarkLogic.h:654
C++ representation of the XQuery type xs:decimal.
Definition: MarkLogic.h:182
Encapsulation of a User Defined Function for performing aggregate analysis across co-occurrences in r...
Definition: MarkLogic.h:814
xs:gDay
Definition: MarkLogic.h:657
xs:gMonth
Definition: MarkLogic.h:656
xs:unsignedLong
Definition: MarkLogic.h:647
C++ representation of the XQuery type xs:gYear.
Definition: MarkLogic.h:222
xs:date
Definition: MarkLogic.h:653
Order
Whether the index values are in ascending or descending order.
Definition: MarkLogic.h:92
Serialize values.
Definition: MarkLogic.h:504
C++ representation of the MarkLogic XQuery cts:point.
Definition: MarkLogic.h:291
Type
The type of the values in a range index.
Definition: MarkLogic.h:69
Definition: MarkLogic.h:134
C++ representation of the XQuery type xs:time.
Definition: MarkLogic.h:206
A sequence of values produced by your AggregateUDF::finish implementation.
Definition: MarkLogic.h:429
xs:string
Definition: MarkLogic.h:86
xs:gYearMonth
Definition: MarkLogic.h:80
Type
The types of item values that can occur in a Sequence.
Definition: MarkLogic.h:642
xs:int
Definition: MarkLogic.h:644
C++ representation of the XQuery type xs:dateTime.
Definition: MarkLogic.h:190
cts:point (MarkLogic XQuery dialect)
Definition: MarkLogic.h:673
xs:time
Definition: MarkLogic.h:652
xs:long
Definition: MarkLogic.h:646
void registerAggregate(const char *name)
Register an AggregateUDF implementation with MarkLogic Server.
Definition: MarkLogic.h:1065
C++ representation of the XQuery type xs:gYearMonth.
Definition: MarkLogic.h:214
xs:time
Definition: MarkLogic.h:78
xs:float
Definition: MarkLogic.h:74
LogLevel
Available log levels.
Definition: MarkLogic.h:592
A key-value map, equivalent to the MarkLogic XQuery type map:map.
Definition: MarkLogic.h:765
xs:float
Definition: MarkLogic.h:648
xs:yearMonthDuration
Definition: MarkLogic.h:84
Log messages and report errors to MarkLogic Server. You do not need to subclass this class...
Definition: MarkLogic.h:588
xs:date
Definition: MarkLogic.h:79
xs:unsignedInt
Definition: MarkLogic.h:645
Encapsulation of the configuration of a range index.
Definition: MarkLogic.h:58
xs:boolean
Definition: MarkLogic.h:662
xs:yearMonthDuration
Definition: MarkLogic.h:658
xs:int
Definition: MarkLogic.h:70
xs:gMonth
Definition: MarkLogic.h:82
C++ representation of the XQuery type xs:dayTimeDuration.
Definition: MarkLogic.h:254
Definition: MarkLogic.h:99
C++ representation of the XQuery type xs:string, encapsulating a string value with its collation...
Definition: MarkLogic.h:263
xs:anyURI
Definition: MarkLogic.h:661
xs:anyURI
Definition: MarkLogic.h:87
xs:double
Definition: MarkLogic.h:649
The MarkLogic Server native plugin registry.
Definition: MarkLogic.h:985
xs:decimal
Definition: MarkLogic.h:76
A sequence of Item values.
Definition: MarkLogic.h:709
Iterator over a sequence of N-way co-occurrences of range index values from a single stand...
Definition: MarkLogic.h:339
xs:dayTimeDuration
Definition: MarkLogic.h:85
xs:gYear
Definition: MarkLogic.h:655
C++ representation of the XQuery type xs:gMonth.
Definition: MarkLogic.h:230
map:map (MarkLogic XQuery dialect)
Definition: MarkLogic.h:674
xs:decimal
Definition: MarkLogic.h:650
xs:double
Definition: MarkLogic.h:75
C++ representation of the XQuery type xs:date.
Definition: MarkLogic.h:198
C++ representation of the XQuery type xs:gDay.
Definition: MarkLogic.h:238
xs:gYear
Definition: MarkLogic.h:81
xs:dateTime
Definition: MarkLogic.h:77
xs:gDay
Definition: MarkLogic.h:83
xs:unsignedInt
Definition: MarkLogic.h:71
xs:string
Definition: MarkLogic.h:660
xs:long
Definition: MarkLogic.h:72
Definition: MarkLogic.h:148
xs:dateTime
Definition: MarkLogic.h:651
C++ representation of the XQuery type xs:yearMonthDuration.
Definition: MarkLogic.h:246
xs:unsignedLong
Definition: MarkLogic.h:73
De-serialize values.
Definition: MarkLogic.h:543
Definition: MarkLogic.h:162
xs:dayTimeDuration
Definition: MarkLogic.h:659