XdmfCore.i 43.8 KB
Newer Older
1 2 3 4 5
/*
XdmfCorePython.cpp:
swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
*/

6 7 8

#ifdef XDMF_BUILD_DSM

9 10
%module XdmfCore
%{
11 12 13

    #include <mpi.h>

14 15 16 17 18
    #include <XdmfArray.hpp>
    #include <XdmfArrayType.hpp>
    #include <XdmfCore.hpp>
    #include <XdmfCoreItemFactory.hpp>
    #include <XdmfCoreReader.hpp>
19
    #include <XdmfError.hpp>
20 21 22 23 24 25 26 27 28
    #include <XdmfHeavyDataController.hpp>
    #include <XdmfHeavyDataWriter.hpp>
    #include <XdmfHDF5Controller.hpp>
    #include <XdmfHDF5Writer.hpp>
    #include <XdmfHDF5ControllerDSM.hpp>
    #include <XdmfHDF5WriterDSM.hpp>
    #include <XdmfInformation.hpp>
    #include <XdmfItem.hpp>
    #include <XdmfItemProperty.hpp>
29
    #include <XdmfSharedPtr.hpp>
30
    #include <XdmfSparseMatrix.hpp>
31 32 33 34
    #include <XdmfSystemUtils.hpp>
    #include <XdmfVersion.hpp>
    #include <XdmfVisitor.hpp>
    #include <XdmfWriter.hpp>
35 36

    #include <ProjectVersion.hpp>
37 38
%}

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

#else

%module XdmfCore
%{
    #include <XdmfArray.hpp>
    #include <XdmfArrayType.hpp>
    #include <XdmfCore.hpp>
    #include <XdmfCoreItemFactory.hpp>
    #include <XdmfCoreReader.hpp>
    #include <XdmfError.hpp>
    #include <XdmfHeavyDataController.hpp>
    #include <XdmfHeavyDataWriter.hpp>
    #include <XdmfHDF5Controller.hpp>
    #include <XdmfHDF5Writer.hpp>
    #include <XdmfInformation.hpp>
    #include <XdmfItem.hpp>
    #include <XdmfItemProperty.hpp>
    #include <XdmfSharedPtr.hpp>
58
    #include <XdmfSparseMatrix.hpp>
59 60 61 62 63 64 65 66 67 68
    #include <XdmfSystemUtils.hpp>
    #include <XdmfVersion.hpp>
    #include <XdmfVisitor.hpp>
    #include <XdmfWriter.hpp>

    #include <ProjectVersion.hpp>
%}

#endif

69
#ifdef SWIGJAVA
70

71
// Ignore const overloaded methods
72
%ignore XdmfArray::getHeavyDataController() const;
73 74 75
%ignore XdmfArray::getValuesInternal() const;
%ignore XdmfItem::getInformation(const unsigned int) const;
%ignore XdmfItem::getInformation(const std::string &) const;
76
%ignore XdmfWriter::getHeavyDataWriter() const;
77 78
%ignore XdmfInformation::getArray(unsigned int const) const;
%ignore XdmfInformation::getArray(std::string const &) const;
79

80 81 82
// Ignore ItemTags
%ignore XdmfArray::ItemTag;
%ignore XdmfInformation::ItemTag;
83

84
// Define equality operators
85
%extend XdmfItem {
86

87 88 89 90 91 92 93 94 95 96 97 98 99
    bool equals(boost::shared_ptr<XdmfItem> item) {
        if (item == NULL) {
            return false;
        }
        return self == item.get();
    }

    bool IsEqual(boost::shared_ptr<XdmfItem> item) {
        if (item == NULL) {
            return false;
        }
        return self == item.get();
    }
100
};
101

102
%extend XdmfItemProperty {
103

104 105 106 107 108 109 110 111 112 113 114 115 116
    bool equals(boost::shared_ptr<XdmfItemProperty> itemProperty) {
        if (itemProperty == NULL) {
            return false;
        }
        return self == itemProperty.get();
    }

    bool IsEqual(boost::shared_ptr<XdmfItemProperty> itemProperty) {
        if (itemProperty == NULL) {
            return false;
        }
        return self == itemProperty.get();
    }
117 118 119

};

120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
%typemap(javacode) XdmfArray %{
    public void insertValuesAsInt8(int index, char[] values) {
        for(int i = 0; i < values.length; i++)
            this.insertValueAsInt8(index+i, values[i]);
    }

    public void insertValuesAsInt16(int index, short[] values) {
        for(int i = 0; i < values.length; i++)
            this.insertValueAsInt16(index+i, values[i]);
    }

    public void insertValuesAsInt32(int index, int[] values) {
        for(int i = 0; i < values.length; i++)
            this.insertValueAsInt32(index+i, values[i]);
    }

    public void insertValuesAsFloat32(int index, float[] values) {
        for(int i = 0; i < values.length; i++)
            this.insertValueAsFloat32(index+i, values[i]);
    }

    public void insertValuesAsFloat64(int index, double[] values) {
        for(int i = 0; i < values.length; i++)
            this.insertValueAsFloat64(index+i, values[i]);
    }
%}

147
%pragma(java) jniclasscode=%{
148 149 150 151 152
    static {
        try {
            System.loadLibrary("XdmfCoreJava");
        }
        catch (UnsatisfiedLinkError e) {
153 154
            System.err.println("Native code library failed to load for" +
                               "XdmfCoreJava\n" + e);
155 156 157
            System.exit(1);
        }
    }
158 159 160
%}

#endif /* SWIGJAVA */
161

162 163
#ifdef SWIGPYTHON

164 165 166 167
%include mpi4py/mpi4py.i

%mpi4py_typemap(Comm, MPI_Comm);

