ElementPath.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. "use strict";
  2. var FieldRef = require('./FieldRef');
  3. // Autogenerated by cport.py on 2013-09-17 14:37
  4. var ElementPath = module.exports = function ElementPath(){
  5. this._fieldRef = new FieldRef();
  6. this.shouldTraverseLeafArray = false;
  7. }, klass = ElementPath, base = Object , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
  8. // File: path.h lines: 41-41
  9. // FieldRef _fieldRef;
  10. proto._fieldRef = undefined;
  11. // File: path.h lines: 42-42
  12. // bool _shouldTraverseLeafArray;
  13. proto._shouldTraverseLeafArray = undefined;
  14. /**
  15. * getFieldDottedOrArray
  16. *
  17. * @method getFieldDottedArray
  18. * @param doc
  19. * @param path
  20. * @param idxPathObj This is an object with a pathID element. This allows for pass by ref in calling function.
  21. * */
  22. klass.getFieldDottedOrArray = function getFieldDottedOrArray(doc, path, idxPathObj){
  23. // File path_internal.cpp lines 31-72
  24. if (path.numParts() === 0 ) { return doc.getField(""); }
  25. var res,curr = doc,
  26. stop = false,
  27. partNum = 0;
  28. while (partNum < path.numParts() && !stop) {
  29. res = curr.getField( path.getPart( partNum) );
  30. if(res instanceof EOO){
  31. stop = true;
  32. } else if (res instanceof Object) {
  33. curr = res;
  34. partNum++;
  35. } else if (res instanceof Array) {
  36. stop = true;
  37. } else {
  38. if (partNum + 1 < path.numParts() ) {
  39. res = {};
  40. }
  41. stope = true;
  42. }
  43. }
  44. idxPath.pathID = partNum;
  45. return res;
  46. };
  47. /**
  48. * isAllDigits does what it says on the tin.
  49. *
  50. * @method isAllDigits
  51. * @param str
  52. */
  53. klass.isAllDigits = function isAllDigits ( str ){
  54. // File path_internal.cpp lines 23-29
  55. digitCheck = /\D/g;
  56. if (digitCheck.exec(str) === null){ return true; }
  57. return false;
  58. };
  59. /**
  60. *
  61. * This documentation was automatically generated. Please update when you touch this function.
  62. * @method fieldRef
  63. * @param
  64. *
  65. */
  66. proto.fieldRef = function fieldRef( /* */ ){
  67. // File: path.h lines: 37-36
  68. return this._fieldRef;
  69. };
  70. /**
  71. *
  72. * This documentation was automatically generated. Please update when you touch this function.
  73. * @method init
  74. * @param
  75. *
  76. */
  77. proto.init = function init( path ){ // const StringData& path
  78. // File: path.cpp lines: 26-29
  79. this._shouldTraverseLeafArray = true;
  80. this._fieldRef.parse( path );
  81. return {'code':'OK'};
  82. };
  83. /**
  84. *
  85. * This documentation was automatically generated. Please update when you touch this function.
  86. * @method setTraverseLeafArray
  87. * @param
  88. *
  89. */
  90. proto.setTraverseLeafArray = function setTraverseLeafArray( b ){ // bool b
  91. // File: path.h lines: 35-34
  92. this._shouldTraverseLeafArray = b;
  93. };
  94. /**
  95. *
  96. * This documentation was automatically generated. Please update when you touch this function.
  97. * @method shouldTraverseLeafArray
  98. * @param
  99. *
  100. */
  101. proto.shouldTraverseLeafArray = function shouldTraverseLeafArray( /* */ ){
  102. // File: path.h lines: 38-37
  103. return this._shouldTraverseLeafArray;
  104. };
  105. klass.objAtPath = function objAtPath( doc,path) {
  106. debugger;
  107. if(path.length == 0) {
  108. debugger;
  109. return doc;
  110. }
  111. if (path.length > 0 && Object.keys(doc).length == 0){
  112. debugger;
  113. return {};
  114. }
  115. if (doc === null || doc === undefined) {
  116. debugger;
  117. return doc;
  118. }
  119. var tpath = path.split('.');
  120. debugger;
  121. return klass.objAtPath(doc[tpath[0]],tpath.slice(1).join('.'));
  122. };