Ejemplo n.º 1
0
        public override string ToString()
        {
            var    ofstream = IntPtr.Zero;
            var    stdstr   = IntPtr.Zero;
            string str      = null;

            try
            {
                ofstream = Dlib.Native.ostringstream_new();

                Dlib.Native.ErrorType ret;
                switch (this._ElementType)
                {
                case Dlib.Native.ElementType.OpTrans:
                    ret = Native.matrix_op_op_trans_operator_left_shift(this._MatrixElementType,
                                                                        this.NativePtr,
                                                                        this.TemplateRows,
                                                                        this.TemplateColumns,
                                                                        ofstream);
                    break;

                case Dlib.Native.ElementType.OpStdVectToMat:
                    ret = Native.matrix_op_op_std_vect_to_mat_operator_left_shift(this._MatrixElementType,
                                                                                  this.NativePtr,
                                                                                  this.TemplateRows,
                                                                                  this.TemplateColumns,
                                                                                  ofstream);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                switch (ret)
                {
                case Dlib.Native.ErrorType.OK:
                    stdstr = Dlib.Native.ostringstream_str(ofstream);
                    str    = StringHelper.FromStdString(stdstr);
                    break;

                case Dlib.Native.ErrorType.InputElementTypeNotSupport:
                    throw new ArgumentException($"Input {this._ElementType} is not supported.");

                default:
                    throw new ArgumentException();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                if (stdstr != IntPtr.Zero)
                {
                    Dlib.Native.string_delete(stdstr);
                }
                if (ofstream != IntPtr.Zero)
                {
                    Dlib.Native.ostringstream_delete(ofstream);
                }
            }

            return(str);
        }