168 169 170 171
/*This causes it to avoid throwing a warning for redefining fuctions that are defined for XdmfArray.
  I this case doing so was intentional.*/
#pragma SWIG nowarn=302

172
// Provide accessors from python lists to XdmfArrays
173
%extend XdmfArray {
174

175 176 177 178 179 180 181 182 183
%{
  #include <stack>;
/*These can't be accessed from python so don't worry about security issues.*/
  static std::map<std::string, PyObject *> pythonFunctions;
  static std::map<char, PyObject *> pythonOperations;
  static int pythonOperationPriority [4];
  static std::string pythonSupportedOperations = "";
%}

184 185 186 187 188 189 190 191 192 193
    PyObject * getBuffer() {
        void *vp = $self->getValuesInternal();
        Py_ssize_t sz =
            $self->getSize() * $self->getArrayType()->getElementSize();
        PyObject * c = PyBuffer_FromMemory(vp, sz);
        return(c);
    }

    %pythoncode {
        def getNumpyArray(self):
194
            h5ctl = self.getHeavyDataController()
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
            if h5ctl == None :
                try :
                    from numpy import frombuffer as ___frombuffer
                except :
                    return None
                buf = self.getBuffer()
                aType = self.getArrayType()
                if aType == XdmfArrayType.Int8() :
                    return(___frombuffer(buf, 'int8'))
                if aType == XdmfArrayType.Int16() :
                    return(___frombuffer(buf, 'int16'))
                if aType == XdmfArrayType.Int32() :
                    return(___frombuffer(buf, 'int32'))
                if aType == XdmfArrayType.Int64() :
                    return(___frombuffer(buf, 'int64'))
                if aType == XdmfArrayType.Float32() :
                    return(___frombuffer(buf, 'float32'))
                if aType == XdmfArrayType.Float64() :
                    return(___frombuffer(buf, 'float64'))
                if aType == XdmfArrayType.UInt8() :
                    return(___frombuffer(buf, 'uint8'))
                if aType == XdmfArrayType.UInt16() :
                    return(___frombuffer(buf, 'uint16'))
                if aType == XdmfArrayType.UInt32() :
                    return(___frombuffer(buf, 'uint32'))
                return None
            else :
                h5FileName = h5ctl.getFilePath()
                h5DataSetName = h5ctl.getDataSetPath()
                if (h5FileName == None) | (h5DataSetName == None) :
                    return None
                try :
                    from h5py import File as ___File
                    from numpy import array as ___array
                    f = ___File(h5FileName, 'r')
                    if h5DataSetName in f.keys() :
                        return(___array(f[h5DataSetName]))
                except :
                    pass
                return None
    };

237 238 239 240 241
    void insertAsInt8(int startIndex, PyObject * list) {
        Py_ssize_t size = PyList_Size(list);
        for(Py_ssize_t i = 0; i < size; ++i) {
            $self->insert(i+startIndex, (char)(PyLong_AsLong(PyList_GetItem(list, i))));
        }
242 243
    }

244 245 246 247 248
    void insertAsInt16(int startIndex, PyObject * list) {
        Py_ssize_t size = PyList_Size(list);
        for(Py_ssize_t i = 0; i < size; ++i) {
            $self->insert(i+startIndex, (short)(PyLong_AsLong(PyList_GetItem(list, i))));
        }
249 250
    }

251 252 253 254 255
    void insertAsInt32(int startIndex, PyObject * list) {
        Py_ssize_t size = PyList_Size(list);
        for(Py_ssize_t i = 0; i < size; ++i) {
            $self->insert(i+startIndex, (int)(PyLong_AsLong(PyList_GetItem(list, i))));
        }
256 257
    }

258 259 260 261 262
    void insertAsInt64(int startIndex, PyObject * list) {
        Py_ssize_t size = PyList_Size(list);
        for(Py_ssize_t i = 0; i < size; ++i) {
            $self->insert(i+startIndex, PyLong_AsLong(PyList_GetItem(list, i)));
        }
263 264
    }

265 266 267 268 269
    void insertAsFloat32(int startIndex, PyObject * list) {
        Py_ssize_t size = PyList_Size(list);
        for(Py_ssize_t i = 0; i < size; ++i) {
            $self->insert(i+startIndex, (float)PyFloat_AsDouble(PyList_GetItem(list, i)));
        }
270 271
    }

272 273 274 275 276
    void insertAsFloat64(int startIndex, PyObject * list) {
        Py_ssize_t size = PyList_Size(list);
        for(Py_ssize_t i = 0; i < size; ++i) {
            $self->insert(i+startIndex, PyFloat_AsDouble(PyList_GetItem(list, i)));
        }
277 278
    }

279 280 281 282 283
    void insertAsUInt8(int startIndex, PyObject * list) {
        Py_ssize_t size = PyList_Size(list);
        for(Py_ssize_t i = 0; i < size; ++i) {
            $self->insert(i+startIndex, (unsigned char)(PyLong_AsUnsignedLong(PyList_GetItem(list, i))));
        }
284 285
    }

286 287 288 289 290
    void insertAsUInt16(int startIndex, PyObject * list) {
        Py_ssize_t size = PyList_Size(list);
        for(Py_ssize_t i = 0; i < size; ++i) {
            $self->insert(i+startIndex, (unsigned short)(PyLong_AsUnsignedLong(PyList_GetItem(list, i))));
        }
291 292
    }

293 294 295 296 297
    void insertAsUInt32(int startIndex, PyObject * list) {
        Py_ssize_t size = PyList_Size(list);
        for(Py_ssize_t i = 0; i < size; ++i) {
            $self->insert(i+startIndex, (unsigned int)(PyLong_AsUnsignedLong(PyList_GetItem(list, i))));
        }
298
    }
299

Kenneth Leiter's avatar
Kenneth Leiter committed
300 301 302 303 304 305 306
    void insertAsString(int startIndex, PyObject * list) {
        Py_ssize_t size = PyList_Size(list);
        for(Py_ssize_t i = 0; i < size; ++i) {
            $self->insert<std::string>(i+startIndex, PyString_AsString(PyList_GetItem(list, i)));
        }
    }

307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004

/*Note, the things in this block are defined twice for a reason.
  If they are not defined here they can not be referenced by other functions in swig.*/
%{
    /*trying to transfer python funcitons*/
    /*note, accessing private members is impossible from swig.*/

    /*to generate new static functions mark them as static here.*/
    static std::vector<std::string> getSupportedFunctions()
    {
      std::vector<std::string> returnVector = XdmfArray::getSupportedFunctions();
      for (std::map<std::string, PyObject *>::iterator functionWalker = pythonFunctions.begin(); functionWalker != pythonFunctions.end(); functionWalker++)
      {
        returnVector.push_back(functionWalker->first);
      }
      return returnVector;
    }

    static shared_ptr<XdmfArray> evaluateFunction(std::vector<shared_ptr<XdmfArray> > functValues, std::string functName)
    {
      if (pythonFunctions.find(functName)!= pythonFunctions.end())
      {
        swig_type_info * paramType = SWIG_TypeQuery("_p_std__vectorT_boost__shared_ptrT_XdmfArray_t_std__allocatorT_boost__shared_ptrT_XdmfArray_t_t_t");
        PyObject * pyVector = SWIG_NewPointerObj(static_cast<void*>(& functValues), paramType, SWIG_POINTER_NEW);
        PyObject * args = PyTuple_New(1);
        PyTuple_SetItem(args, 0, pyVector);/*In this case you could also cast a pointer to the vector into the PyObject * type, but that doesn't work for all types*/
        PyObject * resultObject = PyObject_CallObject(pythonFunctions[functName], args);
        void * resultPointer = 0;
        swig_type_info * returnType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfArray_t");
        SWIG_ConvertPtr(resultObject, &resultPointer, returnType, 0);
        shared_ptr<XdmfArray> * returnArrayPointer = reinterpret_cast<shared_ptr<XdmfArray> *>(resultPointer);
        shared_ptr<XdmfArray> returnArray = returnArrayPointer[0];
        return returnArray;
      }
      else
      {
         /*this does not actually cause an infinte recursive loop, it sends the values to the version of the function defined in XdmfArray.cpp*/
         return XdmfArray::evaluateFunction(functValues, functName);
      }
    }

    static std::string getSupportedOperations()
    {
      std::string returnVector = XdmfArray::getSupportedOperations();
      returnVector += pythonSupportedOperations;
      return returnVector;
    }

    static int getOperationPriority(char operation)
    {
      size_t operationLocation = pythonSupportedOperations.find(operation);
      if (operationLocation != std::string::npos)
      {
        return pythonOperationPriority[operationLocation];
      }
      else
      {
        return XdmfArray::getOperationPriority(operation);
      }
    }

    static shared_ptr<XdmfArray> evaluateOperation(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2, char functName)
    {
      if (pythonOperations.find(functName)!= pythonOperations.end())
      {
        swig_type_info * paramType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfArray_t");
        PyObject * pyVal1 = SWIG_NewPointerObj(static_cast<void*>(& val1), paramType, SWIG_POINTER_NEW);
        PyObject * pyVal2 = SWIG_NewPointerObj(static_cast<void*>(& val2), paramType, SWIG_POINTER_NEW);
        PyObject * args = PyTuple_New(2);
        PyTuple_SetItem(args, 0, pyVal1);
        PyTuple_SetItem(args, 1, pyVal2);
        PyObject * resultObject = PyObject_CallObject(pythonOperations[functName], args);
        void * resultPointer = 0;
        swig_type_info * returnType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfArray_t");
        SWIG_ConvertPtr(resultObject, &resultPointer, returnType, 0);
        shared_ptr<XdmfArray> * returnArrayPointer = reinterpret_cast<shared_ptr<XdmfArray> *>(resultPointer);
        shared_ptr<XdmfArray> returnArray = returnArrayPointer[0];
        return returnArray;
      }
      else
      {
         /*this does not actually cause an infinte recursive loop, it sends the values to the version of the function defined in XdmfArray.cpp*/
         return XdmfArray::evaluateOperation(val1, val2, functName);
      }
    }

    static shared_ptr<XdmfArray> evaluateExpression(std::string expression, std::map<std::string, shared_ptr<XdmfArray> > variables)
    {
      std::stack<shared_ptr<XdmfArray> > valueStack;
      std::stack<char> operationStack;

      /*string is parsed left to right
        elements of the same priority are evaluated right to left*/
      for (int i = 0; i < expression.size(); i++)
      {
        if (XdmfArray::getValidDigitChars().find(expression[i]) != std::string::npos)/*found to be a digit*/
        {
          /*progress until a non-digit is found*/
          int valueStart = i;
          while (XdmfArray::getValidDigitChars().find(expression[i + 1]) != std::string::npos)
          {
            i++;
          }
          /*push back to the value stack*/
          shared_ptr<XdmfArray> valueArray = XdmfArray::New();
          valueArray->insert(0, atof(expression.substr(valueStart, i + 1 - valueStart).c_str()));/*use this to convert to double*/
          valueStack.push(valueArray);
        }
        else if (XdmfArray::getValidVariableChars().find(expression[i]) != std::string::npos)/*found to be a variable*/
        {
          int valueStart = i;
          /*progress until a nonvariable value is found*/
          while (XdmfArray::getValidVariableChars().find(expression[i + 1]) != std::string::npos)
          {
            i++;
          }
          /*convert to equivalent*/
          if (variables.find(expression.substr(valueStart, i + 1 - valueStart)) == variables.end())
          {
            std::vector<std::string> functionList = XdmfArray::getSupportedFunctions();
            bool functionExists = false;
            for (int j = 0; j < functionList.size() && !functionExists; j++)
            {
              if (functionList[j] == expression.substr(valueStart, i + 1 - valueStart))
              {
                functionExists = true;
              }
            }
            if (functionExists)
            {
              XdmfError::message(XdmfError::FATAL,
                                 "Error: Invalid Variable in evaluateExpression " + expression.substr(valueStart, i + 1 - valueStart));
            }
            else
            {
              std::string currentFunction = expression.substr(valueStart, i + 1 - valueStart);
              /*check if next character is an open parenthesis*/
              if (expression[i+1] != '(')
              {
                XdmfError::message(XdmfError::FATAL,
                                   "Error: No values supplied to function " + expression.substr(valueStart, i + 1 - valueStart));
              }
              /*if it is grab the string between paranthesis*/
              i = i + 2;
              valueStart = i;
              int numOpenParenthesis = 0;
              while ((expression[i] != ')' || numOpenParenthesis) && i < expression.size())
              {
                if (expression[i] == '(')
                {
                  numOpenParenthesis++;
                }
                else if (expression[i] == ')')
                {
                  numOpenParenthesis--;
                }
                i++;
              }
              std::string functionParameters = expression.substr(valueStart, i - valueStart);
              std::vector<shared_ptr<XdmfArray> > parameterVector;
              /*split that string at commas*/
              size_t parameterSplit = 0;
              while (parameterSplit != std::string::npos)
              {
                parameterSplit = 0;
                parameterSplit = functionParameters.find_first_of(",", parameterSplit);
                /*feed the substrings to the parse function*/
                if (parameterSplit == std::string::npos)
                {
                  parameterVector.push_back(evaluateExpression(functionParameters, variables));
                }
                else
                {
                  parameterVector.push_back(evaluateExpression(functionParameters.substr(0, parameterSplit), variables));
                  functionParameters = functionParameters.substr(parameterSplit+1);
                }
              }
              valueStack.push(evaluateFunction(parameterVector, currentFunction));
            }
          }
          else
          {
            /*push equivalent to value stack*/
            valueStack.push(variables.find(expression.substr(valueStart, i + 1 - valueStart))->second);
          }
        }
        else if (XdmfArray::getSupportedOperations().find(expression[i]) != std::string::npos)//found to be an operation
        {
          /*pop operations off the stack until one of a lower or equal importance is found*/
          if (operationStack.size() > 0)
          {
            if (expression[i] == ')')
            {
              /*to close a parenthesis pop off all operations until another parentheis is found*/
              while (operationStack.size() > 0 && operationStack.top() != '(')
              {
                if (valueStack.size() < 2)/*must be at least two values for this loop to work properly*/
                {
                  XdmfError::message(XdmfError::FATAL,
                                     "Error: Not Enough Values in evaluateExpression");
                }
                else
                {
                  shared_ptr<XdmfArray> val2 = valueStack.top();
                  valueStack.pop();
                  shared_ptr<XdmfArray> val1 = valueStack.top();
                  valueStack.pop();
                  valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
                  operationStack.pop();
                }
              }
              operationStack.pop();
            }
            else if (expression[i] == '(')
            {
              /*just add it if it's a start parenthesis
                nothing happens here in that case
                addition happens after the if statement block*/
            }
            else
            {
              int operationLocation = XdmfArray::getOperationPriority(expression[i]);
              int topOperationLocation = XdmfArray::getOperationPriority(operationStack.top());
              /*see order of operations to determine importance*/
              while (operationStack.size() > 0 && operationLocation < topOperationLocation)
              {
                if (valueStack.size() < 2)/*must be at least two values for this loop to work properly*/
                {
                  XdmfError::message(XdmfError::FATAL,
                                     "Error: Not Enough Values in evaluateExpression");
                }
                else
                {
                  shared_ptr<XdmfArray> val2 = valueStack.top();
                  valueStack.pop();
                  shared_ptr<XdmfArray> val1 = valueStack.top();
                  valueStack.pop();
                  valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
                  operationStack.pop();
                  if (operationStack.size() == 0)
                  {
                    break;
                  }
                  topOperationLocation = XdmfArray::getOperationPriority(operationStack.top());
                }
              }
            }
          }
          if (expression[i] != ')')
          {
            /*add the operation to the operation stack*/
            operationStack.push(expression[i]);
          }
        }
        /*if not a value or operation the character is ignored*/
      }


      /*empty what's left in the stacks before finishing*/
      while (valueStack.size() > 1 && operationStack.size() > 0)
      {
        if (valueStack.size() < 2)/*must be at least two values for this loop to work properly*/
        {
          XdmfError::message(XdmfError::FATAL,
                             "Error: Not Enough Values in evaluateExpression");
        }
        else
        {
          if(operationStack.top() == '(')
          {
            XdmfError::message(XdmfError::WARNING,
                               "Warning: Unpaired Parenthesis");
          }
          else
          {
            shared_ptr<XdmfArray> val2 = valueStack.top();
            valueStack.pop();
            shared_ptr<XdmfArray> val1 = valueStack.top();
            valueStack.pop();
            if (operationStack.size() == 0)
            {
              XdmfError::message(XdmfError::FATAL,
                                 "Error: Not Enough Operators in evaluateExpression");
            }
            else
            {
              valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
              operationStack.pop();
            }
          }
        }
      }

      /*throw error if there's extra operations*/
      if (operationStack.size() > 0)
      {
        XdmfError::message(XdmfError::WARNING,
                           "Warning: Left Over Operators in evaluateExpression");
      }

      if (valueStack.size() > 1)
      {
        XdmfError::message(XdmfError::WARNING,
                           "Warning: Left Over Values in evaluateExpression");
      }

      return valueStack.top();
    }

%}

    /*trying to transfer python funcitons*/
    /*note, accessing private members is impossible from swig.*/
    static int addFunction(std::string newName, PyObject * functionref)
    {
      /*check if the object is callable*/
      if (PyCallable_Check(functionref) == 1)
      {
        pythonFunctions[newName] = functionref;
        return pythonFunctions.size();
      }
      else
      {
        XdmfError::message(XdmfError::FATAL,
          "Error: Function is not callable");
        return -1;
      }
    }

    /*to generate new static functions mark them as static here.*/
    static std::vector<std::string> getSupportedFunctions()
    {
      std::vector<std::string> returnVector = XdmfArray::getSupportedFunctions();
      for (std::map<std::string, PyObject *>::iterator functionWalker = pythonFunctions.begin(); functionWalker != pythonFunctions.end(); functionWalker++)
      {
        returnVector.push_back(functionWalker->first);
      }
      return returnVector;
    }

    static shared_ptr<XdmfArray> evaluateFunction(std::vector<shared_ptr<XdmfArray> > functValues, std::string functName)
    {
      if (pythonFunctions.find(functName)!= pythonFunctions.end())
      {
        swig_type_info * paramType = SWIG_TypeQuery("_p_std__vectorT_boost__shared_ptrT_XdmfArray_t_std__allocatorT_boost__shared_ptrT_XdmfArray_t_t_t");
        PyObject * pyVector = SWIG_NewPointerObj(static_cast<void*>(& functValues), paramType, SWIG_POINTER_NEW);
        PyObject * args = PyTuple_New(1);
        PyTuple_SetItem(args, 0, pyVector);/*In this case you could also cast a pointer to the vector into the PyObject * type, but that doesn't work for all types*/
        PyObject * resultObject = PyObject_CallObject(pythonFunctions[functName], args);
        void * resultPointer = 0;
        swig_type_info * returnType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfArray_t");
        SWIG_ConvertPtr(resultObject, &resultPointer, returnType, 0);
        shared_ptr<XdmfArray> * returnArrayPointer = reinterpret_cast<shared_ptr<XdmfArray> *>(resultPointer);
        shared_ptr<XdmfArray> returnArray = returnArrayPointer[0];
        return returnArray;
      }
      else
      {
         /*this does not actually cause an infinte recursive loop, it sends the values to the version of the function defined in XdmfArray.cpp*/
         return XdmfArray::evaluateFunction(functValues, functName);
      }
    }

    static int addOperation(char newName, PyObject * calcref, int priority)
    {
      if (newName == '(' || newName == ')')
      {
        XdmfError::message(XdmfError::FATAL,
                           "Error: Parenthesis can not be redefined");
      }
      /*check if the object is callable*/
      if (PyCallable_Check(calcref) == 1)
      {
        if (pythonOperations.find(newName) != pythonOperations.end() || XdmfArray::getSupportedOperations().find(newName) != std::string::npos)
        {
          XdmfError::message(XdmfError::WARNING,
            "Warning: Operation Redefined");/*It's a good idea to warn users when they're doing this*/
          size_t operationLocation = pythonSupportedOperations.find(newName);
          /*if not an already defined python function*/
          if (pythonOperations.find(newName) == pythonOperations.end())
          {
            pythonSupportedOperations.push_back(newName);
            int priorityArraySize = sizeof(pythonOperationPriority)/sizeof(int);
            if (pythonSupportedOperations.size()-1 > priorityArraySize)
            {
              int newArray [priorityArraySize*2];
              std::copy(pythonOperationPriority, pythonOperationPriority+(priorityArraySize-1), newArray);
              delete pythonOperationPriority;
              *pythonOperationPriority = *newArray;
            }
          }
          pythonOperationPriority[operationLocation] = priority;
          /*if defined on the c++ side same as adding a new one*/
        }
        else
        {
          pythonSupportedOperations += newName;
          if (XdmfArray::getValidVariableChars().find(newName) != std::string::npos || XdmfArray::getValidDigitChars().find(newName) != std::string::npos)
          {
            XdmfError::message(XdmfError::FATAL,
              "Error: Operation Overlaps with Variables");
          }
          else
          {
            pythonSupportedOperations.push_back(newName);
            int priorityArraySize = sizeof(pythonOperationPriority)/sizeof(int);
            if (pythonSupportedOperations.size()-1 > priorityArraySize)
            {
              int newArray [priorityArraySize*2];
              std::copy(pythonOperationPriority, pythonOperationPriority+(priorityArraySize-1), newArray);
              delete pythonOperationPriority;
              *pythonOperationPriority = *newArray;
            }
          }
        }
        pythonOperations[newName] = calcref;
        return pythonOperations.size();
      }
      else
      {
        XdmfError::message(XdmfError::FATAL,
          "Error: Operation is not callable");
        return -1;
      }
    }

    static std::string getSupportedOperations()
    {
      std::string returnVector = XdmfArray::getSupportedOperations();
      for (std::map<char, PyObject *>::iterator functionWalker = pythonOperations.begin(); functionWalker != pythonOperations.end(); functionWalker++)
      {
        returnVector += functionWalker->first;
      }
      return returnVector;
    }

    static shared_ptr<XdmfArray> evaluateOperation(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2, char functName)
    {
      if (pythonOperations.find(functName)!= pythonOperations.end())
      {
        swig_type_info * paramType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfArray_t");
        PyObject * pyVal1 = SWIG_NewPointerObj(static_cast<void*>(& val1), paramType, SWIG_POINTER_NEW);
        PyObject * pyVal2 = SWIG_NewPointerObj(static_cast<void*>(& val2), paramType, SWIG_POINTER_NEW);
        PyObject * args = PyTuple_New(2);
        PyTuple_SetItem(args, 0, pyVal1);
        PyTuple_SetItem(args, 1, pyVal2);
        PyObject * resultObject = PyObject_CallObject(pythonOperations[functName], args);
        void * resultPointer = 0;
        swig_type_info * returnType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfArray_t");
        SWIG_ConvertPtr(resultObject, &resultPointer, returnType, 0);
        shared_ptr<XdmfArray> * returnArrayPointer = reinterpret_cast<shared_ptr<XdmfArray> *>(resultPointer);
        shared_ptr<XdmfArray> returnArray = returnArrayPointer[0];
        return returnArray;
      }
      else
      {
         /*this does not actually cause an infinte recursive loop, it sends the values to the version of the function defined in XdmfArray.cpp*/
         return XdmfArray::evaluateOperation(val1, val2, functName);
      }
    }

    static shared_ptr<XdmfArray> evaluateExpression(std::string expression, std::map<std::string, shared_ptr<XdmfArray> > variables)
    {
      std::stack<shared_ptr<XdmfArray> > valueStack;
      std::stack<char> operationStack;

      /*string is parsed left to right
        elements of the same priority are evaluated right to left*/
      for (int i = 0; i < expression.size(); i++)
      {
        if (XdmfArray::getValidDigitChars().find(expression[i]) != std::string::npos) /*found to be a digit*/
        {
          /*progress until a non-digit is found*/
          int valueStart = i;
          while (XdmfArray::getValidDigitChars().find(expression[i + 1]) != std::string::npos)
          {
            i++;
          }
          /*push back to the value stack*/
          shared_ptr<XdmfArray> valueArray = XdmfArray::New();
          valueArray->insert(0, atof(expression.substr(valueStart, i + 1 - valueStart).c_str()));/*use this to convert to double*/
          valueStack.push(valueArray);
        }
        else if (XdmfArray::getValidVariableChars().find(expression[i]) != std::string::npos)/*found to be a variable*/
        {
          int valueStart = i;
          /*progress until a nonvariable value is found*/
          while (XdmfArray::getValidVariableChars().find(expression[i + 1]) != std::string::npos)
          {
            i++;
          }
          /*convert to equivalent*/
          if (variables.find(expression.substr(valueStart, i + 1 - valueStart)) == variables.end())
          {
            std::vector<std::string> functionList = XdmfArray::getSupportedFunctions();
            bool functionExists = false;
            for (int j = 0; j < functionList.size() && !functionExists; j++)
            {
              if (functionList[j] == expression.substr(valueStart, i + 1 - valueStart))
              {
                functionExists = true;
              }
            }
            if (functionExists)
            {
              XdmfError::message(XdmfError::FATAL,
                                 "Error: Invalid Variable in evaluateExpression " + expression.substr(valueStart, i + 1 - valueStart));
            }
            else
            {
              std::string currentFunction = expression.substr(valueStart, i + 1 - valueStart);
              /*check if next character is an open parenthesis*/
              if (expression[i+1] != '(')
              {
                XdmfError::message(XdmfError::FATAL,
                                   "Error: No values supplied to function " + expression.substr(valueStart, i + 1 - valueStart));
              }
              /*if it is grab the string between paranthesis*/
              i = i + 2;
              valueStart = i;
              int numOpenParenthesis = 0;
              while ((expression[i] != ')' || numOpenParenthesis) && i < expression.size())
              {
                if (expression[i] == '(')
                {
                  numOpenParenthesis++;
                }
                else if (expression[i] == ')')
                {
                  numOpenParenthesis--;
                }
                i++;
              }
              std::string functionParameters = expression.substr(valueStart, i - valueStart);
              std::vector<shared_ptr<XdmfArray> > parameterVector;
              /*split that string at commas*/
              size_t parameterSplit = 0;
              while (parameterSplit != std::string::npos)
              {
                parameterSplit = 0;
                parameterSplit = functionParameters.find_first_of(",", parameterSplit);
                /*feed the substrings to the parse function*/
                if (parameterSplit == std::string::npos)
                {
                  parameterVector.push_back(evaluateExpression(functionParameters, variables));
                }
                else
                {
                  parameterVector.push_back(evaluateExpression(functionParameters.substr(0, parameterSplit), variables));
                  functionParameters = functionParameters.substr(parameterSplit+1);
                }
              }
              valueStack.push(evaluateFunction(parameterVector, currentFunction));
            }
          }
          else
          {
            /*push equivalent to value stack*/
            valueStack.push(variables.find(expression.substr(valueStart, i + 1 - valueStart))->second);
          }
        }
        else if (XdmfArray::getSupportedOperations().find(expression[i]) != std::string::npos)//found to be an operation
        {
          /*pop operations off the stack until one of a lower or equal importance is found*/
          if (operationStack.size() > 0)
          {
            if (expression[i] == ')')
            {
              /*to close a parenthesis pop off all operations until another parentheis is found*/
              while (operationStack.size() > 0 && operationStack.top() != '(')
              {
                if (valueStack.size() < 2)/*must be at least two values for this loop to work properly*/
                {
                  XdmfError::message(XdmfError::FATAL,
                                     "Error: Not Enough Values in evaluateExpression");
                }
                else
                {
                  shared_ptr<XdmfArray> val2 = valueStack.top();
                  valueStack.pop();
                  shared_ptr<XdmfArray> val1 = valueStack.top();
                  valueStack.pop();
                  valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
                  operationStack.pop();
                }
              }
              operationStack.pop();
            }
            else if (expression[i] == '(')
            {
              /*just add it if it's a start parenthesis
                nothing happens here in that case
                addition happens after the if statement*/
            }
            else
            {
              int operationLocation = XdmfArray::getOperationPriority(expression[i]);
              int topOperationLocation = XdmfArray::getOperationPriority(operationStack.top());
              /*see order of operations to determine importance*/
              while (operationStack.size() > 0 && operationLocation < topOperationLocation)
              {
                if (valueStack.size() < 2)/*must be at least two values for this loop to work properly*/
                {
                  XdmfError::message(XdmfError::FATAL,
                                     "Error: Not Enough Values in evaluateExpression");
                }
                else
                {
                  shared_ptr<XdmfArray> val2 = valueStack.top();
                  valueStack.pop();
                  shared_ptr<XdmfArray> val1 = valueStack.top();
                  valueStack.pop();
                  valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
                  operationStack.pop();
                  if (operationStack.size() == 0)
                  {
                    break;
                  }
                  topOperationLocation = XdmfArray::getOperationPriority(operationStack.top());
                }
              }
            }
          }
          if (expression[i] != ')')
          {
            /*add the operation to the operation stack*/
            operationStack.push(expression[i]);
          }
        }
        /*if not a value or operation the character is ignored*/
      }


      /*empty what's left in the stacks before finishing*/
      while (valueStack.size() > 1 && operationStack.size() > 0)
      {
        if (valueStack.size() < 2)/*must be at least two values for this loop to work properly*/
        {
          XdmfError::message(XdmfError::FATAL,
                             "Error: Not Enough Values in evaluateExpression");
        }
        else
        {
          if(operationStack.top() == '(')
          {
            XdmfError::message(XdmfError::WARNING,
                               "Warning: Unpaired Parenthesis");
          }
          else
          {
            shared_ptr<XdmfArray> val2 = valueStack.top();
            valueStack.pop();
            shared_ptr<XdmfArray> val1 = valueStack.top();
            valueStack.pop();
            if (operationStack.size() == 0)
            {
              XdmfError::message(XdmfError::FATAL,
                                 "Error: Not Enough Operators in evaluateExpression");
            }
            else
            {
              valueStack.push(evaluateOperation(val1, val2, operationStack.top()));
              operationStack.pop();
            }
          }
        }
      }

      /*throw error if there's extra operations*/
      if (operationStack.size() > 0)
      {
        XdmfError::message(XdmfError::WARNING,
                           "Warning: Left Over Operators in evaluateExpression");
      }

      if (valueStack.size() > 1)
      {
        XdmfError::message(XdmfError::WARNING,
                           "Warning: Left Over Values in evaluateExpression");
      }

      return valueStack.top();
    }



    static shared_ptr<XdmfArray> XdmfArrayPtr(PyObject * obj)
    {
      void * resultPointer = 0;
      swig_type_info * returnType = SWIG_TypeQuery("_p_boost__shared_ptrT_XdmfArray_t");
      SWIG_ConvertPtr(obj, &resultPointer, returnType, 0);
      shared_ptr<XdmfArray> * returnArrayPointer = reinterpret_cast<shared_ptr<XdmfArray> *>(resultPointer);
      shared_ptr<XdmfArray> returnArray = returnArrayPointer[0];
      return returnArray;
    }



1005 1006
};

