1 /* 2 * Copyright 2015-2018 HuntLabs.cn 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 module hunt.sql.visitor.VisitorFeature; 17 18 struct VisitorFeature { 19 enum VisitorFeature OutputUCase = VisitorFeature(0); 20 enum VisitorFeature OutputPrettyFormat = VisitorFeature(1); 21 enum VisitorFeature OutputParameterized = VisitorFeature(2); 22 enum VisitorFeature OutputDesensitize = VisitorFeature(3); 23 enum VisitorFeature OutputUseInsertValueClauseOriginalString = VisitorFeature(4); 24 enum VisitorFeature OutputSkipSelectListCacheString = VisitorFeature(5); 25 enum VisitorFeature OutputSkipInsertColumnsString = VisitorFeature(6); 26 enum VisitorFeature OutputParameterizedQuesUnMergeInList = VisitorFeature(7); 27 enum VisitorFeature OutputParameterizedQuesUnMergeOr = VisitorFeature(8); 28 enum VisitorFeature OutputKeepParenthesisWhenNotExpr = VisitorFeature(9); 29 enum VisitorFeature OutputQuotedIdentifier = VisitorFeature(10); 30 31 private this(int ord){ 32 mask = (1 << ord); 33 } 34 35 int mask; 36 37 38 static bool isEnabled(int features, VisitorFeature feature) { 39 return (features & feature.mask) != 0; 40 } 41 42 static int config(int features, VisitorFeature feature, bool state) { 43 if (state) { 44 features |= feature.mask; 45 } else { 46 features &= ~feature.mask; 47 } 48 49 return features; 50 } 51 52 static int of(VisitorFeature[] features...) { 53 if (features is null) { 54 return 0; 55 } 56 57 int value = 0; 58 59 foreach (VisitorFeature feature; features) { 60 value |= feature.mask; 61 } 62 63 return value; 64 } 65 66 bool opEquals(const VisitorFeature h) nothrow { 67 return mask == h.mask ; 68 } 69 70 bool opEquals(ref const VisitorFeature h) nothrow { 71 return mask == h.mask ; 72 } 73 }