Browse Source

EAGLESIX-2651: expr: minor OO fixes and docs

Kyle P Davis 11 years ago
parent
commit
d6f6b1fa3e

+ 3 - 4
lib/pipeline/expressions/ConstantExpression.js

@@ -1,8 +1,5 @@
 "use strict";
 "use strict";
 
 
-var Value = require("../Value"),
-    Expression = require("./Expression");
-
 /**
 /**
  * Internal expression for constant values
  * Internal expression for constant values
  * @class ConstantExpression
  * @class ConstantExpression
@@ -14,7 +11,9 @@ var ConstantExpression = module.exports = function ConstantExpression(value){
     if (arguments.length !== 1) throw new Error(klass.name + ": args expected: value");
     if (arguments.length !== 1) throw new Error(klass.name + ": args expected: value");
     this.value = value;
     this.value = value;
     base.call(this);
     base.call(this);
-}, klass = ConstantExpression, base = require("./FixedArityExpressionT")(klass,1), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+}, klass = ConstantExpression, base = require("./FixedArityExpressionT")(ConstantExpression, 1), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+
+var Expression = require("./Expression");
 
 
 klass.parse = function parse(exprElement, vps) {
 klass.parse = function parse(exprElement, vps) {
 	return new ConstantExpression(exprElement);
 	return new ConstantExpression(exprElement);

+ 1 - 1
lib/pipeline/expressions/Expression.js

@@ -15,7 +15,7 @@
  */
  */
 var Expression = module.exports = function Expression() {
 var Expression = module.exports = function Expression() {
 	if (arguments.length !== 0) throw new Error("zero args expected");
 	if (arguments.length !== 0) throw new Error("zero args expected");
-}, klass = Expression, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
+}, klass = Expression, proto = klass.prototype;
 
 
 
 
 var Value = require("../Value"),
 var Value = require("../Value"),

+ 6 - 7
lib/pipeline/expressions/FixedArityExpressionT.js

@@ -6,8 +6,7 @@
  * @namespace mungedb-aggregate.pipeline.expressions
  * @namespace mungedb-aggregate.pipeline.expressions
  * @module mungedb-aggregate
  * @module mungedb-aggregate
  * @constructor
  * @constructor
