Skip to content

Instantly share code, notes, and snippets.

@isc-bspead
Last active December 21, 2016 08:00
Show Gist options
  • Save isc-bspead/bf23a28029e8d389ac39a3a4af3342bd to your computer and use it in GitHub Desktop.
Save isc-bspead/bf23a28029e8d389ac39a3a4af3342bd to your computer and use it in GitHub Desktop.
Macros for writing forward compatible JSON code in InterSystems Caché 2016.1
#include %occReference
#if $$$comClassDefined("%Library.Object")
#define jsonClassIsLatestVersion $classIsLatestVersion
//usage: obj.$$$jsonClassIsLatestVersion()
#define jsonExtends $extends
//usage: {}.$$$jsonExtends(classname)
#define jsonFromJSON $fromJSON
//usage: {}.$$$jsonFromJSON(string)
#define jsonGetIterator $getIterator
//usage: obj.$$$jsonGetIterator()
#define jsonGetNext $getNext
//usage: iterator.$$$jsonGetNext(.key, .value)
#define jsonIsA $isA
//usage: obj.$$$jsonIsA(classname)
#define jsonToJSON $toJSON
//usage: obj.$$$jsonToJSON()
#define jsonGet $get
//usage: obj.$$$jsonGet(key)
#define jsonIsDefined $isDefined
//usage: obj.$$$jsonIsDefined(key)
#define jsonRemove $remove
//usage: obj.$$$jsonRemove(key)
#define jsonSet $set
//usage: obj.$$$jsonSet(key, val)
#define jsonSize $size
// usage: obj.$$$jsonSize()
#define jsonPop $pop
//usage: obj.$$$jsonPop()
#define jsonPush $push
//usage: obj.$$$jsonPush(val)
#define jsonAbstractClass %Library.AbstractObject
#define jsonObjectClass %Library.Object
#define jsonArrayClass %Library.Array
#else
#define jsonClassIsLatestVersion %ClassIsLatestVersion
//usage: obj.$$$jsonClassIsLatestVersion()
#define jsonExtends %Extends
//usage: {}.$$$jsonExtends(classname)
#define jsonFromJSON %FromJSON
//usage: {}.$$$jsonFromJSON(string)
#define jsonGetIterator %GetIterator
//usage: obj.$$$jsonGetIterator()
#define jsonGetNext %GetNext
//usage: iterator.$$$jsonGetNext(.key, .value)
#define jsonIsA %IsA
//usage: obj.$$$jsonIsA(className)
#define jsonToJSON %ToJSON
//usage: obj.$$$jsonToJSON()
#define jsonGet %Get
//usage: obj.$$$jsonGet(key)
#define jsonIsDefined %IsDefined
//usage: obj.$$$jsonIsDefined(key)
#define jsonRemove %Remove
//usage: obj.$$$jsonRemove(key)
#define jsonSet %Set
//usage: obj.$$$jsonSet(key, val)
#define jsonSize %Size
//usage: obj.$$$jsonSize()
#define jsonPop %Pop
//usage: obj.$$$jsonPop()
#define jsonPush %Push
//usage: obj.$$$jsonPush(val)
#define jsonAbstractClass %Library.AbstractDynamicObject
#define jsonObjectClass %Library.DynamicObject
#define jsonArrayClass %Library.DynamicArray
#endif
#def1arg jsonIsAbstract %IsA(##Quote($$$jsonAbstractClass))
//usage: obj.$$$jsonIsAbstract
#def1arg jsonIsObject %IsA(##Quote($$$jsonObjectClass))
//usage: obj.$$$jsonIsObject
#def1arg jsonIsArray %IsA(##Quote($$$jsonArrayClass))
//usage: obj.$$$jsonIsArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment