diff options
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFactory.cxx | 18 | ||||
-rw-r--r-- | writerfilter/source/ooxml/OOXMLFactory.hxx | 20 | ||||
-rw-r--r-- | writerfilter/source/ooxml/factory_ns.py | 2 | ||||
-rw-r--r-- | writerfilter/source/ooxml/factoryimpl.py | 11 | ||||
-rw-r--r-- | writerfilter/source/ooxml/factoryimpl_ns.py | 50 |
5 files changed, 38 insertions, 63 deletions
diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx index 813982d12b8d..d692305e5a4a 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.cxx +++ b/writerfilter/source/ooxml/OOXMLFactory.cxx @@ -30,30 +30,12 @@ namespace ooxml { using namespace com::sun::star; -CreateElement::CreateElement() -:m_nResource(RT_NoResource), m_nId(0) -{ -} - -CreateElement::CreateElement(ResourceType_t nResource, Id nId) -: m_nResource(nResource), m_nId(nId) -{ -} - // class OOXMLFactory_ns OOXMLFactory_ns::~OOXMLFactory_ns() { } -CreateElementMapPointer OOXMLFactory_ns::getCreateElementMap(Id nId) -{ - if (m_CreateElementsMap.find(nId) == m_CreateElementsMap.end()) - m_CreateElementsMap[nId] = createCreateElementMap(nId); - - return m_CreateElementsMap[nId]; -} - // class OOXMLFactory typedef rtl::Static< osl::Mutex, OOXMLFactory > OOXMLFactory_Mutex; diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx index 67a3e95c4bed..094bd62b9e17 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.hxx +++ b/writerfilter/source/ooxml/OOXMLFactory.hxx @@ -64,19 +64,6 @@ struct AttributeInfo Id m_nRef; }; -struct CreateElement -{ - ResourceType_t m_nResource; - Id m_nId; - - CreateElement(ResourceType_t nResource, Id nId); - CreateElement(); -}; - -typedef boost::unordered_map<Token_t, CreateElement> CreateElementMap; -typedef boost::shared_ptr<CreateElementMap> CreateElementMapPointer; -typedef boost::unordered_map<Id, CreateElementMapPointer> CreateElementsMap; - class OOXMLFactory_ns { public: typedef boost::shared_ptr<OOXMLFactory_ns> Pointer_t; @@ -86,19 +73,14 @@ public: virtual void endAction(OOXMLFastContextHandler * pHandler); virtual void attributeAction(OOXMLFastContextHandler * pHandler, Token_t nToken, OOXMLValue::Pointer_t pValue); - CreateElementMapPointer getCreateElementMap(Id nId); - protected: virtual ~OOXMLFactory_ns(); - CreateElementsMap m_CreateElementsMap; - - virtual CreateElementMapPointer createCreateElementMap(Id nId) = 0; - public: virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) = 0; virtual Id getResourceId(Id nDefine, sal_Int32 nToken) = 0; virtual const AttributeInfo* getAttributeInfoArray(Id nId) = 0; + virtual bool getElementId(Id nDefine, Id nId, ResourceType_t& rOutResource, Id& rOutElement) = 0; }; class OOXMLFactory diff --git a/writerfilter/source/ooxml/factory_ns.py b/writerfilter/source/ooxml/factory_ns.py index f275ed449cf1..38be6d264967 100644 --- a/writerfilter/source/ooxml/factory_ns.py +++ b/writerfilter/source/ooxml/factory_ns.py @@ -36,7 +36,7 @@ public: static Pointer_t getInstance(); virtual const AttributeInfo* getAttributeInfoArray(Id nId); - virtual CreateElementMapPointer createCreateElementMap(Id nId); + virtual bool getElementId(Id nDefine, Id nId, ResourceType_t& rOutResource, Id& rOutElement); virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue); virtual Id getResourceId(Id nDefine, sal_Int32 nToken); """ % nsToken) diff --git a/writerfilter/source/ooxml/factoryimpl.py b/writerfilter/source/ooxml/factoryimpl.py index 05284ee47fcc..8e7e74dfce72 100644 --- a/writerfilter/source/ooxml/factoryimpl.py +++ b/writerfilter/source/ooxml/factoryimpl.py @@ -29,21 +29,20 @@ def createFastChildContextFromFactory(model): if (pFactory.get() != NULL) { - CreateElementMapPointer pMap = pFactory->getCreateElementMap(nDefine); - - if (pMap.get() != NULL) + ResourceType_t nResource; + Id nElementId; + if (pFactory->getElementId(nDefine, Element, nResource, nElementId)) { Id nId = pFactory->getResourceId(nDefine, Element); - CreateElement aCreateElement = (*pMap)[Element]; - switch (aCreateElement.m_nResource) + switch (nResource) {""") resources = ["List", "Integer", "Hex", "String", "UniversalMeasure", "Boolean"] for resource in [r.getAttribute("resource") for r in model.getElementsByTagName("resource")]: if resource not in resources: resources.append(resource) print(""" case RT_%s: - aResult.set(OOXMLFastHelper<OOXMLFastContextHandler%s>::createAndSetParentAndDefine(pHandler, Element, nId, aCreateElement.m_nId)); + aResult.set(OOXMLFastHelper<OOXMLFastContextHandler%s>::createAndSetParentAndDefine(pHandler, Element, nId, nElementId)); break;""" % (resource, resource)) print(""" case RT_Any: aResult.set(createFastChildContextFromStart(pHandler, Element)); diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py index e619ffd4dd49..6f04ba504c3c 100644 --- a/writerfilter/source/ooxml/factoryimpl_ns.py +++ b/writerfilter/source/ooxml/factoryimpl_ns.py @@ -310,28 +310,27 @@ def idForRef(nsNode, refNode): def factoryCreateElementMapInner(files, nsNode, defineNode, resourceNamespaceNode=None): if not resourceNamespaceNode: resourceNamespaceNode = nsNode - ret = [] + ret = {} for refNode in defineNode.getElementsByTagName("ref"): parent = refNode.parentNode if parent.localName in ("element", "attribute"): continue refName = refNode.getAttribute("name") - block = [] + block = {} for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: block = factoryCreateElementMapInner(files, nsNode, define) if len(block) == 0: - block1 = [] + block1 = {} for namespaceNode in getChildrenByName(nsNode.parentNode, "namespace"): for define in [i for i in getChildrenByName(getChildByName(namespaceNode, "grammar"), "define") if i.getAttribute("name") == refName]: - block1.extend(factoryCreateElementMapInner(files, namespaceNode, define, nsNode)) + block1.update(factoryCreateElementMapInner(files, namespaceNode, define, nsNode)) else: block1 = block if len(block1): - ret.append(" /* ref: %s*/" % refName) - ret.extend(block1) + ret.update(block1) for elementNode in defineNode.getElementsByTagName("element"): resource = "" @@ -341,7 +340,7 @@ def factoryCreateElementMapInner(files, nsNode, defineNode, resourceNamespaceNod if len(resource): break if len(resource): - ret.append(" (*pMap)[%s] = CreateElement(RT_%s, %s);" % (fastToken(elementNode), resource, idForRef(nsNode, getChildByName(elementNode, "ref")))) + ret[fastToken(elementNode)] = " case %s: rOutResource = RT_%s; rOutElement = %s; break;" % (fastToken(elementNode), resource, idForRef(nsNode, getChildByName(elementNode, "ref"))) return ret @@ -354,31 +353,44 @@ def factoryCreateElementMapFromStart(files, nsNode): block = factoryCreateElementMapInner(files, nsNode, defineNode) print(" /* start: %s*/" % startName) if block: - print("\n".join(block)) - print(""" break; - } - - return pMap; -}""") - print() + for k in block.keys(): + print(block[k]) def factoryCreateElementMap(files, nsNode): - print("""CreateElementMapPointer OOXMLFactory_%s::createCreateElementMap(Id nId) + print("""bool OOXMLFactory_%s::getElementId(Id nDefine, Id nId, ResourceType_t& rOutResource, Id& rOutElement) { - CreateElementMapPointer pMap(new CreateElementMap()); + (void) rOutResource; + (void) rOutElement; - switch (nId) + switch (nDefine) {""" % nsToLabel(nsNode)) for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"): - inner = "\n".join(factoryCreateElementMapInner(files, nsNode, defineNode)) + inner = factoryCreateElementMapInner(files, nsNode, defineNode) if len(inner): print(" case %s:" % idForDefine(nsNode, defineNode)) - print(inner) + print(" switch (nId)") + print(" {") + for k in inner.keys(): + print(inner[k]) + print(" default: return false;") + print(" }") + print(" return true;") print(" break;") print(" default:") + print(" switch (nId)") + print(" {") factoryCreateElementMapFromStart(files, nsNode) + print(""" default: return false; + } + return true; + break; + } + + return false; +} +""") # factoryActions |