- **/
-
+ */
 var FixedArityExpressionT = module.exports = function FixedArityExpressionT(SubClass, nArgs) {
 var FixedArityExpressionT = module.exports = function FixedArityExpressionT(SubClass, nArgs) {
 
 
 	var FixedArityExpression = function FixedArityExpression() {
 	var FixedArityExpression = function FixedArityExpression() {
@@ -15,12 +14,16 @@ var FixedArityExpressionT = module.exports = function FixedArityExpressionT(SubC
 		base.call(this);
 		base.call(this);
 	}, klass = FixedArityExpression, base = require("./NaryBaseExpressionT")(SubClass), proto = klass.prototype = Object.create(base.prototype, {constructor: {value: klass}});
 	}, klass = FixedArityExpression, base = require("./NaryBaseExpressionT")(SubClass), proto = klass.prototype = Object.create(base.prototype, {constructor: {value: klass}});
 
 
+	//NOTE: attach statics to emulate the C++ behavior
+	for (var propName in base)
+		klass[propName] = base[propName];
+
 	/**
 	/**
 	 * Check that the number of args is what we expected
 	 * Check that the number of args is what we expected
 	 * @method validateArguments
 	 * @method validateArguments
 	 * @param args Array The array of arguments to the expression
 	 * @param args Array The array of arguments to the expression
 	 * @throws
 	 * @throws
-	 **/
+	 */
 	proto.validateArguments = function validateArguments(args) {
 	proto.validateArguments = function validateArguments(args) {
 		if(args.length !== nArgs) {
 		if(args.length !== nArgs) {
 			throw new Error("Expression " + this.getOpName() + " takes exactly " +
 			throw new Error("Expression " + this.getOpName() + " takes exactly " +
@@ -28,9 +31,5 @@ var FixedArityExpressionT = module.exports = function FixedArityExpressionT(SubC
 		}
 		}
 	};
 	};
 
 
-	klass.parse = base.parse; 						// NOTE: Need to explicitly
-	klass.parseArguments = base.parseArguments;		// bubble static members in
-													// our inheritance chain
 	return FixedArityExpression;
 	return FixedArityExpression;
 };
 };
-

+ 3 - 3
lib/pipeline/expressions/MultiplyExpression.js

@@ -2,14 +2,14 @@
 
 
 /**
 /**
  * A $multiply pipeline expression.
  * A $multiply pipeline expression.
- * @see evaluateInternal
  * @class MultiplyExpression
  * @class MultiplyExpression
+ * @extends mungedb-aggregate.pipeline.expressions.VariadicExpressionT
  * @namespace mungedb-aggregate.pipeline.expressions
  * @namespace mungedb-aggregate.pipeline.expressions
  * @module mungedb-aggregate
  * @module mungedb-aggregate
  * @constructor
  * @constructor
  */
  */
-var MultiplyExpression = module.exports = function MultiplyExpression(){
-if (arguments.length !== 0) throw new Error(klass.name + ": no args expected");
+var MultiplyExpression = module.exports = function MultiplyExpression() {
+	if (arguments.length !== 0) throw new Error(klass.name + ": no args expected");
 	base.call(this);
 	base.call(this);
 }, klass = MultiplyExpression, base = require("./VariadicExpressionT")(MultiplyExpression), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 }, klass = MultiplyExpression, base = require("./VariadicExpressionT")(MultiplyExpression), proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 

+ 5 - 4
lib/pipeline/expressions/NaryBaseExpressionT.js

@@ -3,9 +3,9 @@
 /**
 /**
  * Inherit from ExpressionVariadic or ExpressionFixedArity instead of directly from this class.
  * Inherit from ExpressionVariadic or ExpressionFixedArity instead of directly from this class.
  * @class NaryBaseExpressionT
  * @class NaryBaseExpressionT
+ * @extends mungedb-aggregate.pipeline.expressions.NaryExpression
  * @namespace mungedb-aggregate.pipeline.expressions
  * @namespace mungedb-aggregate.pipeline.expressions
  * @module mungedb-aggregate
  * @module mungedb-aggregate
- * @extends mungedb-aggregate.pipeline.expressions.NaryExpression
  * @constructor
  * @constructor
  */
  */
 var NaryBaseExpressionT = module.exports = function NaryBaseExpressionT(SubClass) {
 var NaryBaseExpressionT = module.exports = function NaryBaseExpressionT(SubClass) {
@@ -15,6 +15,10 @@ var NaryBaseExpressionT = module.exports = function NaryBaseExpressionT(SubClass
 		base.call(this);
 		base.call(this);
 	}, klass = NaryBaseExpression, NaryExpression = require("./NaryExpression"), base = NaryExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 	}, klass = NaryBaseExpression, NaryExpression = require("./NaryExpression"), base = NaryExpression, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 
+	//NOTE: attach statics to emulate the C++ behavior
+	for (var propName in base)
+		klass[propName] = base[propName];
+
 	klass.parse = function(objExpr, vps) {
 	klass.parse = function(objExpr, vps) {
 		var expr = new SubClass(),
 		var expr = new SubClass(),
 			args = NaryExpression.parseArguments(objExpr, vps);
 			args = NaryExpression.parseArguments(objExpr, vps);
@@ -23,8 +27,5 @@ var NaryBaseExpressionT = module.exports = function NaryBaseExpressionT(SubClass
 		return expr;
 		return expr;
 	};
 	};
 
 
-	klass.parseArguments = base.parseArguments;		// NOTE: Need to explicitly
-													// bubble static members in
-													// our inheritance chain
 	return NaryBaseExpression;
 	return NaryBaseExpression;
 };
 };

+ 1 - 1
lib/pipeline/expressions/NaryExpression.js

@@ -3,9 +3,9 @@
 /**
 /**
  * The base class for all n-ary `Expression`s
  * The base class for all n-ary `Expression`s
  * @class NaryExpression
  * @class NaryExpression
+ * @extends mungedb-aggregate.pipeline.expressions.Expression
  * @namespace mungedb-aggregate.pipeline.expressions
  * @namespace mungedb-aggregate.pipeline.expressions
  * @module mungedb-aggregate
  * @module mungedb-aggregate
- * @extends mungedb-aggregate.pipeline.expressions.Expression
  * @constructor
  * @constructor
  */
  */
 var NaryExpression = module.exports = function NaryExpression() {
 var NaryExpression = module.exports = function NaryExpression() {

+ 6 - 5
lib/pipeline/expressions/VariadicExpressionT.js

@@ -3,11 +3,11 @@
 /**
 /**
  * A factory and base class for all expressions that are variadic (AKA they accept any number of arguments)
  * A factory and base class for all expressions that are variadic (AKA they accept any number of arguments)
  * @class VariadicExpressionT
  * @class VariadicExpressionT
+ * @extends mungedb-aggregate.pipeline.expressions.NaryBaseExpressionT
  * @namespace mungedb-aggregate.pipeline.expressions
  * @namespace mungedb-aggregate.pipeline.expressions
  * @module mungedb-aggregate
  * @module mungedb-aggregate
  * @constructor
  * @constructor
- **/
-
+ */
 var VariadicExpressionT = module.exports = function VariadicExpressionT(SubClass) {
 var VariadicExpressionT = module.exports = function VariadicExpressionT(SubClass) {
 
 
 	var VariadicExpression = function VariadicExpression() {
 	var VariadicExpression = function VariadicExpression() {
@@ -15,8 +15,9 @@ var VariadicExpressionT = module.exports = function VariadicExpressionT(SubClass
 		base.call(this);
 		base.call(this);
 	}, klass = VariadicExpression, base = require("./NaryBaseExpressionT")(SubClass), proto = klass.prototype = Object.create(base.prototype, {constructor: {value: klass}});
 	}, klass = VariadicExpression, base = require("./NaryBaseExpressionT")(SubClass), proto = klass.prototype = Object.create(base.prototype, {constructor: {value: klass}});
 
 
-	klass.parse = base.parse; 						// NOTE: Need to explicitly
-	klass.parseArguments = base.parseArguments;		// bubble static members in
-													// our inheritance chain
+	//NOTE: attach statics to emulate the C++ behavior
+	for (var propName in base)
+		klass[propName] = base[propName];
+
 	return VariadicExpression;
 	return VariadicExpression;
 };
 };