Exemple #1
0
 public static void DoFormat <T> (RCVector <T> vector,
                                  StringBuilder builder,
                                  RCFormat args,
                                  RCColmap colmap,
                                  int level)
 {
     if (vector.Count == 0)
     {
         builder.Append("~");
         builder.Append(vector.TypeCode);
     }
     else
     {
         for (int i = 0; i < vector.Count; ++i)
         {
             vector.ScalarToString(builder, vector[i]);
             if (i < vector.Count - 1)
             {
                 builder.Append(" ");
             }
             else
             {
                 builder.Append(vector.Suffix);
             }
         }
     }
 }
Exemple #2
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            RCVector <T> cobj = obj as RCVector <T>;

            if (cobj == null)
            {
                return(false);
            }
            if (cobj.Count != Count)
            {
                return(false);
            }
            for (int i = 0; i < Count; ++i)
            {
                if (!ScalarEquals(this[i], cobj[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #3
0
        public static long[] DoRank <T> (SortDirection direction, RCVector <T> vector)
            where T : IComparable <T>
        {
            long[] indices = new long[vector.Count];
            for (long i = 0; i < indices.Length; ++i)
            {
                indices[i] = i;
            }
            RankState <T>     state = new RankState <T> (vector);
            Comparison <long> comparison;

            switch (direction)
            {
            case SortDirection.asc: comparison = new Comparison <long> (state.Asc); break;

            case SortDirection.desc: comparison = new Comparison <long> (state.Desc); break;

            case SortDirection.absasc: comparison = new Comparison <long> (state.AbsAsc); break;

            case SortDirection.absdesc: comparison = new Comparison <long> (state.AbsDesc); break;

            default: throw new Exception("Unknown SortDirection: " + direction.ToString());
            }
            Array.Sort(indices, comparison);
            return(indices);
        }
Exemple #4
0
        public RankState(RCVector <T> data)
        {
            _data = data;
            object abs = null;

            _absmap.TryGetValue(data.TypeCode, out abs);
            if (abs == null)
            {
                _abs = new AbsoluteValue <T> ();
            }
            else
            {
                _abs = (AbsoluteValue <T>)abs;
            }
        }
Exemple #5
0
 public static void WriteVectorDecimal(RCArray <byte> result, RCVector <decimal> vector)
 {
     result.Write((byte)vector.TypeCode);
     WriteVectorDecimal(result, vector.Data);
 }
Exemple #6
0
 public static void WriteVectorIncr(RCArray <byte> result, RCVector <RCIncrScalar> vector)
 {
     result.Write((byte)vector.TypeCode);
     WriteVectorIncr(result, vector.Data);
 }
Exemple #7
0
 public static void WriteVectorString(RCArray <byte> result, RCVector <string> vector)
 {
     result.Write((byte)vector.TypeCode);
     WriteVectorString(result, vector.Data);
 }
Exemple #8
0
 public static RCArray <int> ReadVector4(RCArray <byte> data, ref int start)
 {
     return(RCVector <int> .ReadVector(data, ref start, sizeof(int)));
 }
Exemple #9
0
        protected static RCString ExpandTemplate(StringBuilder builder,
                                                 RCTemplate template,
                                                 RCBlock right,
                                                 int I,
                                                 string parentIndent)
        {
            string indent = parentIndent;

            for (int i = 0; i < right.Count; ++i)
            {
                RCValue           child = right.Get(i);
                RCVector <string> text  = child as RCVector <string>;
                if (text == null)
                {
                    RCArray <string> strings     = new RCArray <string> (right.Count);
                    RCBlock          nestedBlock = (RCBlock)child;
                    for (int j = 0; j < nestedBlock.Count; ++j)
                    {
                        strings.Write(nestedBlock.GetString(j));
                    }
                    text = new RCString(strings);
                    // ExpandTemplate (builder, template, (RCBlock) child, I + i, indent);
                }
                // else
                {
                    bool somethingAdded = false;
                    for (int j = 0; j < text.Count; ++j)
                    {
                        string section = text[j];
                        int    start   = 0;
                        int    lineNum = 0;
                        for (int k = 0; k < section.Length; ++k)
                        {
                            if (section[k] == '\n')
                            {
                                string line;
                                if (i % 2 == 1)
                                {
                                    if (k > 0 && section.Length > 0 && section[k - 1] == '\r')
                                    {
                                        line = section.Substring(start, k - start - 1);
                                    }
                                    else
                                    {
                                        line = section.Substring(start, k - start);
                                    }
                                    // if (j > 0 || start > 0)
                                    // Using j and start here didn't work because sometimes empty strings
                                    // are added. Instead keep track of whether a line has been added.
                                    // We may need this variable to handle other cases as well, but
                                    // they haven't cropped yet.
                                    if (somethingAdded)
                                    {
                                        // Notice below in the section with w. If there is extra content
                                        // before the code section on the same line, it will have been
                                        // inserted/indented already.
                                        builder.Append(indent);
                                    }
                                    builder.Append(line);
                                    builder.Append("\n");
                                    somethingAdded = true;
                                }
                                else
                                {
                                    // In content sections after the first one,
                                    // skip newlines if they are the first thing in the section.
                                    line = section.Substring(start, k - start);
                                    if (I + i == 0)
                                    {
                                        builder.Append(line);
                                        builder.Append("\n");
                                    }
                                    else if (line != "")
                                    {
                                        if (builder[builder.Length - 1] == '\n')
                                        {
                                            if (start == 0 && (k < section.Length - 1 || i == right.Count - 1))
                                            {
                                                builder.Append(indent);
                                            }
                                            else if (k == section.Length - 1 && i < right.Count - 1)
                                            {
                                                builder.Append(indent);
                                            }
                                        }
                                        builder.Append(line);
                                        builder.Append("\n");
                                    }
                                    else if (k > 0 || (builder.Length > 0 && builder[builder.Length - 1] != '\n'))
                                    {
                                        builder.Append(line);
                                        builder.Append("\n");
                                    }
                                }
                                start = k + 1;
                                ++lineNum;
                            }
                        }
                        if (template.Multiline)
                        {
                            // If this is a code section, the lastPiece is just the last line of the
                            // template.
                            // There is no newline at the end.
                            // If this is a text section, the lastPiece is a prefix for the next code
                            // section.
                            string lastPiece = section.Substring(start, section.Length - start);
                            if (i % 2 == 1)
                            {
                                // Odd sections are always code sections.
                                // Code sections don't have a newline at the end.
                                if (j == 0)
                                {
                                    // This means there was a newline at the end of section.
                                    if (start > 0 && lastPiece != "")
                                    {
                                        builder.Append(indent);
                                    }
                                }
                                else if (j == text.Count - 1)
                                {
                                    indent = parentIndent;
                                }
                                builder.Append(lastPiece);
                            }
                            else
                            {
                                int w;
                                for (w = 0; w < lastPiece.Length; ++w)
                                {
                                    if (lastPiece[w] != ' ')
                                    {
                                        break;
                                    }
                                }
                                // indent only includes spaces before the first non-space character.
                                // The non-space part of the text is only inserted once.
                                // An edge case involves spaces inserted between code sections on the same
                                // line.
                                // \t not spoken here.
                                // while (builder.Length == 0 || builder[builder.Length - 1] == '\n')
                                {
                                    string end;
                                    if (builder.Length == 0 || builder[builder.Length - 1] == '\n')
                                    {
                                        indent = parentIndent + lastPiece.Substring(0, w);
                                        end    = lastPiece.Substring(w, lastPiece.Length - w);
                                    }
                                    else
                                    {
                                        end = lastPiece;
                                    }
                                    if (i < right.Count - 1)
                                    {
                                        if (section.Length > 0)
                                        {
                                            if (builder.Length == 0 || builder[builder.Length - 1] == '\n')
                                            {
                                                builder.Append(indent);
                                            }
                                        }
                                    }
                                    builder.Append(end);
                                }
                            }
                        }
                        else
                        {
                            // If there are no newlines in the template then just drop the whole thing
                            // in as is.
                            builder.Append(text[j]);
                        }
                    }
                }
            }
            // Go back and remove the final newline now.
            // Let the enclosing template decide how to finish off.
            if (template.Multiline)
            {
                if (builder.Length > 0 && builder[builder.Length - 1] != '\n')
                {
                    builder.Append("\n");
                }
            }
            return(new RCString(builder.ToString()));
        }
Exemple #10
0
 public RCVectorEnumerator(RCVector <T> array)
 {
     _vector = array;
 }