1007 1008 1009
%extend XdmfArrayType {
    bool __eq__(const XdmfArrayType * arrayType) {
   	return $self == arrayType;
1010
    }
1011 1012 1013 1014
};

#endif /* SWIGPYTHON */

1015
%include boost_shared_ptr.i
1016 1017 1018 1019 1020 1021 1022

%inline
%{
    #include <boost/shared_ptr.hpp>
    using namespace boost;
%}

1023 1024
%include std_string.i
%include std_vector.i
1025
%include std_map.i
1026

1027
%shared_ptr(Loki::BaseVisitor)
1028 1029 1030 1031
%shared_ptr(Loki::BaseVisitable<void>)
%shared_ptr(Loki::Visitor<XdmfItem>)
%shared_ptr(Loki::Visitor<XdmfArray>)

1032
%include loki/Visitor.h
1033

1034 1035 1036 1037 1038 1039 1040
// Shared Pointer Templates
%shared_ptr(XdmfArray)
%shared_ptr(XdmfArrayType)
%shared_ptr(XdmfCoreItemFactory)
%shared_ptr(XdmfCoreReader)
%shared_ptr(XdmfHDF5Controller)
%shared_ptr(XdmfHDF5Writer)
1041
#ifdef XDMF_BUILD_DSM
1042 1043
    %shared_ptr(XdmfHDF5ControllerDSM)
    %shared_ptr(XdmfHDF5WriterDSM)
