~ubuntu-branches/ubuntu/wily/opencollada/wily

« back to all changes in this revision

Viewing changes to COLLADAFramework/src/COLLADAFWFormulas.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008-2009 NetAllied Systems GmbH
 
3
 
 
4
    This file is part of COLLADAFramework.
 
5
 
 
6
    Licensed under the MIT Open Source License, 
 
7
    for details please see LICENSE file or the website
 
8
    http://www.opensource.org/licenses/mit-license.php
 
9
*/
 
10
 
 
11
#include "COLLADAFWStableHeaders.h"
 
12
#include "COLLADAFWFormulas.h"
 
13
 
 
14
#include "MathMLASTNode.h"
 
15
#include "MathMLASTArithmeticExpression.h"
 
16
#include "MathMLASTBinaryComparisionExpression.h"
 
17
#include "MathMLASTConstantExpression.h"
 
18
#include "MathMLASTFragmentExpression.h"
 
19
#include "MathMLASTFunctionExpression.h"
 
20
#include "MathMLASTLogicExpression.h"
 
21
#include "MathMLASTUnaryArithmeticExpression.h"
 
22
#include "MathMLASTVariableExpression.h"
 
23
 
 
24
 
 
25
namespace COLLADAFW
 
26
{
 
27
 
 
28
        //------------------------------
 
29
        void setFragments( MathML::AST::INode* astNode, const Formula::ASTNodeASTNodeMap& originalClonedASTNodeMap)
 
30
        {
 
31
                switch ( astNode->getNodeType() )
 
32
                {
 
33
                case MathML::AST::INode::ARITHMETIC:
 
34
                        {
 
35
                                MathML::AST::ArithmeticExpression* arithmetic = (MathML::AST::ArithmeticExpression*)astNode;
 
36
                                MathML::AST::NodeList& operands = arithmetic->getOperands();
 
37
                                for ( size_t i = 0, count = operands.size(); i < count; ++i )
 
38
                                {
 
39
                                        setFragments(operands[i], originalClonedASTNodeMap);
 
40
                                }
 
41
                                break;
 
42
                        }
 
43
                case MathML::AST::INode::COMPARISON:
 
44
                        {
 
45
                                MathML::AST::BinaryComparisonExpression* comparison = (MathML::AST::BinaryComparisonExpression*)astNode;
 
46
                                setFragments(comparison->getLeftOperand(), originalClonedASTNodeMap);
 
47
                                setFragments(comparison->getRightOperand(), originalClonedASTNodeMap);
 
48
                                break;
 
49
                        }
 
50
                case MathML::AST::INode::CONSTANT:
 
51
                case MathML::AST::INode::VARIABLE:
 
52
                        break;
 
53
                case MathML::AST::INode::FRAGMENT:
 
54
                        {
 
55
                                MathML::AST::FragmentExpression* fragment = (MathML::AST::FragmentExpression*)astNode;
 
56
                                MathML::AST::INode* fragmentNode = fragment->getFragment();
 
57
                                Formula::ASTNodeASTNodeMap::const_iterator it = originalClonedASTNodeMap.find(fragmentNode);
 
58
                                COLLADABU_ASSERT( it != originalClonedASTNodeMap.end() );
 
59
                                fragment->setFragment( it->second );
 
60
                                break;
 
61
                        }
 
62
                case MathML::AST::INode::LOGICAL:
 
63
                        {
 
64
                                MathML::AST::LogicExpression* logical = (MathML::AST::LogicExpression*)astNode;
 
65
                                MathML::AST::NodeList& operands = logical->getOperands();
 
66
                                for ( size_t i = 0, count = operands.size(); i < count; ++i )
 
67
                                {
 
68
                                        setFragments(operands[i], originalClonedASTNodeMap);
 
69
                                }
 
70
                                break;
 
71
                        }
 
72
                case MathML::AST::INode::UNARY:
 
73
                        {
 
74
                                MathML::AST::UnaryExpression* unary = (MathML::AST::UnaryExpression*)astNode;
 
75
                                setFragments(unary->getOperand(), originalClonedASTNodeMap);
 
76
                                break;
 
77
                        }
 
78
                case MathML::AST::INode::FUNCTION:
 
79
                        {
 
80
                                MathML::AST::FunctionExpression* func = (MathML::AST::FunctionExpression*)astNode;
 
81
                                MathML::AST::NodeList& operands = func->getParameterList();
 
82
                                for ( size_t i = 0, count = operands.size(); i < count; ++i )
 
83
                                {
 
84
                                        setFragments(operands[i], originalClonedASTNodeMap);
 
85
                                }
 
86
                                break;
 
87
                        }
 
88
                default:
 
89
                        COLLADABU_ASSERT(false);
 
90
                }
 
91
 
 
92
        }
 
93
 
 
94
    //------------------------------
 
95
        Formulas::Formulas(  )
 
96
                : mFormulas( FormulaArray::OWNER )
 
97
        {
 
98
        }
 
99
 
 
100
        //------------------------------
 
101
        Formulas::Formulas( const Formulas& rhs )
 
102
                : mFormulas( FormulaArray::OWNER )
 
103
        {
 
104
                Formula::ASTNodeASTNodeMap originalClonedASTNodeMap;
 
105
                size_t count = rhs.mFormulas.getCount();
 
106
                mFormulas.reallocMemory(count);
 
107
                for ( size_t i = 0; i < count; ++i )
 
108
                {
 
109
                        mFormulas[i] = rhs.mFormulas[i]->clone( originalClonedASTNodeMap );
 
110
                }
 
111
                mFormulas.setCount(count);
 
112
 
 
113
                for ( size_t i = 0; i < count; ++i )
 
114
                {
 
115
                        const MathmlAstArray& asts = mFormulas[i]->getMathmlAsts();
 
116
                        // second step: set fragments to corresponding formula ast
 
117
                        for ( size_t j = 0, count = asts.getCount(); j < count; ++j )
 
118
                        {
 
119
                                setFragments(asts[j], originalClonedASTNodeMap);
 
120
                        }
 
121
                }
 
122
        }
 
123
    //------------------------------
 
124
        Formulas::~Formulas()
 
125
        {
 
126
                for ( size_t i = 0, count = mFormulas.getCount(); i < count; ++i )
 
127
                {
 
128
                        FW_DELETE mFormulas[i];
 
129
                }
 
130
        }
 
131
 
 
132
} // namespace COLLADAFW