/// <summary>Initializes a slice.</summary> /// <exception cref="ArgumentException">The start index was below zero.</exception> /// <remarks>The (start, count) range is allowed to be invalid, as long /// as 'start' and 'count' are zero or above. /// <ul> /// <li>If 'start' is above the original Count, the Count of the new slice /// is set to zero.</li> /// <li>if (start + count) is above the original Count, the Count of the new /// slice is reduced to <c>list.Count - start</c>.</li> /// </ul> /// </remarks> public ROLSlice(TList list, int start, int count = int.MaxValue) { _list = list; _start = start; _count = count; _count = CheckParam.ThrowIfStartOrCountAreBelowZeroAndLimitCountIfNecessary(start, count, list.Count); }
public StdIdNode(Symbol name, SourceRange range, NodeStyle style = NodeStyle.Default) : base(range, style) { if ((_name = name) == null) { CheckParam.ThrowBadArgument("Cannot set IdNode.Name to null."); } }
public void Print(IEnumerable <ILNode> nodes, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null) { CheckParam.IsNotNull("target", target); var p = new Les3Printer(target, sink, options); p.Print(nodes); }
private static void Sort <T>(this IList <T> list, int index, int count, Comparison <T> comp, int[] indexes, int quickSelectElems = int.MaxValue) { CheckParam.IsInRange("index", index, 0, list.Count); CheckParam.IsInRange("count", count, 0, list.Count - index); SortCore(list, index, count, comp, indexes, quickSelectElems); }
public void SetTag(Symbol key, ValueT val) { if (key == null) { CheckParam.ThrowBadArgument("SetTag: key is null"); } int count = Count; KeyValuePair <Symbol, ValueT> kvp; // Try the last-accessed entry int hint = UserByte; if (hint < count) { if ((kvp = GetAtDff(hint)).Key == key) { SetAt(hint, new KeyValuePair <Symbol, ValueT>(key, val)); return; } } // Try the other entries for (int i = 0; i < count; i++) { if (i != hint && (kvp = GetAtDff(hint)).Key == key) { UserByte = (byte)i; SetAt(i, new KeyValuePair <Symbol, ValueT>(key, val)); return; } } Add(new KeyValuePair <Symbol, ValueT>(key, val)); }
public void ClearSpace(int index, int count = 1) { CheckParam.IsNotNegative("count", count); AutoThrow(); int end = checked (index + count); if (end > Count) { CheckParam.IsNotNegative("index", index); // this is also checked by DoSparseOperation if (index >= Count) { InsertSpace(Count, end - Count); return; } else { InsertSpace(Count, end - Count); } } if (count == 0) { return; } var op = new AListSparseOperation <T>((uint)index, false, true, count, _observer); DoSparseOperation(ref op); }
public StdIdNode(Symbol name, LNode ras) : base(ras) { if ((_name = name) == null) { CheckParam.ThrowBadArgument("Cannot set IdNode.Name to null."); } }
/// <summary> /// RetrieveMultiple method override optimized for FetchExpression. Returns all pages using callback or 'yield' iterator /// </summary> /// <param name="query">A query that determines the set of record</param> /// <param name="callback">Optional function to be called for each record page</param> /// <returns>Entity set as 'yield' iterator</returns> public static IEnumerable <Entity> RetrieveMultiple(this IOrganizationService service, FetchExpression query, Action <EntityCollection> callback = null) { CheckParam.CheckForNull(query, nameof(query)); EntityCollection collection = new EntityCollection { MoreRecords = true }; /// For performance reasons it's better to load XML once XDocument document = XDocument.Parse(query.Query); while (collection.MoreRecords) { /// Paging start working if Page > 1 query.NextPage(document, collection.PagingCookie); collection = service.RetrieveMultiple(query); callback?.Invoke(collection); foreach (Entity entity in collection.Entities) { yield return(entity); } } }
/// <summary> /// Simplifies getting values from Entity.FormattedValues collection /// <param name="attributeLogicalName">Attribute name</param> /// <returns>Attribute formated value</returns> public static String GetFormatedValue(this Entity entity, String attributeLogicalName) { CheckParam.CheckForNull(attributeLogicalName, nameof(attributeLogicalName)); entity.FormattedValues.TryGetValue(attributeLogicalName, out string outValue); return(outValue); }
public void Add(ulong key, TValue value) { if (!TryAdd(key, value)) { CheckParam.ThrowBadArgument(nameof(key), "Key already exists: {0}", key); } }
public void CopyTo(TKey [] array, int index) { if (array == null) { CheckParam.ThrowArgumentNull(nameof(array)); } if (index < 0) { CheckParam.ThrowOutOfRange(nameof(index)); } // we want no exception for index==array.Length && dictionary.Count == 0 if (index > array.Length) { CheckParam.ThrowBadArgument("index larger than largest valid index of array"); } if (array.Length - index < dictionary.Count) { CheckParam.ThrowBadArgument("Destination array cannot hold the requested elements!"); } foreach (TKey k in this) { array [index++] = k; } }
public MacroInfo(Symbol @namespace, LexicalMacroAttribute a, LexicalMacro macro, bool deprecateAllNames = false) : base(a.Syntax, a.Description, a.Names) { DeprecatedNames = a.DeprecatedNames; DeprecationMessage = a.DeprecationMessage; if (Names.Length == 0 && (a.DeprecatedNames == null || a.DeprecatedNames.Length == 0) && (a.Mode & (MacroMode.MatchEveryCall | MacroMode.MatchEveryLiteral | MacroMode.MatchEveryIdentifier)) == 0) { Names = new string[1] { macro.Method.Name } } ; if (deprecateAllNames) { DeprecatedNames = (DeprecatedNames ?? EmptyArray <string> .Value).Union(Names).ToArray(); } CheckParam.IsNotNull("macro", macro); Namespace = @namespace; Macro = macro; Mode = a.Mode; }
void IDictionary <Symbol, ValueT> .Add(Symbol key, ValueT value) { if (HasTag(key)) { CheckParam.ThrowBadArgument(nameof(key), "The key '{0}' already exists in the IDictionary", key.Name); } SetTag(key, value); }
public MacroInfo(Symbol @namespace, LexicalMacroAttribute a, LexicalMacro macro) : base(a.Syntax, a.Description, a.Names != null && a.Names.Length > 0 ? a.Names : new[] { macro.Method.Name }) { CheckParam.IsNotNull("macro", macro); Namespace = @namespace; Macro = macro; Mode = a.Mode; }
/// <inheritdoc cref="Log2Floor(int)"/> public static int Log2Floor(long x) { if (x < 0) { CheckParam.ThrowOutOfRange(nameof(x), "Log2Floor({0}) called", x); } return(Log2Floor((ulong)x)); }
/// <summary>Adds the specified item to the set, or throws an exception if /// a matching item is already present.</summary> /// <exception cref="ArgumentException">The item already exists in the set.</exception> public void AddUnique(T item) { if (_set.Add(ref item, _comparer, false)) { _count++; } CheckParam.ThrowBadArgument("The item already exists in the set."); }
public void CopyTo(T[] array, int arrayIndex) { if (_count > array.Length - arrayIndex) { CheckParam.ThrowBadArgument("CopyTo: Insufficient space in supplied array"); } _set.CopyTo(array, arrayIndex); }
/// <summary>Returns true if the specified child of the specified node /// can be an implicit child statement, i.e. a child statement that is /// not necessarily a braced block, e.g. the second child of a while /// loop.</summary> /// <remarks> /// This method helps the printer decide when a newline should be added /// before an unbraced child statement when there are no attributes /// dictating whether to add a newline or not. /// <para/> /// This method only cares about executable parent nodes. It returns /// false for class/space and function/property bodies, which are always /// braced blocks and therefore get a newline before every child statement /// automatically. /// </remarks> public static bool MayBeImplicitChildStatement(LNode node, int childIndex) { CheckParam.IsNotNull("node", node); if (childIndex < 0) // target or attributes { return(false); } var n = node.Name; if (!LNode.IsSpecialName(n.Name)) { return(false); } if (n == S.Braces) { return(true); } if (n == S.Try) { return(childIndex == 0); } switch (node.ArgCount) { case 1: if (n == S.Finally) { return(true); } break; case 2: if (childIndex == 0 ? n == S.DoWhile : n == S.If || n == S.While || n == S.UsingStmt || n == S.Lock || n == S.Switch || n == S.Fixed) { return(true); } break; case 3: if (childIndex != 0 && n == S.If) { return(true); } if (childIndex == 2 && n == S.ForEach) { return(true); } break; case 4: if (childIndex == 3 && (n == S.For || n == S.Catch)) { return(true); } break; } return(false); }
public void Add(string key, TValue value) { KeyWalker kw = StringToBytes(key); if (base.Set(ref kw, ref value, CPMode.Create)) { CheckParam.ThrowBadArgument(nameof(key), "Key already exists: {0}", key); } }
public virtual void Reset(IListSource <Token> tokens, ISourceFile file) { CheckParam.IsNotNull("tokens", tokens); CheckParam.IsNotNull("file", file); _tokensRoot = _tokens = tokens; _sourceFile = file; F = new LNodeFactory(file); InputPosition = 0; // reads LT(0) }
public SparseListSourceSlice <T, TList> Slice(int start, int count = int.MaxValue) { var slice = new SparseListSourceSlice <T, TList>(); slice._list = this._list; slice._start = this._start + start; slice._count = CheckParam.ThrowIfStartOrCountAreBelowZeroAndLimitCountIfNecessary(start, count, this._count); return(slice); }
public LNode Fn(LNode retType, LNode name, LNode argList, LNode body = null, int startIndex = -1, int endIndex = -1) { Debug.Assert(endIndex >= startIndex); CheckParam.Arg("argList", argList.Name == S.List || argList.Name == S.Missing); LNode[] list = body == null ? new[] { retType, name, argList } : new[] { retType, name, argList, body }; return(new StdSimpleCallNode(S.Fn, new RVList <LNode>(list), new SourceRange(_file, startIndex, endIndex - startIndex))); }
/// <inheritdoc cref="InternalSet{T}.IsProperSubsetOf(ISet{T}, int)"/> public void Add(KeyValuePair <K, V> item) { if (_set.Add(ref item, Comparer, false)) { _count++; return; } CheckParam.ThrowBadArgument("The specified key already exists in the map."); }
/// <summary>Adds the specified key-value pair to the trie, throwing an /// exception if the key is already present.</summary> public void Add(byte[] key, TValue value) { KeyWalker kw = new KeyWalker(key, key.Length); if (base.Set(ref kw, ref value, CPMode.Create)) { CheckParam.ThrowBadArgument(nameof(key), "Key already exists: {0}", key); } }
public LNode Property(LNode type, LNode name, LNode body = null, int startIndex = -1, int endIndex = -1) { Debug.Assert(endIndex >= startIndex); CheckParam.Arg("body", body.IsCall && (body.Name == S.Braces || (body.Name == S.Forward && body.Args.Count == 1))); LNode[] list = body == null ? new[] { type, name, } : new[] { type, name, body }; return(new StdSimpleCallNode(S.Property, new RVList <LNode>(list), new SourceRange(_file, startIndex, endIndex - startIndex))); }
public RunningEnv(MainForm mainForm) { CheckData = new CheckParam(); CheckingData = new CheckingParam(); LibraryData = new LibraryParam(); SettingData = new SettingParam(); UIContext = mainForm; EnvTimestamp = new DateTime(); }
public Num this[int index] { get { if ((uint)index >= (uint)_count) { CheckParam.ThrowOutOfRange("index", index, 0, _count - 1); } return(M.Add(_lo, M.From(index))); } }
/// <summary> /// Expands environment variables (e.g. %TEMP%) and @files in a list of /// command-line arguments, and adds any options of the form "--opt" or /// "--opt=value" to a dictionary. /// </summary> /// <param name="args">The original arguments to process.</param> /// <param name="options">Any long options (arguments that start with "--") /// will be added to this dictionary, and removed from <c>args</c>. This /// parameter cannot be null. /// By default, long options are not case sensitive. In that case, the /// user's option name is converted to lower case. /// <para/> /// Long options are expected to have the form --ID or --ID=value, where ID /// matches the regex "[a-zA-Z_0-9-]+". If there is no "=" or ":", that's /// okay too. For example, --Id{foo} is equivalent to --Id={foo}; both yield /// in the name-value pair ("id", "{foo}"). If there is no value (no equals /// or colon), the value associated with the option is null.</param> /// <param name="atFolder">If a parameter has the form @filename, the folder /// specified by atFolder will be searched for an options text file with the /// user-specified filename, and the contents of the file will be expanded /// into the list of arguments (split using SplitCommandLineArguments). The /// expanded list can contain new @filenames, which are also processed. To /// search in the current directory, use "". The @filename may use an absolute /// path, which overrides this folder. To disable @filename expansion, set /// this parameter to null. Whether the feature is enabled or disabled, /// @filenames are <i>not</i> removed from <c>args</c>, in case you want to /// be aware of the filenames afterward.</param> /// <param name="shortOptions">A map from one-letter options that start with /// "-" rather than "--", to the name of the corresponding long option (this /// option can be null to ignore all short options.) For example, if this /// contains (<c>'a', "all"</c>), and the input <c>args</c> contains "-a:foo", /// the pair ("all", "foo") will be added to <c>options</c>. If a value in /// this map is null, the key itself is used. Short options can be combined; /// for example <c>-abc:foo</c> is equivalent to <c>-a -b -c:foo</c>. Short /// options are always case-sensitive; to define an option that is not case /// sensitive, place two entries in the dictionary e.g. ('a', "all") and /// ('A', "all"). If the user specifies a short option letter that is not /// recognized, the entire command will be ignored and left in args. For /// example, if <c>shortOptions</c> contains only ('a', "all") but <c>args</c> /// contains "-ab=foo", the command is ignored and left in <c>args</c>. /// Rationale: -ab=foo might be a filename. /// <para/> /// On the other hand, if -a is a valid option then <c>-a123</c> is also /// valid even when there is no option called '1'; the number "123" is /// treated as an argument to -a. Now, if '1' is a registered short option /// but '2' is not, then <c>-a123</c> is equivalent to <c>-a -1=23</c>. /// </param> /// <param name="twoArgOptions">A set of options in which the argument can /// be separated by a space from the option. For example, if the input is /// "--out foo.txt" and you want to recognize "foo.txt" as the argument to /// "--out", add the string "out" to this set. If you want to treat <i>all</i> /// options this way, use <c>InvertibleSet{string}.All</c>. Note: /// If the input is "--out:foo bar", "foo" is recognized as the argument to /// "--out" and "bar" is left alone, i.e. it is treated as unrelated. /// Short options participate automatically. For example if "-f" means /// "--foo", and twoArgOptions contains "foo", then "-f arg" is interpreted /// like "--foo=arg". /// <para/> /// The argument will not be treated as an argument if it starts with a /// dash, e.g. in <c>--foo -*</c>, <c>-*</c> will not be treated as an /// argument to <c>--foo</c>, even if <c>-*</c> is not a registered option. /// </param> /// <param name="argLimit">A limit placed on the number of arguments when /// expanding @files. Such a file may refer to itself, and this is the only /// protection provided against infinite recursive expansion.</param> /// <param name="expandEnvVars">If true, environment variable references /// such as <c>%TEMP%</c> are expanded by calling the standard method /// <see cref="Environment.ExpandEnvironmentVariables"/>.</param> /// <param name="caseSensitiveLongOpts">If true, long options are case- /// sensitive. By default, long options are not case sensitive.</param> /// <remarks> /// Two types of options are recognized, short (-s) and long (--long), and /// only one argument is supported per option. The documentation is above. /// <para/> /// You can choose whether to permit duplicate options or not. If you use /// a standard <see cref="Dictionary{K,V}"/> to hold the options, an /// exception will occur when this method calls Add() to add the duplicate. /// The exception is caught, the first ocurrance is kept, and a warning /// message is printed to <see cref="MessageSink.Default"/>. /// <para/> /// To allow duplicates, store options in a different data structure such as /// <c>List(KeyValuePair(string, string))</c> or <c>BMultiMap(string,string)</c>. /// <para/> /// DOS-style slash-options like /foo are not supported. Since Windows /// recognizes the forward slash as a path separator, forward-slash options /// can be recognized as paths. If you want to recognize them as options /// instead, you can preprocess the argument list, replacing every command /// that starts with "/" with a "--" command: /// <code> /// for (int i = 0; args.Count > i; i++) /// if (args[i].StartsWith("/")) /// args[i] = "--" + args[i].Substring(1); /// </code> /// <para/> /// Globs (e.g. *.txt) are not recognized or expanded, but environment /// variables are expanded when <c>expandEnvVars</c> is true. /// <para/> /// Quote marks are not processed. An argument of <c>"--a"</c>, with quote /// marks, is not recognized as an option (these quote marks should be /// removed before calling this method, e.g. /// <see cref="G.SplitCommandLineArguments"/> handles this.) /// </remarks> public static void ProcessCommandLineArguments(IList <string> args, ICollection <KeyValuePair <string, string> > options, string atFolder, IDictionary <char, string> shortOptions = null, InvertibleSet <string> twoArgOptions = null, int argLimit = 0xFFFF, bool expandEnvVars = true, bool caseSensitiveLongOpts = false) { CheckParam.IsNotNull("args", args); CheckParam.IsNotNull("options", options); for (int i = 0; i < args.Count; i++) { ProcessArgument(args, i, options, atFolder, shortOptions, twoArgOptions, argLimit, expandEnvVars, caseSensitiveLongOpts); } args.RemoveAll(s => s == null); }
public void InsertSpace(int index, int count = 1) { CheckParam.IsNotNegative("count", count); //CheckParam.IsInRange("index", index, 0, Count); checked by DoSparseOperation AutoThrow(); var newCount = checked (Count + count); var op = new AListSparseOperation <T>((uint)index, true, true, count, _observer); DoSparseOperation(ref op); }
/// <summary>Reinitializes the object. This method is called by the constructor.</summary> /// <remarks>See the constructor for documentation of the parameters.</remarks> protected virtual void Reset(List list, Func <Token, Token> getEofToken, MatchType eof, ISourceFile file, int startIndex = 0) { CheckParam.IsNotNull <object>("list", list); _getEofToken = getEofToken; EOF = eof; _tokenList = list; _listCount = list.Count; // to avoid 1st-chance exceptions _sourceFile = file; InputPosition = startIndex; }
public IndicatorParam() { SlotNumber = 0; IsDefined = false; SlotType = SlotTypes.NotDefined; IndicatorName = String.Empty; IndicatorType = TypeOfIndicator.Indicator; ExecutionTime = ExecutionTime.DuringTheBar; IsDeafultGroupAll = false; IsAllowLTF = true; ListParam = new ListParam[5]; NumParam = new NumericParam[6]; CheckParam = new CheckParam[2]; for (int i = 0; i < 5; i++) ListParam[i] = new ListParam(); for (int i = 0; i < 6; i++) NumParam[i] = new NumericParam(); for (int i = 0; i < 2; i++) CheckParam[i] = new CheckParam(); }