1044
#endif
1045 1046
%shared_ptr(XdmfHeavyDataController)
%shared_ptr(XdmfHeavyDataWriter)
1047 1048 1049
%shared_ptr(XdmfInformation)
%shared_ptr(XdmfItem)
%shared_ptr(XdmfItemProperty)
1050
%shared_ptr(XdmfSparseMatrix)
1051 1052
%shared_ptr(XdmfVisitor)
%shared_ptr(XdmfWriter)
1053

1054 1055
%shared_ptr(std::vector<int>)

1056
// Abstract Base Classes
1057
%template(BaseVisitable) Loki::BaseVisitable<void>;
1058 1059
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
1060

1061
%include XdmfCore.hpp
1062
%include XdmfError.hpp
1063 1064
%include XdmfItem.hpp
%include XdmfItemProperty.hpp
1065
%include XdmfSparseMatrix.hpp
1066
%include XdmfVisitor.hpp
1067 1068 1069
%include XdmfHeavyDataController.hpp
%include XdmfHeavyDataWriter.hpp

1070 1071 1072 1073 1074 1075 1076
%include XdmfCoreItemFactory.hpp
%include XdmfCoreReader.hpp
%include XdmfInformation.hpp
%include XdmfHDF5Controller.hpp
%include XdmfHDF5Writer.hpp
%include XdmfWriter.hpp

1077 1078 1079
%include CMake/VersionSuite/ProjectVersion.hpp
%include XdmfVersion.hpp

1080
#ifdef XDMF_BUILD_DSM
1081 1082
    %include XdmfHDF5ControllerDSM.hpp
    %include XdmfHDF5WriterDSM.hpp
1083 1084
#endif

1085 1086 1087
%include XdmfArray.hpp
%include XdmfArrayType.hpp

1088 1089 1090 1091 1092 1093 1094 1095
#ifdef SWIGPYTHON

%pythoncode {
    XdmfVersion = _XdmfCore.cvar.XdmfVersion
};

#endif /* SWIGPYTHON */

1096 1097 1098 1099 1100 1101 1102 1103 1104
%template(getValueAsInt8) XdmfArray::getValue<char>;
%template(getValueAsInt16) XdmfArray::getValue<short>;
%template(getValueAsInt32) XdmfArray::getValue<int>;
%template(getValueAsInt64) XdmfArray::getValue<long>;
%template(getValueAsFloat32) XdmfArray::getValue<float>;
%template(getValueAsFloat64) XdmfArray::getValue<double>;
%template(getValueAsUInt8) XdmfArray::getValue<unsigned char>;
%template(getValueAsUInt16) XdmfArray::getValue<unsigned short>;
%template(getValueAsUInt32) XdmfArray::getValue<unsigned int>;
Kenneth Leiter's avatar
Kenneth Leiter committed
1105
%template(getValueAsString) XdmfArray::getValue<std::string>;
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115

%template(initializeAsInt8) XdmfArray::initialize<char>;
%template(initializeAsInt16) XdmfArray::initialize<short>;
%template(initializeAsInt32) XdmfArray::initialize<int>;
%template(initializeAsInt64) XdmfArray::initialize<long>;
%template(initializeAsFloat32) XdmfArray::initialize<float>;
%template(initializeAsFloat64) XdmfArray::initialize<double>;
%template(initializeAsUInt8) XdmfArray::initialize<unsigned char>;
%template(initializeAsUInt16) XdmfArray::initialize<unsigned short>;
%template(initializeAsUInt32) XdmfArray::initialize<unsigned int>;
Kenneth Leiter's avatar
Kenneth Leiter committed
1116
%template(initializeAsString) XdmfArray::initialize<std::string>;
1117

1118 1119 1120 1121 1122 1123 1124 1125 1126
%template(insertValueAsInt8) XdmfArray::insert<char>;
%template(insertValueAsInt16) XdmfArray::insert<short>;
%template(insertValueAsInt32) XdmfArray::insert<int>;
%template(insertValueAsInt64) XdmfArray::insert<long>;
%template(insertValueAsFloat32) XdmfArray::insert<float>;
%template(insertValueAsFloat64) XdmfArray::insert<double>;
%template(insertValueAsUInt8) XdmfArray::insert<unsigned char>;
%template(insertValueAsUInt16) XdmfArray::insert<unsigned short>;
%template(insertValueAsUInt32) XdmfArray::insert<unsigned int>;
Kenneth Leiter's avatar
Kenneth Leiter committed
1127
%template(insertValueAsString) XdmfArray::insert<std::string>;
1128

1129 1130 1131 1132 1133 1134 1135 1136 1137
%template(pushBackAsInt8) XdmfArray::pushBack<char>;
%template(pushBackAsInt16) XdmfArray::pushBack<short>;
%template(pushBackAsInt32) XdmfArray::pushBack<int>;
%template(pushBackAsInt64) XdmfArray::pushBack<long>;
%template(pushBackAsFloat32) XdmfArray::pushBack<float>;
%template(pushBackAsFloat64) XdmfArray::pushBack<double>;
%template(pushBackAsUInt8) XdmfArray::pushBack<unsigned char>;
%template(pushBackAsUInt16) XdmfArray::pushBack<unsigned short>;
%template(pushBackAsUInt32) XdmfArray::pushBack<unsigned int>;
Kenneth Leiter's avatar
Kenneth Leiter committed
1138
%template(pushBackAsString) XdmfArray::pushBack<std::string>;
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148

%template(resizeAsInt8) XdmfArray::resize<char>;
%template(resizeAsInt16) XdmfArray::resize<short>;
%template(resizeAsInt32) XdmfArray::resize<int>;
%template(resizeAsInt64) XdmfArray::resize<long>;
%template(resizeAsFloat32) XdmfArray::resize<float>;
%template(resizeAsFloat64) XdmfArray::resize<double>;
%template(resizeAsUInt8) XdmfArray::resize<unsigned char>;
%template(resizeAsUInt16) XdmfArray::resize<unsigned short>;
%template(resizeAsUInt32) XdmfArray::resize<unsigned int>;
Kenneth Leiter's avatar
Kenneth Leiter committed
1149
%template(resizeAsString) XdmfArray::resize<std::string>;
1150

1151 1152 1153 1154 1155 1156 1157 1158 1159
%template(UInt8Vector) std::vector<unsigned char>;
%template(UInt16Vector) std::vector<unsigned short>;
%template(UInt32Vector) std::vector<unsigned int>;
%template(Int8Vector) std::vector<char>;
%template(Int16Vector) std::vector<short>;
%template(Int32Vector) std::vector<int>;
%template(Int64Vector) std::vector<long>;
%template(Float32Vector) std::vector<float>;
%template(Float64Vector) std::vector<double>;
1160
%template(StringVector) std::vector<std::string>;
1161
%template(ItemVector) std::vector<boost::shared_ptr<XdmfItem> >;
1162
%template(ArrayMap) std::map<std::string, boost::shared_ptr<XdmfArray> >;
1163
%template(StringMap) std::map<std::string, std::string>;