diff --git a/cocos/2d/actions/CCAction.cpp b/cocos/2d/CCAction.cpp similarity index 100% rename from cocos/2d/actions/CCAction.cpp rename to cocos/2d/CCAction.cpp diff --git a/cocos/2d/actions/CCAction.h b/cocos/2d/CCAction.h similarity index 100% rename from cocos/2d/actions/CCAction.h rename to cocos/2d/CCAction.h diff --git a/cocos/2d/actions/CCActionCamera.cpp b/cocos/2d/CCActionCamera.cpp similarity index 100% rename from cocos/2d/actions/CCActionCamera.cpp rename to cocos/2d/CCActionCamera.cpp diff --git a/cocos/2d/actions/CCActionCamera.h b/cocos/2d/CCActionCamera.h similarity index 100% rename from cocos/2d/actions/CCActionCamera.h rename to cocos/2d/CCActionCamera.h diff --git a/cocos/2d/actions/CCActionCatmullRom.cpp b/cocos/2d/CCActionCatmullRom.cpp similarity index 100% rename from cocos/2d/actions/CCActionCatmullRom.cpp rename to cocos/2d/CCActionCatmullRom.cpp diff --git a/cocos/2d/actions/CCActionCatmullRom.h b/cocos/2d/CCActionCatmullRom.h similarity index 100% rename from cocos/2d/actions/CCActionCatmullRom.h rename to cocos/2d/CCActionCatmullRom.h diff --git a/cocos/2d/actions/CCActionEase.cpp b/cocos/2d/CCActionEase.cpp similarity index 100% rename from cocos/2d/actions/CCActionEase.cpp rename to cocos/2d/CCActionEase.cpp diff --git a/cocos/2d/actions/CCActionEase.h b/cocos/2d/CCActionEase.h similarity index 100% rename from cocos/2d/actions/CCActionEase.h rename to cocos/2d/CCActionEase.h diff --git a/cocos/2d/actions/CCActionGrid.cpp b/cocos/2d/CCActionGrid.cpp similarity index 100% rename from cocos/2d/actions/CCActionGrid.cpp rename to cocos/2d/CCActionGrid.cpp diff --git a/cocos/2d/actions/CCActionGrid.h b/cocos/2d/CCActionGrid.h similarity index 100% rename from cocos/2d/actions/CCActionGrid.h rename to cocos/2d/CCActionGrid.h diff --git a/cocos/2d/actions/CCActionGrid3D.cpp b/cocos/2d/CCActionGrid3D.cpp similarity index 100% rename from cocos/2d/actions/CCActionGrid3D.cpp rename to cocos/2d/CCActionGrid3D.cpp diff --git a/cocos/2d/actions/CCActionGrid3D.h b/cocos/2d/CCActionGrid3D.h similarity index 100% rename from cocos/2d/actions/CCActionGrid3D.h rename to cocos/2d/CCActionGrid3D.h diff --git a/cocos/2d/actions/CCActionInstant.cpp b/cocos/2d/CCActionInstant.cpp similarity index 100% rename from cocos/2d/actions/CCActionInstant.cpp rename to cocos/2d/CCActionInstant.cpp diff --git a/cocos/2d/actions/CCActionInstant.h b/cocos/2d/CCActionInstant.h similarity index 100% rename from cocos/2d/actions/CCActionInstant.h rename to cocos/2d/CCActionInstant.h diff --git a/cocos/2d/actions/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp similarity index 100% rename from cocos/2d/actions/CCActionInterval.cpp rename to cocos/2d/CCActionInterval.cpp diff --git a/cocos/2d/actions/CCActionInterval.h b/cocos/2d/CCActionInterval.h similarity index 100% rename from cocos/2d/actions/CCActionInterval.h rename to cocos/2d/CCActionInterval.h diff --git a/cocos/2d/actions/CCActionManager.cpp b/cocos/2d/CCActionManager.cpp similarity index 100% rename from cocos/2d/actions/CCActionManager.cpp rename to cocos/2d/CCActionManager.cpp diff --git a/cocos/2d/actions/CCActionManager.h b/cocos/2d/CCActionManager.h similarity index 100% rename from cocos/2d/actions/CCActionManager.h rename to cocos/2d/CCActionManager.h diff --git a/cocos/2d/actions/CCActionPageTurn3D.cpp b/cocos/2d/CCActionPageTurn3D.cpp similarity index 100% rename from cocos/2d/actions/CCActionPageTurn3D.cpp rename to cocos/2d/CCActionPageTurn3D.cpp diff --git a/cocos/2d/actions/CCActionPageTurn3D.h b/cocos/2d/CCActionPageTurn3D.h similarity index 100% rename from cocos/2d/actions/CCActionPageTurn3D.h rename to cocos/2d/CCActionPageTurn3D.h diff --git a/cocos/2d/actions/CCActionProgressTimer.cpp b/cocos/2d/CCActionProgressTimer.cpp similarity index 100% rename from cocos/2d/actions/CCActionProgressTimer.cpp rename to cocos/2d/CCActionProgressTimer.cpp diff --git a/cocos/2d/actions/CCActionProgressTimer.h b/cocos/2d/CCActionProgressTimer.h similarity index 100% rename from cocos/2d/actions/CCActionProgressTimer.h rename to cocos/2d/CCActionProgressTimer.h diff --git a/cocos/2d/actions/CCActionTiledGrid.cpp b/cocos/2d/CCActionTiledGrid.cpp similarity index 100% rename from cocos/2d/actions/CCActionTiledGrid.cpp rename to cocos/2d/CCActionTiledGrid.cpp diff --git a/cocos/2d/actions/CCActionTiledGrid.h b/cocos/2d/CCActionTiledGrid.h similarity index 100% rename from cocos/2d/actions/CCActionTiledGrid.h rename to cocos/2d/CCActionTiledGrid.h diff --git a/cocos/2d/actions/CCActionTween.cpp b/cocos/2d/CCActionTween.cpp similarity index 100% rename from cocos/2d/actions/CCActionTween.cpp rename to cocos/2d/CCActionTween.cpp diff --git a/cocos/2d/actions/CCActionTween.h b/cocos/2d/CCActionTween.h similarity index 100% rename from cocos/2d/actions/CCActionTween.h rename to cocos/2d/CCActionTween.h diff --git a/cocos/2d/sprite-nodes/CCAnimation.cpp b/cocos/2d/CCAnimation.cpp similarity index 100% rename from cocos/2d/sprite-nodes/CCAnimation.cpp rename to cocos/2d/CCAnimation.cpp diff --git a/cocos/2d/sprite-nodes/CCAnimation.h b/cocos/2d/CCAnimation.h similarity index 100% rename from cocos/2d/sprite-nodes/CCAnimation.h rename to cocos/2d/CCAnimation.h diff --git a/cocos/2d/sprite-nodes/CCAnimationCache.cpp b/cocos/2d/CCAnimationCache.cpp similarity index 100% rename from cocos/2d/sprite-nodes/CCAnimationCache.cpp rename to cocos/2d/CCAnimationCache.cpp diff --git a/cocos/2d/sprite-nodes/CCAnimationCache.h b/cocos/2d/CCAnimationCache.h similarity index 100% rename from cocos/2d/sprite-nodes/CCAnimationCache.h rename to cocos/2d/CCAnimationCache.h diff --git a/cocos/2d/base-nodes/CCAtlasNode.cpp b/cocos/2d/CCAtlasNode.cpp similarity index 100% rename from cocos/2d/base-nodes/CCAtlasNode.cpp rename to cocos/2d/CCAtlasNode.cpp diff --git a/cocos/2d/base-nodes/CCAtlasNode.h b/cocos/2d/CCAtlasNode.h similarity index 100% rename from cocos/2d/base-nodes/CCAtlasNode.h rename to cocos/2d/CCAtlasNode.h diff --git a/cocos/2d/misc-nodes/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp similarity index 100% rename from cocos/2d/misc-nodes/CCClippingNode.cpp rename to cocos/2d/CCClippingNode.cpp diff --git a/cocos/2d/misc-nodes/CCClippingNode.h b/cocos/2d/CCClippingNode.h similarity index 100% rename from cocos/2d/misc-nodes/CCClippingNode.h rename to cocos/2d/CCClippingNode.h diff --git a/cocos/2d/support/component/CCComponent.cpp b/cocos/2d/CCComponent.cpp similarity index 100% rename from cocos/2d/support/component/CCComponent.cpp rename to cocos/2d/CCComponent.cpp diff --git a/cocos/2d/support/component/CCComponent.h b/cocos/2d/CCComponent.h similarity index 100% rename from cocos/2d/support/component/CCComponent.h rename to cocos/2d/CCComponent.h diff --git a/cocos/2d/support/component/CCComponentContainer.cpp b/cocos/2d/CCComponentContainer.cpp similarity index 100% rename from cocos/2d/support/component/CCComponentContainer.cpp rename to cocos/2d/CCComponentContainer.cpp diff --git a/cocos/2d/support/component/CCComponentContainer.h b/cocos/2d/CCComponentContainer.h similarity index 100% rename from cocos/2d/support/component/CCComponentContainer.h rename to cocos/2d/CCComponentContainer.h diff --git a/cocos/2d/include/CCDeprecated.h b/cocos/2d/CCDeprecated.h similarity index 100% rename from cocos/2d/include/CCDeprecated.h rename to cocos/2d/CCDeprecated.h diff --git a/cocos/2d/draw-nodes/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp similarity index 100% rename from cocos/2d/draw-nodes/CCDrawNode.cpp rename to cocos/2d/CCDrawNode.cpp diff --git a/cocos/2d/draw-nodes/CCDrawNode.h b/cocos/2d/CCDrawNode.h similarity index 100% rename from cocos/2d/draw-nodes/CCDrawNode.h rename to cocos/2d/CCDrawNode.h diff --git a/cocos/2d/draw-nodes/CCDrawingPrimitives.cpp b/cocos/2d/CCDrawingPrimitives.cpp similarity index 100% rename from cocos/2d/draw-nodes/CCDrawingPrimitives.cpp rename to cocos/2d/CCDrawingPrimitives.cpp diff --git a/cocos/2d/draw-nodes/CCDrawingPrimitives.h b/cocos/2d/CCDrawingPrimitives.h similarity index 100% rename from cocos/2d/draw-nodes/CCDrawingPrimitives.h rename to cocos/2d/CCDrawingPrimitives.h diff --git a/cocos/2d/event-dispatcher/CCEvent.cpp b/cocos/2d/CCEvent.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCEvent.cpp rename to cocos/2d/CCEvent.cpp diff --git a/cocos/2d/event-dispatcher/CCEvent.h b/cocos/2d/CCEvent.h similarity index 100% rename from cocos/2d/event-dispatcher/CCEvent.h rename to cocos/2d/CCEvent.h diff --git a/cocos/2d/event-dispatcher/CCEventAcceleration.cpp b/cocos/2d/CCEventAcceleration.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCEventAcceleration.cpp rename to cocos/2d/CCEventAcceleration.cpp diff --git a/cocos/2d/event-dispatcher/CCEventAcceleration.h b/cocos/2d/CCEventAcceleration.h similarity index 100% rename from cocos/2d/event-dispatcher/CCEventAcceleration.h rename to cocos/2d/CCEventAcceleration.h diff --git a/cocos/2d/event-dispatcher/CCEventCustom.cpp b/cocos/2d/CCEventCustom.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCEventCustom.cpp rename to cocos/2d/CCEventCustom.cpp diff --git a/cocos/2d/event-dispatcher/CCEventCustom.h b/cocos/2d/CCEventCustom.h similarity index 100% rename from cocos/2d/event-dispatcher/CCEventCustom.h rename to cocos/2d/CCEventCustom.h diff --git a/cocos/2d/event-dispatcher/CCEventDispatcher.cpp b/cocos/2d/CCEventDispatcher.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCEventDispatcher.cpp rename to cocos/2d/CCEventDispatcher.cpp diff --git a/cocos/2d/event-dispatcher/CCEventDispatcher.h b/cocos/2d/CCEventDispatcher.h similarity index 100% rename from cocos/2d/event-dispatcher/CCEventDispatcher.h rename to cocos/2d/CCEventDispatcher.h diff --git a/cocos/2d/event-dispatcher/CCEventKeyboard.cpp b/cocos/2d/CCEventKeyboard.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCEventKeyboard.cpp rename to cocos/2d/CCEventKeyboard.cpp diff --git a/cocos/2d/event-dispatcher/CCEventKeyboard.h b/cocos/2d/CCEventKeyboard.h similarity index 100% rename from cocos/2d/event-dispatcher/CCEventKeyboard.h rename to cocos/2d/CCEventKeyboard.h diff --git a/cocos/2d/event-dispatcher/CCEventListener.cpp b/cocos/2d/CCEventListener.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCEventListener.cpp rename to cocos/2d/CCEventListener.cpp diff --git a/cocos/2d/event-dispatcher/CCEventListener.h b/cocos/2d/CCEventListener.h similarity index 100% rename from cocos/2d/event-dispatcher/CCEventListener.h rename to cocos/2d/CCEventListener.h diff --git a/cocos/2d/event-dispatcher/CCEventListenerAcceleration.cpp b/cocos/2d/CCEventListenerAcceleration.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCEventListenerAcceleration.cpp rename to cocos/2d/CCEventListenerAcceleration.cpp diff --git a/cocos/2d/event-dispatcher/CCEventListenerAcceleration.h b/cocos/2d/CCEventListenerAcceleration.h similarity index 100% rename from cocos/2d/event-dispatcher/CCEventListenerAcceleration.h rename to cocos/2d/CCEventListenerAcceleration.h diff --git a/cocos/2d/event-dispatcher/CCEventListenerCustom.cpp b/cocos/2d/CCEventListenerCustom.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCEventListenerCustom.cpp rename to cocos/2d/CCEventListenerCustom.cpp diff --git a/cocos/2d/event-dispatcher/CCEventListenerCustom.h b/cocos/2d/CCEventListenerCustom.h similarity index 100% rename from cocos/2d/event-dispatcher/CCEventListenerCustom.h rename to cocos/2d/CCEventListenerCustom.h diff --git a/cocos/2d/event-dispatcher/CCEventListenerKeyboard.cpp b/cocos/2d/CCEventListenerKeyboard.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCEventListenerKeyboard.cpp rename to cocos/2d/CCEventListenerKeyboard.cpp diff --git a/cocos/2d/event-dispatcher/CCEventListenerKeyboard.h b/cocos/2d/CCEventListenerKeyboard.h similarity index 100% rename from cocos/2d/event-dispatcher/CCEventListenerKeyboard.h rename to cocos/2d/CCEventListenerKeyboard.h diff --git a/cocos/2d/event-dispatcher/CCEventListenerTouch.cpp b/cocos/2d/CCEventListenerTouch.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCEventListenerTouch.cpp rename to cocos/2d/CCEventListenerTouch.cpp diff --git a/cocos/2d/event-dispatcher/CCEventListenerTouch.h b/cocos/2d/CCEventListenerTouch.h similarity index 100% rename from cocos/2d/event-dispatcher/CCEventListenerTouch.h rename to cocos/2d/CCEventListenerTouch.h diff --git a/cocos/2d/event-dispatcher/CCEventTouch.cpp b/cocos/2d/CCEventTouch.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCEventTouch.cpp rename to cocos/2d/CCEventTouch.cpp diff --git a/cocos/2d/event-dispatcher/CCEventTouch.h b/cocos/2d/CCEventTouch.h similarity index 100% rename from cocos/2d/event-dispatcher/CCEventTouch.h rename to cocos/2d/CCEventTouch.h diff --git a/cocos/2d/include/CCEventType.h b/cocos/2d/CCEventType.h similarity index 100% rename from cocos/2d/include/CCEventType.h rename to cocos/2d/CCEventType.h diff --git a/cocos/2d/label-nodes/CCFont.cpp b/cocos/2d/CCFont.cpp similarity index 100% rename from cocos/2d/label-nodes/CCFont.cpp rename to cocos/2d/CCFont.cpp diff --git a/cocos/2d/label-nodes/CCFont.h b/cocos/2d/CCFont.h similarity index 100% rename from cocos/2d/label-nodes/CCFont.h rename to cocos/2d/CCFont.h diff --git a/cocos/2d/label-nodes/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp similarity index 100% rename from cocos/2d/label-nodes/CCFontAtlas.cpp rename to cocos/2d/CCFontAtlas.cpp diff --git a/cocos/2d/label-nodes/CCFontAtlas.h b/cocos/2d/CCFontAtlas.h similarity index 100% rename from cocos/2d/label-nodes/CCFontAtlas.h rename to cocos/2d/CCFontAtlas.h diff --git a/cocos/2d/label-nodes/CCFontAtlasCache.cpp b/cocos/2d/CCFontAtlasCache.cpp similarity index 100% rename from cocos/2d/label-nodes/CCFontAtlasCache.cpp rename to cocos/2d/CCFontAtlasCache.cpp diff --git a/cocos/2d/label-nodes/CCFontAtlasCache.h b/cocos/2d/CCFontAtlasCache.h similarity index 100% rename from cocos/2d/label-nodes/CCFontAtlasCache.h rename to cocos/2d/CCFontAtlasCache.h diff --git a/cocos/2d/label-nodes/CCFontAtlasFactory.cpp b/cocos/2d/CCFontAtlasFactory.cpp similarity index 100% rename from cocos/2d/label-nodes/CCFontAtlasFactory.cpp rename to cocos/2d/CCFontAtlasFactory.cpp diff --git a/cocos/2d/label-nodes/CCFontAtlasFactory.h b/cocos/2d/CCFontAtlasFactory.h similarity index 100% rename from cocos/2d/label-nodes/CCFontAtlasFactory.h rename to cocos/2d/CCFontAtlasFactory.h diff --git a/cocos/2d/label-nodes/CCFontDefinition.cpp b/cocos/2d/CCFontDefinition.cpp similarity index 100% rename from cocos/2d/label-nodes/CCFontDefinition.cpp rename to cocos/2d/CCFontDefinition.cpp diff --git a/cocos/2d/label-nodes/CCFontDefinition.h b/cocos/2d/CCFontDefinition.h similarity index 100% rename from cocos/2d/label-nodes/CCFontDefinition.h rename to cocos/2d/CCFontDefinition.h diff --git a/cocos/2d/label-nodes/CCFontFNT.cpp b/cocos/2d/CCFontFNT.cpp similarity index 100% rename from cocos/2d/label-nodes/CCFontFNT.cpp rename to cocos/2d/CCFontFNT.cpp diff --git a/cocos/2d/label-nodes/CCFontFNT.h b/cocos/2d/CCFontFNT.h similarity index 100% rename from cocos/2d/label-nodes/CCFontFNT.h rename to cocos/2d/CCFontFNT.h diff --git a/cocos/2d/label-nodes/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp similarity index 100% rename from cocos/2d/label-nodes/CCFontFreeType.cpp rename to cocos/2d/CCFontFreeType.cpp diff --git a/cocos/2d/label-nodes/CCFontFreeType.h b/cocos/2d/CCFontFreeType.h similarity index 100% rename from cocos/2d/label-nodes/CCFontFreeType.h rename to cocos/2d/CCFontFreeType.h diff --git a/cocos/2d/base-nodes/CCGLBufferedNode.cpp b/cocos/2d/CCGLBufferedNode.cpp similarity index 100% rename from cocos/2d/base-nodes/CCGLBufferedNode.cpp rename to cocos/2d/CCGLBufferedNode.cpp diff --git a/cocos/2d/base-nodes/CCGLBufferedNode.h b/cocos/2d/CCGLBufferedNode.h similarity index 100% rename from cocos/2d/base-nodes/CCGLBufferedNode.h rename to cocos/2d/CCGLBufferedNode.h diff --git a/cocos/2d/shaders/CCGLProgram.cpp b/cocos/2d/CCGLProgram.cpp similarity index 100% rename from cocos/2d/shaders/CCGLProgram.cpp rename to cocos/2d/CCGLProgram.cpp diff --git a/cocos/2d/shaders/CCGLProgram.h b/cocos/2d/CCGLProgram.h similarity index 100% rename from cocos/2d/shaders/CCGLProgram.h rename to cocos/2d/CCGLProgram.h diff --git a/cocos/2d/effects/CCGrabber.cpp b/cocos/2d/CCGrabber.cpp similarity index 100% rename from cocos/2d/effects/CCGrabber.cpp rename to cocos/2d/CCGrabber.cpp diff --git a/cocos/2d/effects/CCGrabber.h b/cocos/2d/CCGrabber.h similarity index 100% rename from cocos/2d/effects/CCGrabber.h rename to cocos/2d/CCGrabber.h diff --git a/cocos/2d/effects/CCGrid.cpp b/cocos/2d/CCGrid.cpp similarity index 100% rename from cocos/2d/effects/CCGrid.cpp rename to cocos/2d/CCGrid.cpp diff --git a/cocos/2d/effects/CCGrid.h b/cocos/2d/CCGrid.h similarity index 100% rename from cocos/2d/effects/CCGrid.h rename to cocos/2d/CCGrid.h diff --git a/cocos/2d/text-input-node/CCIMEDelegate.h b/cocos/2d/CCIMEDelegate.h similarity index 100% rename from cocos/2d/text-input-node/CCIMEDelegate.h rename to cocos/2d/CCIMEDelegate.h diff --git a/cocos/2d/text-input-node/CCIMEDispatcher.cpp b/cocos/2d/CCIMEDispatcher.cpp similarity index 100% rename from cocos/2d/text-input-node/CCIMEDispatcher.cpp rename to cocos/2d/CCIMEDispatcher.cpp diff --git a/cocos/2d/text-input-node/CCIMEDispatcher.h b/cocos/2d/CCIMEDispatcher.h similarity index 100% rename from cocos/2d/text-input-node/CCIMEDispatcher.h rename to cocos/2d/CCIMEDispatcher.h diff --git a/cocos/2d/label-nodes/CCLabel.cpp b/cocos/2d/CCLabel.cpp similarity index 100% rename from cocos/2d/label-nodes/CCLabel.cpp rename to cocos/2d/CCLabel.cpp diff --git a/cocos/2d/label-nodes/CCLabel.h b/cocos/2d/CCLabel.h similarity index 100% rename from cocos/2d/label-nodes/CCLabel.h rename to cocos/2d/CCLabel.h diff --git a/cocos/2d/label-nodes/CCLabelAtlas.cpp b/cocos/2d/CCLabelAtlas.cpp similarity index 100% rename from cocos/2d/label-nodes/CCLabelAtlas.cpp rename to cocos/2d/CCLabelAtlas.cpp diff --git a/cocos/2d/label-nodes/CCLabelAtlas.h b/cocos/2d/CCLabelAtlas.h similarity index 100% rename from cocos/2d/label-nodes/CCLabelAtlas.h rename to cocos/2d/CCLabelAtlas.h diff --git a/cocos/2d/label-nodes/CCLabelBMFont.cpp b/cocos/2d/CCLabelBMFont.cpp similarity index 100% rename from cocos/2d/label-nodes/CCLabelBMFont.cpp rename to cocos/2d/CCLabelBMFont.cpp diff --git a/cocos/2d/label-nodes/CCLabelBMFont.h b/cocos/2d/CCLabelBMFont.h similarity index 100% rename from cocos/2d/label-nodes/CCLabelBMFont.h rename to cocos/2d/CCLabelBMFont.h diff --git a/cocos/2d/label-nodes/CCLabelTTF.cpp b/cocos/2d/CCLabelTTF.cpp similarity index 100% rename from cocos/2d/label-nodes/CCLabelTTF.cpp rename to cocos/2d/CCLabelTTF.cpp diff --git a/cocos/2d/label-nodes/CCLabelTTF.h b/cocos/2d/CCLabelTTF.h similarity index 100% rename from cocos/2d/label-nodes/CCLabelTTF.h rename to cocos/2d/CCLabelTTF.h diff --git a/cocos/2d/label-nodes/CCLabelTextFormatProtocol.h b/cocos/2d/CCLabelTextFormatProtocol.h similarity index 100% rename from cocos/2d/label-nodes/CCLabelTextFormatProtocol.h rename to cocos/2d/CCLabelTextFormatProtocol.h diff --git a/cocos/2d/label-nodes/CCLabelTextFormatter.cpp b/cocos/2d/CCLabelTextFormatter.cpp similarity index 100% rename from cocos/2d/label-nodes/CCLabelTextFormatter.cpp rename to cocos/2d/CCLabelTextFormatter.cpp diff --git a/cocos/2d/label-nodes/CCLabelTextFormatter.h b/cocos/2d/CCLabelTextFormatter.h similarity index 100% rename from cocos/2d/label-nodes/CCLabelTextFormatter.h rename to cocos/2d/CCLabelTextFormatter.h diff --git a/cocos/2d/layers-scenes-transitions-nodes/CCLayer.cpp b/cocos/2d/CCLayer.cpp similarity index 100% rename from cocos/2d/layers-scenes-transitions-nodes/CCLayer.cpp rename to cocos/2d/CCLayer.cpp diff --git a/cocos/2d/layers-scenes-transitions-nodes/CCLayer.h b/cocos/2d/CCLayer.h similarity index 100% rename from cocos/2d/layers-scenes-transitions-nodes/CCLayer.h rename to cocos/2d/CCLayer.h diff --git a/cocos/2d/menu-nodes/CCMenu.cpp b/cocos/2d/CCMenu.cpp similarity index 100% rename from cocos/2d/menu-nodes/CCMenu.cpp rename to cocos/2d/CCMenu.cpp diff --git a/cocos/2d/menu-nodes/CCMenu.h b/cocos/2d/CCMenu.h similarity index 100% rename from cocos/2d/menu-nodes/CCMenu.h rename to cocos/2d/CCMenu.h diff --git a/cocos/2d/menu-nodes/CCMenuItem.cpp b/cocos/2d/CCMenuItem.cpp similarity index 100% rename from cocos/2d/menu-nodes/CCMenuItem.cpp rename to cocos/2d/CCMenuItem.cpp diff --git a/cocos/2d/menu-nodes/CCMenuItem.h b/cocos/2d/CCMenuItem.h similarity index 100% rename from cocos/2d/menu-nodes/CCMenuItem.h rename to cocos/2d/CCMenuItem.h diff --git a/cocos/2d/misc-nodes/CCMotionStreak.cpp b/cocos/2d/CCMotionStreak.cpp similarity index 100% rename from cocos/2d/misc-nodes/CCMotionStreak.cpp rename to cocos/2d/CCMotionStreak.cpp diff --git a/cocos/2d/misc-nodes/CCMotionStreak.h b/cocos/2d/CCMotionStreak.h similarity index 100% rename from cocos/2d/misc-nodes/CCMotionStreak.h rename to cocos/2d/CCMotionStreak.h diff --git a/cocos/2d/base-nodes/CCNode.cpp b/cocos/2d/CCNode.cpp similarity index 100% rename from cocos/2d/base-nodes/CCNode.cpp rename to cocos/2d/CCNode.cpp diff --git a/cocos/2d/base-nodes/CCNode.h b/cocos/2d/CCNode.h similarity index 100% rename from cocos/2d/base-nodes/CCNode.h rename to cocos/2d/CCNode.h diff --git a/cocos/2d/support/CCNotificationCenter.cpp b/cocos/2d/CCNotificationCenter.cpp similarity index 100% rename from cocos/2d/support/CCNotificationCenter.cpp rename to cocos/2d/CCNotificationCenter.cpp diff --git a/cocos/2d/support/CCNotificationCenter.h b/cocos/2d/CCNotificationCenter.h similarity index 100% rename from cocos/2d/support/CCNotificationCenter.h rename to cocos/2d/CCNotificationCenter.h diff --git a/cocos/2d/tilemap-parallax-nodes/CCParallaxNode.cpp b/cocos/2d/CCParallaxNode.cpp similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCParallaxNode.cpp rename to cocos/2d/CCParallaxNode.cpp diff --git a/cocos/2d/tilemap-parallax-nodes/CCParallaxNode.h b/cocos/2d/CCParallaxNode.h similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCParallaxNode.h rename to cocos/2d/CCParallaxNode.h diff --git a/cocos/2d/particle-nodes/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp similarity index 100% rename from cocos/2d/particle-nodes/CCParticleBatchNode.cpp rename to cocos/2d/CCParticleBatchNode.cpp diff --git a/cocos/2d/particle-nodes/CCParticleBatchNode.h b/cocos/2d/CCParticleBatchNode.h similarity index 100% rename from cocos/2d/particle-nodes/CCParticleBatchNode.h rename to cocos/2d/CCParticleBatchNode.h diff --git a/cocos/2d/particle-nodes/CCParticleExamples.cpp b/cocos/2d/CCParticleExamples.cpp similarity index 100% rename from cocos/2d/particle-nodes/CCParticleExamples.cpp rename to cocos/2d/CCParticleExamples.cpp diff --git a/cocos/2d/particle-nodes/CCParticleExamples.h b/cocos/2d/CCParticleExamples.h similarity index 100% rename from cocos/2d/particle-nodes/CCParticleExamples.h rename to cocos/2d/CCParticleExamples.h diff --git a/cocos/2d/particle-nodes/CCParticleSystem.cpp b/cocos/2d/CCParticleSystem.cpp similarity index 100% rename from cocos/2d/particle-nodes/CCParticleSystem.cpp rename to cocos/2d/CCParticleSystem.cpp diff --git a/cocos/2d/particle-nodes/CCParticleSystem.h b/cocos/2d/CCParticleSystem.h similarity index 100% rename from cocos/2d/particle-nodes/CCParticleSystem.h rename to cocos/2d/CCParticleSystem.h diff --git a/cocos/2d/particle-nodes/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp similarity index 100% rename from cocos/2d/particle-nodes/CCParticleSystemQuad.cpp rename to cocos/2d/CCParticleSystemQuad.cpp diff --git a/cocos/2d/particle-nodes/CCParticleSystemQuad.h b/cocos/2d/CCParticleSystemQuad.h similarity index 100% rename from cocos/2d/particle-nodes/CCParticleSystemQuad.h rename to cocos/2d/CCParticleSystemQuad.h diff --git a/cocos/2d/support/CCProfiling.cpp b/cocos/2d/CCProfiling.cpp similarity index 100% rename from cocos/2d/support/CCProfiling.cpp rename to cocos/2d/CCProfiling.cpp diff --git a/cocos/2d/support/CCProfiling.h b/cocos/2d/CCProfiling.h similarity index 100% rename from cocos/2d/support/CCProfiling.h rename to cocos/2d/CCProfiling.h diff --git a/cocos/2d/misc-nodes/CCProgressTimer.cpp b/cocos/2d/CCProgressTimer.cpp similarity index 100% rename from cocos/2d/misc-nodes/CCProgressTimer.cpp rename to cocos/2d/CCProgressTimer.cpp diff --git a/cocos/2d/misc-nodes/CCProgressTimer.h b/cocos/2d/CCProgressTimer.h similarity index 100% rename from cocos/2d/misc-nodes/CCProgressTimer.h rename to cocos/2d/CCProgressTimer.h diff --git a/cocos/2d/include/CCProtocols.h b/cocos/2d/CCProtocols.h similarity index 100% rename from cocos/2d/include/CCProtocols.h rename to cocos/2d/CCProtocols.h diff --git a/cocos/2d/misc-nodes/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp similarity index 100% rename from cocos/2d/misc-nodes/CCRenderTexture.cpp rename to cocos/2d/CCRenderTexture.cpp diff --git a/cocos/2d/misc-nodes/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h similarity index 100% rename from cocos/2d/misc-nodes/CCRenderTexture.h rename to cocos/2d/CCRenderTexture.h diff --git a/cocos/2d/layers-scenes-transitions-nodes/CCScene.cpp b/cocos/2d/CCScene.cpp similarity index 100% rename from cocos/2d/layers-scenes-transitions-nodes/CCScene.cpp rename to cocos/2d/CCScene.cpp diff --git a/cocos/2d/layers-scenes-transitions-nodes/CCScene.h b/cocos/2d/CCScene.h similarity index 100% rename from cocos/2d/layers-scenes-transitions-nodes/CCScene.h rename to cocos/2d/CCScene.h diff --git a/cocos/2d/script-support/CCScriptSupport.cpp b/cocos/2d/CCScriptSupport.cpp similarity index 100% rename from cocos/2d/script-support/CCScriptSupport.cpp rename to cocos/2d/CCScriptSupport.cpp diff --git a/cocos/2d/script-support/CCScriptSupport.h b/cocos/2d/CCScriptSupport.h similarity index 100% rename from cocos/2d/script-support/CCScriptSupport.h rename to cocos/2d/CCScriptSupport.h diff --git a/cocos/2d/shaders/CCShaderCache.cpp b/cocos/2d/CCShaderCache.cpp similarity index 100% rename from cocos/2d/shaders/CCShaderCache.cpp rename to cocos/2d/CCShaderCache.cpp diff --git a/cocos/2d/shaders/CCShaderCache.h b/cocos/2d/CCShaderCache.h similarity index 100% rename from cocos/2d/shaders/CCShaderCache.h rename to cocos/2d/CCShaderCache.h diff --git a/cocos/2d/sprite-nodes/CCSprite.cpp b/cocos/2d/CCSprite.cpp similarity index 100% rename from cocos/2d/sprite-nodes/CCSprite.cpp rename to cocos/2d/CCSprite.cpp diff --git a/cocos/2d/sprite-nodes/CCSprite.h b/cocos/2d/CCSprite.h similarity index 100% rename from cocos/2d/sprite-nodes/CCSprite.h rename to cocos/2d/CCSprite.h diff --git a/cocos/2d/sprite-nodes/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp similarity index 100% rename from cocos/2d/sprite-nodes/CCSpriteBatchNode.cpp rename to cocos/2d/CCSpriteBatchNode.cpp diff --git a/cocos/2d/sprite-nodes/CCSpriteBatchNode.h b/cocos/2d/CCSpriteBatchNode.h similarity index 100% rename from cocos/2d/sprite-nodes/CCSpriteBatchNode.h rename to cocos/2d/CCSpriteBatchNode.h diff --git a/cocos/2d/sprite-nodes/CCSpriteFrame.cpp b/cocos/2d/CCSpriteFrame.cpp similarity index 100% rename from cocos/2d/sprite-nodes/CCSpriteFrame.cpp rename to cocos/2d/CCSpriteFrame.cpp diff --git a/cocos/2d/sprite-nodes/CCSpriteFrame.h b/cocos/2d/CCSpriteFrame.h similarity index 100% rename from cocos/2d/sprite-nodes/CCSpriteFrame.h rename to cocos/2d/CCSpriteFrame.h diff --git a/cocos/2d/sprite-nodes/CCSpriteFrameCache.cpp b/cocos/2d/CCSpriteFrameCache.cpp similarity index 100% rename from cocos/2d/sprite-nodes/CCSpriteFrameCache.cpp rename to cocos/2d/CCSpriteFrameCache.cpp diff --git a/cocos/2d/sprite-nodes/CCSpriteFrameCache.h b/cocos/2d/CCSpriteFrameCache.h similarity index 100% rename from cocos/2d/sprite-nodes/CCSpriteFrameCache.h rename to cocos/2d/CCSpriteFrameCache.h diff --git a/cocos/2d/tilemap-parallax-nodes/CCTMXLayer.cpp b/cocos/2d/CCTMXLayer.cpp similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCTMXLayer.cpp rename to cocos/2d/CCTMXLayer.cpp diff --git a/cocos/2d/tilemap-parallax-nodes/CCTMXLayer.h b/cocos/2d/CCTMXLayer.h similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCTMXLayer.h rename to cocos/2d/CCTMXLayer.h diff --git a/cocos/2d/tilemap-parallax-nodes/CCTMXObjectGroup.cpp b/cocos/2d/CCTMXObjectGroup.cpp similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCTMXObjectGroup.cpp rename to cocos/2d/CCTMXObjectGroup.cpp diff --git a/cocos/2d/tilemap-parallax-nodes/CCTMXObjectGroup.h b/cocos/2d/CCTMXObjectGroup.h similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCTMXObjectGroup.h rename to cocos/2d/CCTMXObjectGroup.h diff --git a/cocos/2d/tilemap-parallax-nodes/CCTMXTiledMap.cpp b/cocos/2d/CCTMXTiledMap.cpp similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCTMXTiledMap.cpp rename to cocos/2d/CCTMXTiledMap.cpp diff --git a/cocos/2d/tilemap-parallax-nodes/CCTMXTiledMap.h b/cocos/2d/CCTMXTiledMap.h similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCTMXTiledMap.h rename to cocos/2d/CCTMXTiledMap.h diff --git a/cocos/2d/tilemap-parallax-nodes/CCTMXXMLParser.cpp b/cocos/2d/CCTMXXMLParser.cpp similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCTMXXMLParser.cpp rename to cocos/2d/CCTMXXMLParser.cpp diff --git a/cocos/2d/tilemap-parallax-nodes/CCTMXXMLParser.h b/cocos/2d/CCTMXXMLParser.h similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCTMXXMLParser.h rename to cocos/2d/CCTMXXMLParser.h diff --git a/cocos/2d/text-input-node/CCTextFieldTTF.cpp b/cocos/2d/CCTextFieldTTF.cpp similarity index 100% rename from cocos/2d/text-input-node/CCTextFieldTTF.cpp rename to cocos/2d/CCTextFieldTTF.cpp diff --git a/cocos/2d/text-input-node/CCTextFieldTTF.h b/cocos/2d/CCTextFieldTTF.h similarity index 100% rename from cocos/2d/text-input-node/CCTextFieldTTF.h rename to cocos/2d/CCTextFieldTTF.h diff --git a/cocos/2d/label-nodes/CCTextImage.cpp b/cocos/2d/CCTextImage.cpp similarity index 100% rename from cocos/2d/label-nodes/CCTextImage.cpp rename to cocos/2d/CCTextImage.cpp diff --git a/cocos/2d/label-nodes/CCTextImage.h b/cocos/2d/CCTextImage.h similarity index 100% rename from cocos/2d/label-nodes/CCTextImage.h rename to cocos/2d/CCTextImage.h diff --git a/cocos/2d/textures/CCTexture2D.cpp b/cocos/2d/CCTexture2D.cpp similarity index 100% rename from cocos/2d/textures/CCTexture2D.cpp rename to cocos/2d/CCTexture2D.cpp diff --git a/cocos/2d/textures/CCTexture2D.h b/cocos/2d/CCTexture2D.h similarity index 100% rename from cocos/2d/textures/CCTexture2D.h rename to cocos/2d/CCTexture2D.h diff --git a/cocos/2d/textures/CCTextureAtlas.cpp b/cocos/2d/CCTextureAtlas.cpp similarity index 100% rename from cocos/2d/textures/CCTextureAtlas.cpp rename to cocos/2d/CCTextureAtlas.cpp diff --git a/cocos/2d/textures/CCTextureAtlas.h b/cocos/2d/CCTextureAtlas.h similarity index 100% rename from cocos/2d/textures/CCTextureAtlas.h rename to cocos/2d/CCTextureAtlas.h diff --git a/cocos/2d/textures/CCTextureCache.cpp b/cocos/2d/CCTextureCache.cpp similarity index 100% rename from cocos/2d/textures/CCTextureCache.cpp rename to cocos/2d/CCTextureCache.cpp diff --git a/cocos/2d/textures/CCTextureCache.h b/cocos/2d/CCTextureCache.h similarity index 100% rename from cocos/2d/textures/CCTextureCache.h rename to cocos/2d/CCTextureCache.h diff --git a/cocos/2d/tilemap-parallax-nodes/CCTileMapAtlas.cpp b/cocos/2d/CCTileMapAtlas.cpp similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCTileMapAtlas.cpp rename to cocos/2d/CCTileMapAtlas.cpp diff --git a/cocos/2d/tilemap-parallax-nodes/CCTileMapAtlas.h b/cocos/2d/CCTileMapAtlas.h similarity index 100% rename from cocos/2d/tilemap-parallax-nodes/CCTileMapAtlas.h rename to cocos/2d/CCTileMapAtlas.h diff --git a/cocos/2d/event-dispatcher/CCTouch.cpp b/cocos/2d/CCTouch.cpp similarity index 100% rename from cocos/2d/event-dispatcher/CCTouch.cpp rename to cocos/2d/CCTouch.cpp diff --git a/cocos/2d/event-dispatcher/CCTouch.h b/cocos/2d/CCTouch.h similarity index 100% rename from cocos/2d/event-dispatcher/CCTouch.h rename to cocos/2d/CCTouch.h diff --git a/cocos/2d/layers-scenes-transitions-nodes/CCTransition.cpp b/cocos/2d/CCTransition.cpp similarity index 100% rename from cocos/2d/layers-scenes-transitions-nodes/CCTransition.cpp rename to cocos/2d/CCTransition.cpp diff --git a/cocos/2d/layers-scenes-transitions-nodes/CCTransition.h b/cocos/2d/CCTransition.h similarity index 100% rename from cocos/2d/layers-scenes-transitions-nodes/CCTransition.h rename to cocos/2d/CCTransition.h diff --git a/cocos/2d/layers-scenes-transitions-nodes/CCTransitionPageTurn.cpp b/cocos/2d/CCTransitionPageTurn.cpp similarity index 100% rename from cocos/2d/layers-scenes-transitions-nodes/CCTransitionPageTurn.cpp rename to cocos/2d/CCTransitionPageTurn.cpp diff --git a/cocos/2d/layers-scenes-transitions-nodes/CCTransitionPageTurn.h b/cocos/2d/CCTransitionPageTurn.h similarity index 100% rename from cocos/2d/layers-scenes-transitions-nodes/CCTransitionPageTurn.h rename to cocos/2d/CCTransitionPageTurn.h diff --git a/cocos/2d/layers-scenes-transitions-nodes/CCTransitionProgress.cpp b/cocos/2d/CCTransitionProgress.cpp similarity index 100% rename from cocos/2d/layers-scenes-transitions-nodes/CCTransitionProgress.cpp rename to cocos/2d/CCTransitionProgress.cpp diff --git a/cocos/2d/layers-scenes-transitions-nodes/CCTransitionProgress.h b/cocos/2d/CCTransitionProgress.h similarity index 100% rename from cocos/2d/layers-scenes-transitions-nodes/CCTransitionProgress.h rename to cocos/2d/CCTransitionProgress.h diff --git a/cocos/2d/support/user_default/CCUserDefault.cpp b/cocos/2d/CCUserDefault.cpp similarity index 100% rename from cocos/2d/support/user_default/CCUserDefault.cpp rename to cocos/2d/CCUserDefault.cpp diff --git a/cocos/2d/support/user_default/CCUserDefault.h b/cocos/2d/CCUserDefault.h similarity index 100% rename from cocos/2d/support/user_default/CCUserDefault.h rename to cocos/2d/CCUserDefault.h diff --git a/cocos/2d/support/user_default/CCUserDefault.mm b/cocos/2d/CCUserDefault.mm similarity index 100% rename from cocos/2d/support/user_default/CCUserDefault.mm rename to cocos/2d/CCUserDefault.mm diff --git a/cocos/2d/support/user_default/CCUserDefaultAndroid.cpp b/cocos/2d/CCUserDefaultAndroid.cpp similarity index 100% rename from cocos/2d/support/user_default/CCUserDefaultAndroid.cpp rename to cocos/2d/CCUserDefaultAndroid.cpp diff --git a/cocos/2d/support/CCVertex.cpp b/cocos/2d/CCVertex.cpp similarity index 100% rename from cocos/2d/support/CCVertex.cpp rename to cocos/2d/CCVertex.cpp diff --git a/cocos/2d/support/CCVertex.h b/cocos/2d/CCVertex.h similarity index 100% rename from cocos/2d/support/CCVertex.h rename to cocos/2d/CCVertex.h diff --git a/cocos/2d/proj.linux/Makefile b/cocos/2d/Makefile similarity index 100% rename from cocos/2d/proj.linux/Makefile rename to cocos/2d/Makefile diff --git a/cocos/2d/support/image_support/TGAlib.cpp b/cocos/2d/TGAlib.cpp similarity index 100% rename from cocos/2d/support/image_support/TGAlib.cpp rename to cocos/2d/TGAlib.cpp diff --git a/cocos/2d/support/image_support/TGAlib.h b/cocos/2d/TGAlib.h similarity index 100% rename from cocos/2d/support/image_support/TGAlib.h rename to cocos/2d/TGAlib.h diff --git a/cocos/2d/support/TransformUtils.cpp b/cocos/2d/TransformUtils.cpp similarity index 100% rename from cocos/2d/support/TransformUtils.cpp rename to cocos/2d/TransformUtils.cpp diff --git a/cocos/2d/support/TransformUtils.h b/cocos/2d/TransformUtils.h similarity index 100% rename from cocos/2d/support/TransformUtils.h rename to cocos/2d/TransformUtils.h diff --git a/cocos/2d/support/zip_support/ZipUtils.cpp b/cocos/2d/ZipUtils.cpp similarity index 100% rename from cocos/2d/support/zip_support/ZipUtils.cpp rename to cocos/2d/ZipUtils.cpp diff --git a/cocos/2d/support/zip_support/ZipUtils.h b/cocos/2d/ZipUtils.h similarity index 100% rename from cocos/2d/support/zip_support/ZipUtils.h rename to cocos/2d/ZipUtils.h diff --git a/cocos/2d/support/base64.cpp b/cocos/2d/base64.cpp similarity index 100% rename from cocos/2d/support/base64.cpp rename to cocos/2d/base64.cpp diff --git a/cocos/2d/support/base64.h b/cocos/2d/base64.h similarity index 100% rename from cocos/2d/support/base64.h rename to cocos/2d/base64.h diff --git a/cocos/2d/support/data_support/ccCArray.cpp b/cocos/2d/ccCArray.cpp similarity index 100% rename from cocos/2d/support/data_support/ccCArray.cpp rename to cocos/2d/ccCArray.cpp diff --git a/cocos/2d/support/data_support/ccCArray.h b/cocos/2d/ccCArray.h similarity index 100% rename from cocos/2d/support/data_support/ccCArray.h rename to cocos/2d/ccCArray.h diff --git a/cocos/2d/include/ccConfig.h b/cocos/2d/ccConfig.h similarity index 100% rename from cocos/2d/include/ccConfig.h rename to cocos/2d/ccConfig.h diff --git a/cocos/2d/shaders/ccGLStateCache.cpp b/cocos/2d/ccGLStateCache.cpp similarity index 100% rename from cocos/2d/shaders/ccGLStateCache.cpp rename to cocos/2d/ccGLStateCache.cpp diff --git a/cocos/2d/shaders/ccGLStateCache.h b/cocos/2d/ccGLStateCache.h similarity index 100% rename from cocos/2d/shaders/ccGLStateCache.h rename to cocos/2d/ccGLStateCache.h diff --git a/cocos/2d/include/ccMacros.h b/cocos/2d/ccMacros.h similarity index 100% rename from cocos/2d/include/ccMacros.h rename to cocos/2d/ccMacros.h diff --git a/cocos/2d/shaders/ccShaderEx_SwitchMask_frag.h b/cocos/2d/ccShaderEx_SwitchMask_frag.h similarity index 100% rename from cocos/2d/shaders/ccShaderEx_SwitchMask_frag.h rename to cocos/2d/ccShaderEx_SwitchMask_frag.h diff --git a/cocos/2d/shaders/ccShader_PositionColorLengthTexture_frag.h b/cocos/2d/ccShader_PositionColorLengthTexture_frag.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionColorLengthTexture_frag.h rename to cocos/2d/ccShader_PositionColorLengthTexture_frag.h diff --git a/cocos/2d/shaders/ccShader_PositionColorLengthTexture_vert.h b/cocos/2d/ccShader_PositionColorLengthTexture_vert.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionColorLengthTexture_vert.h rename to cocos/2d/ccShader_PositionColorLengthTexture_vert.h diff --git a/cocos/2d/shaders/ccShader_PositionColor_frag.h b/cocos/2d/ccShader_PositionColor_frag.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionColor_frag.h rename to cocos/2d/ccShader_PositionColor_frag.h diff --git a/cocos/2d/shaders/ccShader_PositionColor_vert.h b/cocos/2d/ccShader_PositionColor_vert.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionColor_vert.h rename to cocos/2d/ccShader_PositionColor_vert.h diff --git a/cocos/2d/shaders/ccShader_PositionTextureA8Color_frag.h b/cocos/2d/ccShader_PositionTextureA8Color_frag.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionTextureA8Color_frag.h rename to cocos/2d/ccShader_PositionTextureA8Color_frag.h diff --git a/cocos/2d/shaders/ccShader_PositionTextureA8Color_vert.h b/cocos/2d/ccShader_PositionTextureA8Color_vert.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionTextureA8Color_vert.h rename to cocos/2d/ccShader_PositionTextureA8Color_vert.h diff --git a/cocos/2d/shaders/ccShader_PositionTextureColorAlphaTest_frag.h b/cocos/2d/ccShader_PositionTextureColorAlphaTest_frag.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionTextureColorAlphaTest_frag.h rename to cocos/2d/ccShader_PositionTextureColorAlphaTest_frag.h diff --git a/cocos/2d/shaders/ccShader_PositionTextureColor_frag.h b/cocos/2d/ccShader_PositionTextureColor_frag.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionTextureColor_frag.h rename to cocos/2d/ccShader_PositionTextureColor_frag.h diff --git a/cocos/2d/shaders/ccShader_PositionTextureColor_vert.h b/cocos/2d/ccShader_PositionTextureColor_vert.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionTextureColor_vert.h rename to cocos/2d/ccShader_PositionTextureColor_vert.h diff --git a/cocos/2d/shaders/ccShader_PositionTexture_frag.h b/cocos/2d/ccShader_PositionTexture_frag.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionTexture_frag.h rename to cocos/2d/ccShader_PositionTexture_frag.h diff --git a/cocos/2d/shaders/ccShader_PositionTexture_uColor_frag.h b/cocos/2d/ccShader_PositionTexture_uColor_frag.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionTexture_uColor_frag.h rename to cocos/2d/ccShader_PositionTexture_uColor_frag.h diff --git a/cocos/2d/shaders/ccShader_PositionTexture_uColor_vert.h b/cocos/2d/ccShader_PositionTexture_uColor_vert.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionTexture_uColor_vert.h rename to cocos/2d/ccShader_PositionTexture_uColor_vert.h diff --git a/cocos/2d/shaders/ccShader_PositionTexture_vert.h b/cocos/2d/ccShader_PositionTexture_vert.h similarity index 100% rename from cocos/2d/shaders/ccShader_PositionTexture_vert.h rename to cocos/2d/ccShader_PositionTexture_vert.h diff --git a/cocos/2d/shaders/ccShader_Position_uColor_frag.h b/cocos/2d/ccShader_Position_uColor_frag.h similarity index 100% rename from cocos/2d/shaders/ccShader_Position_uColor_frag.h rename to cocos/2d/ccShader_Position_uColor_frag.h diff --git a/cocos/2d/shaders/ccShader_Position_uColor_vert.h b/cocos/2d/ccShader_Position_uColor_vert.h similarity index 100% rename from cocos/2d/shaders/ccShader_Position_uColor_vert.h rename to cocos/2d/ccShader_Position_uColor_vert.h diff --git a/cocos/2d/shaders/ccShaders.cpp b/cocos/2d/ccShaders.cpp similarity index 100% rename from cocos/2d/shaders/ccShaders.cpp rename to cocos/2d/ccShaders.cpp diff --git a/cocos/2d/shaders/ccShaders.h b/cocos/2d/ccShaders.h similarity index 100% rename from cocos/2d/shaders/ccShaders.h rename to cocos/2d/ccShaders.h diff --git a/cocos/2d/include/ccTypes.h b/cocos/2d/ccTypes.h similarity index 100% rename from cocos/2d/include/ccTypes.h rename to cocos/2d/ccTypes.h diff --git a/cocos/2d/support/ccUTF8.cpp b/cocos/2d/ccUTF8.cpp similarity index 100% rename from cocos/2d/support/ccUTF8.cpp rename to cocos/2d/ccUTF8.cpp diff --git a/cocos/2d/support/ccUTF8.h b/cocos/2d/ccUTF8.h similarity index 100% rename from cocos/2d/support/ccUTF8.h rename to cocos/2d/ccUTF8.h diff --git a/cocos/2d/support/ccUtils.h b/cocos/2d/ccUtils.h similarity index 100% rename from cocos/2d/support/ccUtils.h rename to cocos/2d/ccUtils.h diff --git a/cocos/2d/include/cocos2d.h b/cocos/2d/cocos2d.h similarity index 100% rename from cocos/2d/include/cocos2d.h rename to cocos/2d/cocos2d.h diff --git a/cocos/2d/proj.win32/cocos2d.vcxproj b/cocos/2d/cocos2d.vcxproj similarity index 100% rename from cocos/2d/proj.win32/cocos2d.vcxproj rename to cocos/2d/cocos2d.vcxproj diff --git a/cocos/2d/proj.win32/cocos2d.vcxproj.filters b/cocos/2d/cocos2d.vcxproj.filters similarity index 100% rename from cocos/2d/proj.win32/cocos2d.vcxproj.filters rename to cocos/2d/cocos2d.vcxproj.filters diff --git a/cocos/2d/proj.win32/cocos2d.vcxproj.user b/cocos/2d/cocos2d.vcxproj.user similarity index 100% rename from cocos/2d/proj.win32/cocos2d.vcxproj.user rename to cocos/2d/cocos2d.vcxproj.user diff --git a/cocos/2d/proj.linux/cocos2dx.mk b/cocos/2d/cocos2dx.mk similarity index 100% rename from cocos/2d/proj.linux/cocos2dx.mk rename to cocos/2d/cocos2dx.mk diff --git a/cocos/2d/proj.win32/cocos2dx.props b/cocos/2d/cocos2dx.props similarity index 100% rename from cocos/2d/proj.win32/cocos2dx.props rename to cocos/2d/cocos2dx.props diff --git a/cocos/2d/particle-nodes/firePngData.h b/cocos/2d/firePngData.h similarity index 100% rename from cocos/2d/particle-nodes/firePngData.h rename to cocos/2d/firePngData.h diff --git a/cocos/2d/proj.linux/.cproject b/cocos/2d/proj.linux/.cproject deleted file mode 100755 index aaae232fb4..0000000000 --- a/cocos/2d/proj.linux/.cproject +++ /dev/null @@ -1,602 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cocos/2d/proj.linux/.project b/cocos/2d/proj.linux/.project deleted file mode 100755 index 8811b56dd0..0000000000 --- a/cocos/2d/proj.linux/.project +++ /dev/null @@ -1,256 +0,0 @@ - - - libcocos2d - - - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - clean,full,incremental, - - - ?name? - - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.autoBuildTarget - all - - - org.eclipse.cdt.make.core.buildArguments - - - - org.eclipse.cdt.make.core.buildCommand - make - - - org.eclipse.cdt.make.core.buildLocation - ${workspace_loc:/cocos2dx-base/Debug} - - - org.eclipse.cdt.make.core.cleanBuildTarget - clean - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.fullBuildTarget - all - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - true - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.core.ccnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - - - CCCamera.cpp - 1 - PARENT-1-PROJECT_LOC/CCCamera.cpp - - - CCConfiguration.cpp - 1 - PARENT-1-PROJECT_LOC/CCConfiguration.cpp - - - CCConfiguration.h - 1 - PARENT-1-PROJECT_LOC/CCConfiguration.h - - - ccFPSImages.c - 1 - PARENT-1-PROJECT_LOC/ccFPSImages.c - - - ccFPSImages.h - 1 - PARENT-1-PROJECT_LOC/ccFPSImages.h - - - ccTypes.cpp - 1 - PARENT-1-PROJECT_LOC/ccTypes.cpp - - - CCDirector.cpp - 1 - PARENT-1-PROJECT_LOC/CCDirector.cpp - - - CCScheduler.cpp - 1 - PARENT-1-PROJECT_LOC/CCScheduler.cpp - - - actions - 2 - PARENT-1-PROJECT_LOC/actions - - - base_nodes - 2 - PARENT-1-PROJECT_LOC/base_nodes - - - cocoa - 2 - PARENT-1-PROJECT_LOC/cocoa - - - cocos2d.cpp - 1 - PARENT-1-PROJECT_LOC/cocos2d.cpp - - - draw_nodes - 2 - PARENT-1-PROJECT_LOC/draw_nodes - - - effects - 2 - PARENT-1-PROJECT_LOC/effects - - - include - 2 - PARENT-1-PROJECT_LOC/include - - - kazmath - 2 - PARENT-1-PROJECT_LOC/kazmath - - - keypad_dispatcher - 2 - PARENT-1-PROJECT_LOC/keypad_dispatcher - - - keyboard_dispatcher - 2 - PARENT-1-PROJECT_LOC/keyboard_dispatcher - - - label_nodes - 2 - PARENT-1-PROJECT_LOC/label_nodes - - - layers_scenes_transitions_nodes - 2 - PARENT-1-PROJECT_LOC/layers_scenes_transitions_nodes - - - menu_nodes - 2 - PARENT-1-PROJECT_LOC/menu_nodes - - - misc_nodes - 2 - PARENT-1-PROJECT_LOC/misc_nodes - - - particle_nodes - 2 - PARENT-1-PROJECT_LOC/particle_nodes - - - platform - 2 - PARENT-1-PROJECT_LOC/platform - - - script_support - 2 - PARENT-1-PROJECT_LOC/script_support - - - shaders - 2 - PARENT-1-PROJECT_LOC/shaders - - - sprite_nodes - 2 - PARENT-1-PROJECT_LOC/sprite_nodes - - - support - 2 - PARENT-1-PROJECT_LOC/support - - - text_input_node - 2 - PARENT-1-PROJECT_LOC/text_input_node - - - textures - 2 - PARENT-1-PROJECT_LOC/textures - - - tilemap_parallax_nodes - 2 - PARENT-1-PROJECT_LOC/tilemap_parallax_nodes - - - touch_dispatcher - 2 - PARENT-1-PROJECT_LOC/touch_dispatcher - - - - - 1360135975775 - platform - 9 - - org.eclipse.ui.ide.multiFilter - 1.0-name-matches-true-false-linux - - - - diff --git a/cocos/2d/proj.linux/cocos2dx.prf b/cocos/2d/proj.linux/cocos2dx.prf deleted file mode 100644 index 1122180b53..0000000000 --- a/cocos/2d/proj.linux/cocos2dx.prf +++ /dev/null @@ -1,37 +0,0 @@ -################################################################################ -# Do not include this file in your project: see cocos2dx.pri. -################################################################################ - -linux { - # Use OpenAL in default QtCreator project. - isEmpty(COCOS2D_USE_FMOD):COCOS2D_USE_FMOD=0 - - # Variables used when building libraries. - CC_LIBRARY_DIR = $$PWD/../../lib/linux/release - CC_MAKE_FLAGS = -s - CONFIG(debug, debug|release) { - # Override in debug build. - CC_MAKE_FLAGS += DEBUG=1 - CC_LIBRARY_DIR = $$PWD/../../lib/linux/debug - } - contains(COCOS2D_MODULES,box2d) { - CC_MAKE_FLAGS += USE_BOX2D=1 - } - !equals(COCOS2D_USE_FMOD, 1) { - CC_MAKE_FLAGS += OPENAL=1 - } - - # We will compile cocos2d shared library on demand using Makefile. - build_cocos2d.name = Build cocos2d shared library - build_cocos2d.input = $$PWD/Makefile - build_cocos2d.output = $$CC_LIBRARY_DIR/libcocos2d.so - build_cocos2d.target = $$CC_LIBRARY_DIR/libcocos2d.so - build_cocos2d.CONFIG = no_link target_predeps - build_cocos2d.commands = cd $$PWD && make $$CC_MAKE_FLAGS ${QMAKE_FILE_IN} - - QMAKE_EXTRA_COMPILERS += build_cocos2d - QMAKE_EXTRA_TARGETS += build_cocos2d - - PRE_TARGETDEPS += $$CC_LIBRARY_DIR/libcocos2d.so - LIBS += -L$$CC_LIBRARY_DIR -lcocos2d -Wl,-rpath,\'$$CC_LIBRARY_DIR\' -} diff --git a/cocos/2d/proj.linux/cocos2dx.pri b/cocos/2d/proj.linux/cocos2dx.pri deleted file mode 100644 index 84bbb6d987..0000000000 --- a/cocos/2d/proj.linux/cocos2dx.pri +++ /dev/null @@ -1,70 +0,0 @@ - -################################################################################ -# -# If you want enable extra modules, set COCOS2D_MODULES variable before include -# this file, example: -# COCOS2D_MODULES += CocosDenshion -# COCOS2D_MODULES += extensions -# COCOS2D_MODULES += box2d -# or -# COCOS2D_MODULES += chipmunk -# note: you cannot include both box2d and chipmunk. -# -# By default, QtCreator project will use OpenAL audio backend (because FMOD is -# free only for non-commercial use). If you are legal FMOD user, set variable -# COCOS2D_USE_FMOD to use FMOD audio backend: -# COCOS2D_USE_FMOD = 1 -# -################################################################################ - -INCLUDEPATH += $$PWD/../ -INCLUDEPATH += $$PWD/../cocoa/ -INCLUDEPATH += $$PWD/../include/ -INCLUDEPATH += $$PWD/../platform/ -INCLUDEPATH += $$PWD/../kazmath/include - -*-msvc* { - # Use equivalents of -Wno-overloaded-virtual -Wno-unused-parameter. - QMAKE_CXXFLAGS_WARN_ON += /wd4263 /wd4100 -} else { - QMAKE_CXXFLAGS_WARN_ON += -Wno-ignored-qualifiers -Wno-overloaded-virtual -Wno-unused-parameter -Wno-unused-function - QMAKE_CXXFLAGS += -std=c++0x -} - -include($$PWD/cocos2dx.prf) - -linux { - DEFINES += LINUX - INCLUDEPATH += $$PWD/../platform/linux - LIBS += -lpthread -} - -contains(COCOS2D_MODULES,CocosDenshion) { - INCLUDEPATH += $$PWD/../../CocosDenshion/include - include($$PWD/../../CocosDenshion/proj.linux/CocosDenshion.prf) -} - -contains(COCOS2D_MODULES,extensions) { - INCLUDEPATH += $$PWD/../../extensions - LIBS += -lcurl - include($$PWD/../../extensions/proj.linux/extensions.prf) -} - -contains(COCOS2D_MODULES,box2d) { - INCLUDEPATH += $$PWD/../../external - include($$PWD/../../external/Box2D/proj.linux/box2d.prf) -} - -contains(COCOS2D_MODULES,chipmunk) { - contains(COCOS2D_MODULES,box2d):error("COCOS2D_MODULES cannot contain both box2d and chipmunk: choose one and remove another.") - - INCLUDEPATH += $$PWD/../../external/chipmunk/include/chipmunk - include($$PWD/../../external/chipmunk/proj.linux/chipmunk.prf) -} - -CONFIG(debug, debug|release) { - DEFINES += COCOS2D_DEBUG=1 -} -else { - DEFINES += COCOS2D_DEBUG=0 -} diff --git a/cocos/2d/support/ccUtils.cpp b/cocos/2d/support/ccUtils.cpp deleted file mode 100644 index d78324565b..0000000000 --- a/cocos/2d/support/ccUtils.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "ccUtils.h" - -namespace cocos2d { - -unsigned long ccNextPOT(unsigned long x) -{ - x = x - 1; - x = x | (x >> 1); - x = x | (x >> 2); - x = x | (x >> 4); - x = x | (x >> 8); - x = x | (x >>16); - return x + 1; -} - -} \ No newline at end of file diff --git a/cocos/2d/support/tinyxml2/tinyxml2.cpp b/cocos/2d/support/tinyxml2/tinyxml2.cpp deleted file mode 100644 index f181b9050c..0000000000 --- a/cocos/2d/support/tinyxml2/tinyxml2.cpp +++ /dev/null @@ -1,2101 +0,0 @@ -/* -Original code by Lee Thomason (www.grinninglizard.com) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - -#include "tinyxml2.h" - -#include // yes, this one new style header, is in the Android SDK. -# if defined(ANDROID_NDK) || (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY) -# include -#else -# include -#endif - -static const char LINE_FEED = (char)0x0a; // all line endings are normalized to LF -static const char LF = LINE_FEED; -static const char CARRIAGE_RETURN = (char)0x0d; // CR gets filtered out -static const char CR = CARRIAGE_RETURN; -static const char SINGLE_QUOTE = '\''; -static const char DOUBLE_QUOTE = '\"'; - -// Bunch of unicode info at: -// http://www.unicode.org/faq/utf_bom.html -// ef bb bf (Microsoft "lead bytes") - designates UTF-8 - -static const unsigned char TIXML_UTF_LEAD_0 = 0xefU; -static const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; -static const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; - - -#define DELETE_NODE( node ) { \ - if ( node ) { \ - MemPool* pool = node->_memPool; \ - node->~XMLNode(); \ - pool->Free( node ); \ - } \ - } -#define DELETE_ATTRIBUTE( attrib ) { \ - if ( attrib ) { \ - MemPool* pool = attrib->_memPool; \ - attrib->~XMLAttribute(); \ - pool->Free( attrib ); \ - } \ - } - -namespace tinyxml2 -{ - -struct Entity { - const char* pattern; - int length; - char value; -}; - -static const int NUM_ENTITIES = 5; -static const Entity entities[NUM_ENTITIES] = { - { "quot", 4, DOUBLE_QUOTE }, - { "amp", 3, '&' }, - { "apos", 4, SINGLE_QUOTE }, - { "lt", 2, '<' }, - { "gt", 2, '>' } -}; - - -StrPair::~StrPair() -{ - Reset(); -} - - -void StrPair::Reset() -{ - if ( _flags & NEEDS_DELETE ) { - delete [] _start; - } - _flags = 0; - _start = 0; - _end = 0; -} - - -void StrPair::SetStr( const char* str, int flags ) -{ - Reset(); - size_t len = strlen( str ); - _start = new char[ len+1 ]; - memcpy( _start, str, len+1 ); - _end = _start + len; - _flags = flags | NEEDS_DELETE; -} - - -char* StrPair::ParseText( char* p, const char* endTag, int strFlags ) -{ - TIXMLASSERT( endTag && *endTag ); - - char* start = p; // fixme: hides a member - char endChar = *endTag; - size_t length = strlen( endTag ); - - // Inner loop of text parsing. - while ( *p ) { - if ( *p == endChar && strncmp( p, endTag, length ) == 0 ) { - Set( start, p, strFlags ); - return p + length; - } - ++p; - } - return 0; -} - - -char* StrPair::ParseName( char* p ) -{ - char* start = p; - - if ( !start || !(*start) ) { - return 0; - } - - while( *p && ( - XMLUtil::IsAlphaNum( (unsigned char) *p ) - || *p == '_' - || *p == ':' - || (*p == '-' && p>start ) // can be in a name, but not lead it. - || (*p == '.' && p>start ) )) { // can be in a name, but not lead it. - ++p; - } - - if ( p > start ) { - Set( start, p, 0 ); - return p; - } - return 0; -} - - -void StrPair::CollapseWhitespace() -{ - // Trim leading space. - _start = XMLUtil::SkipWhiteSpace( _start ); - - if ( _start && *_start ) { - char* p = _start; // the read pointer - char* q = _start; // the write pointer - - while( *p ) { - if ( XMLUtil::IsWhiteSpace( *p )) { - p = XMLUtil::SkipWhiteSpace( p ); - if ( *p == 0 ) { - break; // don't write to q; this trims the trailing space. - } - *q = ' '; - ++q; - } - *q = *p; - ++q; - ++p; - } - *q = 0; - } -} - - -const char* StrPair::GetStr() -{ - if ( _flags & NEEDS_FLUSH ) { - *_end = 0; - _flags ^= NEEDS_FLUSH; - - if ( _flags ) { - char* p = _start; // the read pointer - char* q = _start; // the write pointer - - while( p < _end ) { - if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == CR ) { - // CR-LF pair becomes LF - // CR alone becomes LF - // LF-CR becomes LF - if ( *(p+1) == LF ) { - p += 2; - } - else { - ++p; - } - *q++ = LF; - } - else if ( (_flags & NEEDS_NEWLINE_NORMALIZATION) && *p == LF ) { - if ( *(p+1) == CR ) { - p += 2; - } - else { - ++p; - } - *q++ = LF; - } - else if ( (_flags & NEEDS_ENTITY_PROCESSING) && *p == '&' ) { - // Entities handled by tinyXML2: - // - special entities in the entity table [in/out] - // - numeric character reference [in] - // 中 or 中 - - if ( *(p+1) == '#' ) { - char buf[10] = { 0 }; - int len; - p = const_cast( XMLUtil::GetCharacterRef( p, buf, &len ) ); - for( int i=0; i(p); - // Check for BOM: - if ( *(pu+0) == TIXML_UTF_LEAD_0 - && *(pu+1) == TIXML_UTF_LEAD_1 - && *(pu+2) == TIXML_UTF_LEAD_2 ) { - *bom = true; - p += 3; - } - return p; -} - - -void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) -{ - const unsigned long BYTE_MASK = 0xBF; - const unsigned long BYTE_MARK = 0x80; - const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; - - if (input < 0x80) { - *length = 1; - } - else if ( input < 0x800 ) { - *length = 2; - } - else if ( input < 0x10000 ) { - *length = 3; - } - else if ( input < 0x200000 ) { - *length = 4; - } - else { - *length = 0; // This code won't covert this correctly anyway. - return; - } - - output += *length; - - // Scary scary fall throughs. - switch (*length) { - case 4: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 3: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 2: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 1: - --output; - *output = (char)(input | FIRST_BYTE_MARK[*length]); - default: - break; - } -} - - -const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length ) -{ - // Presume an entity, and pull it out. - *length = 0; - - if ( *(p+1) == '#' && *(p+2) ) { - unsigned long ucs = 0; - ptrdiff_t delta = 0; - unsigned mult = 1; - - if ( *(p+2) == 'x' ) { - // Hexadecimal. - if ( !*(p+3) ) { - return 0; - } - - const char* q = p+3; - q = strchr( q, ';' ); - - if ( !q || !*q ) { - return 0; - } - - delta = q-p; - --q; - - while ( *q != 'x' ) { - if ( *q >= '0' && *q <= '9' ) { - ucs += mult * (*q - '0'); - } - else if ( *q >= 'a' && *q <= 'f' ) { - ucs += mult * (*q - 'a' + 10); - } - else if ( *q >= 'A' && *q <= 'F' ) { - ucs += mult * (*q - 'A' + 10 ); - } - else { - return 0; - } - mult *= 16; - --q; - } - } - else { - // Decimal. - if ( !*(p+2) ) { - return 0; - } - - const char* q = p+2; - q = strchr( q, ';' ); - - if ( !q || !*q ) { - return 0; - } - - delta = q-p; - --q; - - while ( *q != '#' ) { - if ( *q >= '0' && *q <= '9' ) { - ucs += mult * (*q - '0'); - } - else { - return 0; - } - mult *= 10; - --q; - } - } - // convert the UCS to UTF-8 - ConvertUTF32ToUTF8( ucs, value, length ); - return p + delta + 1; - } - return p+1; -} - - -void XMLUtil::ToStr( int v, char* buffer, int bufferSize ) -{ - TIXML_SNPRINTF( buffer, bufferSize, "%d", v ); -} - - -void XMLUtil::ToStr( unsigned v, char* buffer, int bufferSize ) -{ - TIXML_SNPRINTF( buffer, bufferSize, "%u", v ); -} - - -void XMLUtil::ToStr( bool v, char* buffer, int bufferSize ) -{ - TIXML_SNPRINTF( buffer, bufferSize, "%d", v ? 1 : 0 ); -} - - -void XMLUtil::ToStr( float v, char* buffer, int bufferSize ) -{ - TIXML_SNPRINTF( buffer, bufferSize, "%g", v ); -} - - -void XMLUtil::ToStr( double v, char* buffer, int bufferSize ) -{ - TIXML_SNPRINTF( buffer, bufferSize, "%g", v ); -} - - -bool XMLUtil::ToInt( const char* str, int* value ) -{ - if ( TIXML_SSCANF( str, "%d", value ) == 1 ) { - return true; - } - return false; -} - -bool XMLUtil::ToUnsigned( const char* str, unsigned *value ) -{ - if ( TIXML_SSCANF( str, "%u", value ) == 1 ) { - return true; - } - return false; -} - -bool XMLUtil::ToBool( const char* str, bool* value ) -{ - int ival = 0; - if ( ToInt( str, &ival )) { - *value = (ival==0) ? false : true; - return true; - } - if ( StringEqual( str, "true" ) ) { - *value = true; - return true; - } - else if ( StringEqual( str, "false" ) ) { - *value = false; - return true; - } - return false; -} - - -bool XMLUtil::ToFloat( const char* str, float* value ) -{ - if ( TIXML_SSCANF( str, "%f", value ) == 1 ) { - return true; - } - return false; -} - -bool XMLUtil::ToDouble( const char* str, double* value ) -{ - if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) { - return true; - } - return false; -} - - -char* XMLDocument::Identify( char* p, XMLNode** node ) -{ - XMLNode* returnNode = 0; - char* start = p; - p = XMLUtil::SkipWhiteSpace( p ); - if( !p || !*p ) { - return p; - } - - // What is this thing? - // - Elements start with a letter or underscore, but xml is reserved. - // - Comments: - // - // With a special case: - // - // - // - // - // Where the closing element (/foo) *must* be the next thing after the opening - // element, and the names must match. BUT the tricky bit is that the closing - // element will be read by the child. - // - // 'endTag' is the end tag for this node, it is returned by a call to a child. - // 'parentEnd' is the end tag for the parent, which is filled in and returned. - - while( p && *p ) { - XMLNode* node = 0; - - p = _document->Identify( p, &node ); - if ( p == 0 || node == 0 ) { - break; - } - - StrPair endTag; - p = node->ParseDeep( p, &endTag ); - if ( !p ) { - DELETE_NODE( node ); - node = 0; - if ( !_document->Error() ) { - _document->SetError( XML_ERROR_PARSING, 0, 0 ); - } - break; - } - - // We read the end tag. Return it to the parent. - if ( node->ToElement() && node->ToElement()->ClosingType() == XMLElement::CLOSING ) { - if ( parentEnd ) { - *parentEnd = static_cast(node)->_value; - } - node->_memPool->SetTracked(); // created and then immediately deleted. - DELETE_NODE( node ); - return p; - } - - // Handle an end tag returned to this level. - // And handle a bunch of annoying errors. - XMLElement* ele = node->ToElement(); - if ( ele ) { - if ( endTag.Empty() && ele->ClosingType() == XMLElement::OPEN ) { - _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); - p = 0; - } - else if ( !endTag.Empty() && ele->ClosingType() != XMLElement::OPEN ) { - _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); - p = 0; - } - else if ( !endTag.Empty() ) { - if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() )) { - _document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 ); - p = 0; - } - } - } - if ( p == 0 ) { - DELETE_NODE( node ); - node = 0; - } - if ( node ) { - this->InsertEndChild( node ); - } - } - return 0; -} - -// --------- XMLText ---------- // -char* XMLText::ParseDeep( char* p, StrPair* ) -{ - const char* start = p; - if ( this->CData() ) { - p = _value.ParseText( p, "]]>", StrPair::NEEDS_NEWLINE_NORMALIZATION ); - if ( !p ) { - _document->SetError( XML_ERROR_PARSING_CDATA, start, 0 ); - } - return p; - } - else { - int flags = _document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES; - if ( _document->WhitespaceMode() == COLLAPSE_WHITESPACE ) { - flags |= StrPair::COLLAPSE_WHITESPACE; - } - - p = _value.ParseText( p, "<", flags ); - if ( !p ) { - _document->SetError( XML_ERROR_PARSING_TEXT, start, 0 ); - } - if ( p && *p ) { - return p-1; - } - } - return 0; -} - - -XMLNode* XMLText::ShallowClone( XMLDocument* doc ) const -{ - if ( !doc ) { - doc = _document; - } - XMLText* text = doc->NewText( Value() ); // fixme: this will always allocate memory. Intern? - text->SetCData( this->CData() ); - return text; -} - - -bool XMLText::ShallowEqual( const XMLNode* compare ) const -{ - return ( compare->ToText() && XMLUtil::StringEqual( compare->ToText()->Value(), Value() )); -} - - -bool XMLText::Accept( XMLVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - - -// --------- XMLComment ---------- // - -XMLComment::XMLComment( XMLDocument* doc ) : XMLNode( doc ) -{ -} - - -XMLComment::~XMLComment() -{ -} - - -char* XMLComment::ParseDeep( char* p, StrPair* ) -{ - // Comment parses as text. - const char* start = p; - p = _value.ParseText( p, "-->", StrPair::COMMENT ); - if ( p == 0 ) { - _document->SetError( XML_ERROR_PARSING_COMMENT, start, 0 ); - } - return p; -} - - -XMLNode* XMLComment::ShallowClone( XMLDocument* doc ) const -{ - if ( !doc ) { - doc = _document; - } - XMLComment* comment = doc->NewComment( Value() ); // fixme: this will always allocate memory. Intern? - return comment; -} - - -bool XMLComment::ShallowEqual( const XMLNode* compare ) const -{ - return ( compare->ToComment() && XMLUtil::StringEqual( compare->ToComment()->Value(), Value() )); -} - - -bool XMLComment::Accept( XMLVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - - -// --------- XMLDeclaration ---------- // - -XMLDeclaration::XMLDeclaration( XMLDocument* doc ) : XMLNode( doc ) -{ -} - - -XMLDeclaration::~XMLDeclaration() -{ - //printf( "~XMLDeclaration\n" ); -} - - -char* XMLDeclaration::ParseDeep( char* p, StrPair* ) -{ - // Declaration parses as text. - const char* start = p; - p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION ); - if ( p == 0 ) { - _document->SetError( XML_ERROR_PARSING_DECLARATION, start, 0 ); - } - return p; -} - - -XMLNode* XMLDeclaration::ShallowClone( XMLDocument* doc ) const -{ - if ( !doc ) { - doc = _document; - } - XMLDeclaration* dec = doc->NewDeclaration( Value() ); // fixme: this will always allocate memory. Intern? - return dec; -} - - -bool XMLDeclaration::ShallowEqual( const XMLNode* compare ) const -{ - return ( compare->ToDeclaration() && XMLUtil::StringEqual( compare->ToDeclaration()->Value(), Value() )); -} - - - -bool XMLDeclaration::Accept( XMLVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - -// --------- XMLUnknown ---------- // - -XMLUnknown::XMLUnknown( XMLDocument* doc ) : XMLNode( doc ) -{ -} - - -XMLUnknown::~XMLUnknown() -{ -} - - -char* XMLUnknown::ParseDeep( char* p, StrPair* ) -{ - // Unknown parses as text. - const char* start = p; - - p = _value.ParseText( p, ">", StrPair::NEEDS_NEWLINE_NORMALIZATION ); - if ( !p ) { - _document->SetError( XML_ERROR_PARSING_UNKNOWN, start, 0 ); - } - return p; -} - - -XMLNode* XMLUnknown::ShallowClone( XMLDocument* doc ) const -{ - if ( !doc ) { - doc = _document; - } - XMLUnknown* text = doc->NewUnknown( Value() ); // fixme: this will always allocate memory. Intern? - return text; -} - - -bool XMLUnknown::ShallowEqual( const XMLNode* compare ) const -{ - return ( compare->ToUnknown() && XMLUtil::StringEqual( compare->ToUnknown()->Value(), Value() )); -} - - -bool XMLUnknown::Accept( XMLVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - -// --------- XMLAttribute ---------- // -char* XMLAttribute::ParseDeep( char* p, bool processEntities ) -{ - // Parse using the name rules: bug fix, was using ParseText before - p = _name.ParseName( p ); - if ( !p || !*p ) { - return 0; - } - - // Skip white space before = - p = XMLUtil::SkipWhiteSpace( p ); - if ( !p || *p != '=' ) { - return 0; - } - - ++p; // move up to opening quote - p = XMLUtil::SkipWhiteSpace( p ); - if ( *p != '\"' && *p != '\'' ) { - return 0; - } - - char endTag[2] = { *p, 0 }; - ++p; // move past opening quote - - p = _value.ParseText( p, endTag, processEntities ? StrPair::ATTRIBUTE_VALUE : StrPair::ATTRIBUTE_VALUE_LEAVE_ENTITIES ); - return p; -} - - -void XMLAttribute::SetName( const char* n ) -{ - _name.SetStr( n ); -} - - -XMLError XMLAttribute::QueryIntValue( int* value ) const -{ - if ( XMLUtil::ToInt( Value(), value )) { - return XML_NO_ERROR; - } - return XML_WRONG_ATTRIBUTE_TYPE; -} - - -XMLError XMLAttribute::QueryUnsignedValue( unsigned int* value ) const -{ - if ( XMLUtil::ToUnsigned( Value(), value )) { - return XML_NO_ERROR; - } - return XML_WRONG_ATTRIBUTE_TYPE; -} - - -XMLError XMLAttribute::QueryBoolValue( bool* value ) const -{ - if ( XMLUtil::ToBool( Value(), value )) { - return XML_NO_ERROR; - } - return XML_WRONG_ATTRIBUTE_TYPE; -} - - -XMLError XMLAttribute::QueryFloatValue( float* value ) const -{ - if ( XMLUtil::ToFloat( Value(), value )) { - return XML_NO_ERROR; - } - return XML_WRONG_ATTRIBUTE_TYPE; -} - - -XMLError XMLAttribute::QueryDoubleValue( double* value ) const -{ - if ( XMLUtil::ToDouble( Value(), value )) { - return XML_NO_ERROR; - } - return XML_WRONG_ATTRIBUTE_TYPE; -} - - -void XMLAttribute::SetAttribute( const char* v ) -{ - _value.SetStr( v ); -} - - -void XMLAttribute::SetAttribute( int v ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( v, buf, BUF_SIZE ); - _value.SetStr( buf ); -} - - -void XMLAttribute::SetAttribute( unsigned v ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( v, buf, BUF_SIZE ); - _value.SetStr( buf ); -} - - -void XMLAttribute::SetAttribute( bool v ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( v, buf, BUF_SIZE ); - _value.SetStr( buf ); -} - -void XMLAttribute::SetAttribute( double v ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( v, buf, BUF_SIZE ); - _value.SetStr( buf ); -} - -void XMLAttribute::SetAttribute( float v ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( v, buf, BUF_SIZE ); - _value.SetStr( buf ); -} - - -// --------- XMLElement ---------- // -XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ), - _closingType( 0 ), - _rootAttribute( 0 ) -{ -} - - -XMLElement::~XMLElement() -{ - while( _rootAttribute ) { - XMLAttribute* next = _rootAttribute->_next; - DELETE_ATTRIBUTE( _rootAttribute ); - _rootAttribute = next; - } -} - - -XMLAttribute* XMLElement::FindAttribute( const char* name ) -{ - XMLAttribute* a = 0; - for( a=_rootAttribute; a; a = a->_next ) { - if ( XMLUtil::StringEqual( a->Name(), name ) ) { - return a; - } - } - return 0; -} - - -const XMLAttribute* XMLElement::FindAttribute( const char* name ) const -{ - XMLAttribute* a = 0; - for( a=_rootAttribute; a; a = a->_next ) { - if ( XMLUtil::StringEqual( a->Name(), name ) ) { - return a; - } - } - return 0; -} - - -const char* XMLElement::Attribute( const char* name, const char* value ) const -{ - const XMLAttribute* a = FindAttribute( name ); - if ( !a ) { - return 0; - } - if ( !value || XMLUtil::StringEqual( a->Value(), value )) { - return a->Value(); - } - return 0; -} - - -const char* XMLElement::GetText() const -{ - if ( FirstChild() && FirstChild()->ToText() ) { - return FirstChild()->ToText()->Value(); - } - return 0; -} - - -XMLError XMLElement::QueryIntText( int* ival ) const -{ - if ( FirstChild() && FirstChild()->ToText() ) { - const char* t = FirstChild()->ToText()->Value(); - if ( XMLUtil::ToInt( t, ival ) ) { - return XML_SUCCESS; - } - return XML_CAN_NOT_CONVERT_TEXT; - } - return XML_NO_TEXT_NODE; -} - - -XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const -{ - if ( FirstChild() && FirstChild()->ToText() ) { - const char* t = FirstChild()->ToText()->Value(); - if ( XMLUtil::ToUnsigned( t, uval ) ) { - return XML_SUCCESS; - } - return XML_CAN_NOT_CONVERT_TEXT; - } - return XML_NO_TEXT_NODE; -} - - -XMLError XMLElement::QueryBoolText( bool* bval ) const -{ - if ( FirstChild() && FirstChild()->ToText() ) { - const char* t = FirstChild()->ToText()->Value(); - if ( XMLUtil::ToBool( t, bval ) ) { - return XML_SUCCESS; - } - return XML_CAN_NOT_CONVERT_TEXT; - } - return XML_NO_TEXT_NODE; -} - - -XMLError XMLElement::QueryDoubleText( double* dval ) const -{ - if ( FirstChild() && FirstChild()->ToText() ) { - const char* t = FirstChild()->ToText()->Value(); - if ( XMLUtil::ToDouble( t, dval ) ) { - return XML_SUCCESS; - } - return XML_CAN_NOT_CONVERT_TEXT; - } - return XML_NO_TEXT_NODE; -} - - -XMLError XMLElement::QueryFloatText( float* fval ) const -{ - if ( FirstChild() && FirstChild()->ToText() ) { - const char* t = FirstChild()->ToText()->Value(); - if ( XMLUtil::ToFloat( t, fval ) ) { - return XML_SUCCESS; - } - return XML_CAN_NOT_CONVERT_TEXT; - } - return XML_NO_TEXT_NODE; -} - - - -XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name ) -{ - XMLAttribute* last = 0; - XMLAttribute* attrib = 0; - for( attrib = _rootAttribute; - attrib; - last = attrib, attrib = attrib->_next ) { - if ( XMLUtil::StringEqual( attrib->Name(), name ) ) { - break; - } - } - if ( !attrib ) { - attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); - attrib->_memPool = &_document->_attributePool; - if ( last ) { - last->_next = attrib; - } - else { - _rootAttribute = attrib; - } - attrib->SetName( name ); - attrib->_memPool->SetTracked(); // always created and linked. - } - return attrib; -} - - -void XMLElement::DeleteAttribute( const char* name ) -{ - XMLAttribute* prev = 0; - for( XMLAttribute* a=_rootAttribute; a; a=a->_next ) { - if ( XMLUtil::StringEqual( name, a->Name() ) ) { - if ( prev ) { - prev->_next = a->_next; - } - else { - _rootAttribute = a->_next; - } - DELETE_ATTRIBUTE( a ); - break; - } - prev = a; - } -} - - -char* XMLElement::ParseAttributes( char* p ) -{ - const char* start = p; - XMLAttribute* prevAttribute = 0; - - // Read the attributes. - while( p ) { - p = XMLUtil::SkipWhiteSpace( p ); - if ( !p || !(*p) ) { - _document->SetError( XML_ERROR_PARSING_ELEMENT, start, Name() ); - return 0; - } - - // attribute. - if ( XMLUtil::IsAlpha( *p ) ) { - XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); - attrib->_memPool = &_document->_attributePool; - attrib->_memPool->SetTracked(); - - p = attrib->ParseDeep( p, _document->ProcessEntities() ); - if ( !p || Attribute( attrib->Name() ) ) { - DELETE_ATTRIBUTE( attrib ); - _document->SetError( XML_ERROR_PARSING_ATTRIBUTE, start, p ); - return 0; - } - // There is a minor bug here: if the attribute in the source xml - // document is duplicated, it will not be detected and the - // attribute will be doubly added. However, tracking the 'prevAttribute' - // avoids re-scanning the attribute list. Preferring performance for - // now, may reconsider in the future. - if ( prevAttribute ) { - prevAttribute->_next = attrib; - } - else { - _rootAttribute = attrib; - } - prevAttribute = attrib; - } - // end of the tag - else if ( *p == '/' && *(p+1) == '>' ) { - _closingType = CLOSED; - return p+2; // done; sealed element. - } - // end of the tag - else if ( *p == '>' ) { - ++p; - break; - } - else { - _document->SetError( XML_ERROR_PARSING_ELEMENT, start, p ); - return 0; - } - } - return p; -} - - -// -// -// foobar -// -char* XMLElement::ParseDeep( char* p, StrPair* strPair ) -{ - // Read the element name. - p = XMLUtil::SkipWhiteSpace( p ); - if ( !p ) { - return 0; - } - - // The closing element is the form. It is - // parsed just like a regular element then deleted from - // the DOM. - if ( *p == '/' ) { - _closingType = CLOSING; - ++p; - } - - p = _value.ParseName( p ); - if ( _value.Empty() ) { - return 0; - } - - p = ParseAttributes( p ); - if ( !p || !*p || _closingType ) { - return p; - } - - p = XMLNode::ParseDeep( p, strPair ); - return p; -} - - - -XMLNode* XMLElement::ShallowClone( XMLDocument* doc ) const -{ - if ( !doc ) { - doc = _document; - } - XMLElement* element = doc->NewElement( Value() ); // fixme: this will always allocate memory. Intern? - for( const XMLAttribute* a=FirstAttribute(); a; a=a->Next() ) { - element->SetAttribute( a->Name(), a->Value() ); // fixme: this will always allocate memory. Intern? - } - return element; -} - - -bool XMLElement::ShallowEqual( const XMLNode* compare ) const -{ - const XMLElement* other = compare->ToElement(); - if ( other && XMLUtil::StringEqual( other->Value(), Value() )) { - - const XMLAttribute* a=FirstAttribute(); - const XMLAttribute* b=other->FirstAttribute(); - - while ( a && b ) { - if ( !XMLUtil::StringEqual( a->Value(), b->Value() ) ) { - return false; - } - a = a->Next(); - b = b->Next(); - } - if ( a || b ) { - // different count - return false; - } - return true; - } - return false; -} - - -bool XMLElement::Accept( XMLVisitor* visitor ) const -{ - if ( visitor->VisitEnter( *this, _rootAttribute ) ) { - for ( const XMLNode* node=FirstChild(); node; node=node->NextSibling() ) { - if ( !node->Accept( visitor ) ) { - break; - } - } - } - return visitor->VisitExit( *this ); -} - - -// --------- XMLDocument ----------- // -XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) : - XMLNode( 0 ), - _writeBOM( false ), - _processEntities( processEntities ), - _errorID( XML_NO_ERROR ), - _whitespace( whitespace ), - _errorStr1( 0 ), - _errorStr2( 0 ), - _charBuffer( 0 ) -{ - _document = this; // avoid warning about 'this' in initializer list -} - - -XMLDocument::~XMLDocument() -{ - DeleteChildren(); - delete [] _charBuffer; - -#if 0 - textPool.Trace( "text" ); - elementPool.Trace( "element" ); - commentPool.Trace( "comment" ); - attributePool.Trace( "attribute" ); -#endif - -#ifdef DEBUG - if ( Error() == false ) { - TIXMLASSERT( _elementPool.CurrentAllocs() == _elementPool.Untracked() ); - TIXMLASSERT( _attributePool.CurrentAllocs() == _attributePool.Untracked() ); - TIXMLASSERT( _textPool.CurrentAllocs() == _textPool.Untracked() ); - TIXMLASSERT( _commentPool.CurrentAllocs() == _commentPool.Untracked() ); - } -#endif -} - - -void XMLDocument::InitDocument() -{ - _errorID = XML_NO_ERROR; - _errorStr1 = 0; - _errorStr2 = 0; - - delete [] _charBuffer; - _charBuffer = 0; -} - - -XMLElement* XMLDocument::NewElement( const char* name ) -{ - XMLElement* ele = new (_elementPool.Alloc()) XMLElement( this ); - ele->_memPool = &_elementPool; - ele->SetName( name ); - return ele; -} - - -XMLComment* XMLDocument::NewComment( const char* str ) -{ - XMLComment* comment = new (_commentPool.Alloc()) XMLComment( this ); - comment->_memPool = &_commentPool; - comment->SetValue( str ); - return comment; -} - - -XMLText* XMLDocument::NewText( const char* str ) -{ - XMLText* text = new (_textPool.Alloc()) XMLText( this ); - text->_memPool = &_textPool; - text->SetValue( str ); - return text; -} - - -XMLDeclaration* XMLDocument::NewDeclaration( const char* str ) -{ - XMLDeclaration* dec = new (_commentPool.Alloc()) XMLDeclaration( this ); - dec->_memPool = &_commentPool; - dec->SetValue( str ? str : "xml version=\"1.0\" encoding=\"UTF-8\"" ); - return dec; -} - - -XMLUnknown* XMLDocument::NewUnknown( const char* str ) -{ - XMLUnknown* unk = new (_commentPool.Alloc()) XMLUnknown( this ); - unk->_memPool = &_commentPool; - unk->SetValue( str ); - return unk; -} - - -XMLError XMLDocument::LoadFile( const char* filename ) -{ - DeleteChildren(); - InitDocument(); - FILE* fp = 0; - -#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE) - errno_t err = fopen_s(&fp, filename, "rb" ); - if ( !fp || err) { -#else - fp = fopen( filename, "rb" ); - if ( !fp) { -#endif - SetError( XML_ERROR_FILE_NOT_FOUND, filename, 0 ); - return _errorID; - } - LoadFile( fp ); - fclose( fp ); - return _errorID; -} - - -XMLError XMLDocument::LoadFile( FILE* fp ) -{ - DeleteChildren(); - InitDocument(); - - fseek( fp, 0, SEEK_END ); - size_t size = ftell( fp ); - fseek( fp, 0, SEEK_SET ); - - if ( size == 0 ) { - return _errorID; - } - - _charBuffer = new char[size+1]; - size_t read = fread( _charBuffer, 1, size, fp ); - if ( read != size ) { - SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); - return _errorID; - } - - _charBuffer[size] = 0; - - const char* p = _charBuffer; - p = XMLUtil::SkipWhiteSpace( p ); - p = XMLUtil::ReadBOM( p, &_writeBOM ); - if ( !p || !*p ) { - SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); - return _errorID; - } - - ParseDeep( _charBuffer + (p-_charBuffer), 0 ); - return _errorID; -} - - -XMLError XMLDocument::SaveFile( const char* filename, bool compact ) -{ - FILE* fp = 0; -#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE) - errno_t err = fopen_s(&fp, filename, "w" ); - if ( !fp || err) { -#else - fp = fopen( filename, "w" ); - if ( !fp) { -#endif - SetError( XML_ERROR_FILE_COULD_NOT_BE_OPENED, filename, 0 ); - return _errorID; - } - SaveFile(fp, compact); - fclose( fp ); - return _errorID; -} - - -XMLError XMLDocument::SaveFile( FILE* fp, bool compact ) -{ - XMLPrinter stream( fp, compact ); - Print( &stream ); - return _errorID; -} - - -XMLError XMLDocument::Parse( const char* p, size_t len ) -{ - DeleteChildren(); - InitDocument(); - - if ( !p || !*p ) { - SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); - return _errorID; - } - if ( len == (size_t)(-1) ) { - len = strlen( p ); - } - _charBuffer = new char[ len+1 ]; - memcpy( _charBuffer, p, len ); - _charBuffer[len] = 0; - - p = XMLUtil::SkipWhiteSpace( p ); - p = XMLUtil::ReadBOM( p, &_writeBOM ); - if ( !p || !*p ) { - SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); - return _errorID; - } - - ParseDeep( _charBuffer, 0 ); - return _errorID; -} - - -void XMLDocument::Print( XMLPrinter* streamer ) -{ - XMLPrinter stdStreamer( stdout ); - if ( !streamer ) { - streamer = &stdStreamer; - } - Accept( streamer ); -} - - -void XMLDocument::SetError( XMLError error, const char* str1, const char* str2 ) -{ - _errorID = error; - _errorStr1 = str1; - _errorStr2 = str2; -} - - -void XMLDocument::PrintError() const -{ - if ( _errorID ) { - static const int LEN = 20; - char buf1[LEN] = { 0 }; - char buf2[LEN] = { 0 }; - - if ( _errorStr1 ) { - TIXML_SNPRINTF( buf1, LEN, "%s", _errorStr1 ); - } - if ( _errorStr2 ) { - TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 ); - } - - printf( "XMLDocument error id=%d str1=%s str2=%s\n", - _errorID, buf1, buf2 ); - } -} - - -XMLPrinter::XMLPrinter( FILE* file, bool compact ) : - _elementJustOpened( false ), - _firstElement( true ), - _fp( file ), - _depth( 0 ), - _textDepth( -1 ), - _processEntities( true ), - _compactMode( compact ) -{ - for( int i=0; i'] = true; // not required, but consistency is nice - _buffer.Push( 0 ); -} - - -void XMLPrinter::Print( const char* format, ... ) -{ - va_list va; - va_start( va, format ); - - if ( _fp ) { - vfprintf( _fp, format, va ); - } - else { - // This seems brutally complex. Haven't figured out a better - // way on windows. -#if defined _MSC_VER && (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE) - int len = -1; - int expand = 1000; - while ( len < 0 ) { - len = vsnprintf_s( _accumulator.Mem(), _accumulator.Capacity(), _TRUNCATE, format, va ); - if ( len < 0 ) { - expand *= 3/2; - _accumulator.PushArr( expand ); - } - } - char* p = _buffer.PushArr( len ) - 1; - memcpy( p, _accumulator.Mem(), len+1 ); -#else - int len = vsnprintf( 0, 0, format, va ); - // Close out and re-start the va-args - va_end( va ); - va_start( va, format ); - char* p = _buffer.PushArr( len ) - 1; - vsnprintf( p, len+1, format, va ); -#endif - } - va_end( va ); -} - - -void XMLPrinter::PrintSpace( int depth ) -{ - for( int i=0; i 0 && *q < ENTITY_RANGE ) { - // Check for entities. If one is found, flush - // the stream up until the entity, write the - // entity, and keep looking. - if ( flag[(unsigned)(*q)] ) { - while ( p < q ) { - Print( "%c", *p ); - ++p; - } - for( int i=0; i 0) ) { - Print( "%s", p ); - } -} - - -void XMLPrinter::PushHeader( bool writeBOM, bool writeDec ) -{ - static const unsigned char bom[] = { TIXML_UTF_LEAD_0, TIXML_UTF_LEAD_1, TIXML_UTF_LEAD_2, 0 }; - if ( writeBOM ) { - Print( "%s", bom ); - } - if ( writeDec ) { - PushDeclaration( "xml version=\"1.0\"" ); - } -} - - -void XMLPrinter::OpenElement( const char* name ) -{ - if ( _elementJustOpened ) { - SealElement(); - } - _stack.Push( name ); - - if ( _textDepth < 0 && !_firstElement && !_compactMode ) { - Print( "\n" ); - PrintSpace( _depth ); - } - - Print( "<%s", name ); - _elementJustOpened = true; - _firstElement = false; - ++_depth; -} - - -void XMLPrinter::PushAttribute( const char* name, const char* value ) -{ - TIXMLASSERT( _elementJustOpened ); - Print( " %s=\"", name ); - PrintString( value, false ); - Print( "\"" ); -} - - -void XMLPrinter::PushAttribute( const char* name, int v ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( v, buf, BUF_SIZE ); - PushAttribute( name, buf ); -} - - -void XMLPrinter::PushAttribute( const char* name, unsigned v ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( v, buf, BUF_SIZE ); - PushAttribute( name, buf ); -} - - -void XMLPrinter::PushAttribute( const char* name, bool v ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( v, buf, BUF_SIZE ); - PushAttribute( name, buf ); -} - - -void XMLPrinter::PushAttribute( const char* name, double v ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( v, buf, BUF_SIZE ); - PushAttribute( name, buf ); -} - - -void XMLPrinter::CloseElement() -{ - --_depth; - const char* name = _stack.Pop(); - - if ( _elementJustOpened ) { - Print( "/>" ); - } - else { - if ( _textDepth < 0 && !_compactMode) { - Print( "\n" ); - PrintSpace( _depth ); - } - Print( "", name ); - } - - if ( _textDepth == _depth ) { - _textDepth = -1; - } - if ( _depth == 0 && !_compactMode) { - Print( "\n" ); - } - _elementJustOpened = false; -} - - -void XMLPrinter::SealElement() -{ - _elementJustOpened = false; - Print( ">" ); -} - - -void XMLPrinter::PushText( const char* text, bool cdata ) -{ - _textDepth = _depth-1; - - if ( _elementJustOpened ) { - SealElement(); - } - if ( cdata ) { - Print( "" ); - } - else { - PrintString( text, true ); - } -} - -void XMLPrinter::PushText( int value ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( value, buf, BUF_SIZE ); - PushText( buf, false ); -} - - -void XMLPrinter::PushText( unsigned value ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( value, buf, BUF_SIZE ); - PushText( buf, false ); -} - - -void XMLPrinter::PushText( bool value ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( value, buf, BUF_SIZE ); - PushText( buf, false ); -} - - -void XMLPrinter::PushText( float value ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( value, buf, BUF_SIZE ); - PushText( buf, false ); -} - - -void XMLPrinter::PushText( double value ) -{ - char buf[BUF_SIZE]; - XMLUtil::ToStr( value, buf, BUF_SIZE ); - PushText( buf, false ); -} - - -void XMLPrinter::PushComment( const char* comment ) -{ - if ( _elementJustOpened ) { - SealElement(); - } - if ( _textDepth < 0 && !_firstElement && !_compactMode) { - Print( "\n" ); - PrintSpace( _depth ); - } - _firstElement = false; - Print( "", comment ); -} - - -void XMLPrinter::PushDeclaration( const char* value ) -{ - if ( _elementJustOpened ) { - SealElement(); - } - if ( _textDepth < 0 && !_firstElement && !_compactMode) { - Print( "\n" ); - PrintSpace( _depth ); - } - _firstElement = false; - Print( "", value ); -} - - -void XMLPrinter::PushUnknown( const char* value ) -{ - if ( _elementJustOpened ) { - SealElement(); - } - if ( _textDepth < 0 && !_firstElement && !_compactMode) { - Print( "\n" ); - PrintSpace( _depth ); - } - _firstElement = false; - Print( "", value ); -} - - -bool XMLPrinter::VisitEnter( const XMLDocument& doc ) -{ - _processEntities = doc.ProcessEntities(); - if ( doc.HasBOM() ) { - PushHeader( true, false ); - } - return true; -} - - -bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute ) -{ - OpenElement( element.Name() ); - while ( attribute ) { - PushAttribute( attribute->Name(), attribute->Value() ); - attribute = attribute->Next(); - } - return true; -} - - -bool XMLPrinter::VisitExit( const XMLElement& ) -{ - CloseElement(); - return true; -} - - -bool XMLPrinter::Visit( const XMLText& text ) -{ - PushText( text.Value(), text.CData() ); - return true; -} - - -bool XMLPrinter::Visit( const XMLComment& comment ) -{ - PushComment( comment.Value() ); - return true; -} - -bool XMLPrinter::Visit( const XMLDeclaration& declaration ) -{ - PushDeclaration( declaration.Value() ); - return true; -} - - -bool XMLPrinter::Visit( const XMLUnknown& unknown ) -{ - PushUnknown( unknown.Value() ); - return true; -} - -} // namespace tinyxml2 - diff --git a/cocos/2d/support/tinyxml2/tinyxml2.h b/cocos/2d/support/tinyxml2/tinyxml2.h deleted file mode 100644 index eeffa1096f..0000000000 --- a/cocos/2d/support/tinyxml2/tinyxml2.h +++ /dev/null @@ -1,1914 +0,0 @@ -/* -Original code by Lee Thomason (www.grinninglizard.com) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - -#ifndef TINYXML2_INCLUDED -#define TINYXML2_INCLUDED - -#include "platform/CCPlatformConfig.h" -#include "platform/CCPlatformMacros.h" - -#if defined(ANDROID_NDK) || defined(__BORLANDC__) || (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY) -# include -# include -# include -# include -# include -# include -#else -# include -# include -# include -# include -# include -# include -#endif - -/* - TODO: intern strings instead of allocation. -*/ -/* - gcc: - g++ -Wall -DDEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe - - Formatting, Artistic Style: - AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h -*/ - -#if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__) -# ifndef DEBUG -# define DEBUG -# endif -#endif - - -#if defined(DEBUG) -# if defined(_MSC_VER) -# define TIXMLASSERT( x ) if ( !(x)) { __debugbreak(); } //if ( !(x)) WinDebugBreak() -# elif defined (ANDROID_NDK) -# include -# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); } -# else -# include -# define TIXMLASSERT assert -# endif -# else -# define TIXMLASSERT( x ) {} -#endif - - -#if (defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)) -// Microsoft visual studio, version 2005 and higher. -/*int _snprintf_s( - char *buffer, - size_t sizeOfBuffer, - size_t count, - const char *format [, - argument] ... -);*/ -inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... ) -{ - va_list va; - va_start( va, format ); - int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va ); - va_end( va ); - return result; -} -#define TIXML_SSCANF sscanf_s -#else -// GCC version 3 and higher -//#warning( "Using sn* functions." ) -#define TIXML_SNPRINTF snprintf -#define TIXML_SSCANF sscanf -#endif - -static const int TIXML2_MAJOR_VERSION = 1; -static const int TIXML2_MINOR_VERSION = 0; -static const int TIXML2_PATCH_VERSION = 9; - -namespace tinyxml2 -{ -class XMLDocument; -class XMLElement; -class XMLAttribute; -class XMLComment; -class XMLNode; -class XMLText; -class XMLDeclaration; -class XMLUnknown; - -class XMLPrinter; - -/* - A class that wraps strings. Normally stores the start and end - pointers into the XML file itself, and will apply normalization - and entity translation if actually read. Can also store (and memory - manage) a traditional char[] -*/ -class CC_DLL StrPair -{ -public: - enum { - NEEDS_ENTITY_PROCESSING = 0x01, - NEEDS_NEWLINE_NORMALIZATION = 0x02, - COLLAPSE_WHITESPACE = 0x04, - - TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, - TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, - ATTRIBUTE_NAME = 0, - ATTRIBUTE_VALUE = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION, - ATTRIBUTE_VALUE_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION, - COMMENT = NEEDS_NEWLINE_NORMALIZATION - }; - - StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {} - ~StrPair(); - - void Set( char* start, char* end, int flags ) { - Reset(); - _start = start; - _end = end; - _flags = flags | NEEDS_FLUSH; - } - - const char* GetStr(); - - bool Empty() const { - return _start == _end; - } - - void SetInternedStr( const char* str ) { - Reset(); - _start = const_cast(str); - } - - void SetStr( const char* str, int flags=0 ); - - char* ParseText( char* in, const char* endTag, int strFlags ); - char* ParseName( char* in ); - -private: - void Reset(); - void CollapseWhitespace(); - - enum { - NEEDS_FLUSH = 0x100, - NEEDS_DELETE = 0x200 - }; - - // After parsing, if *end != 0, it can be set to zero. - int _flags; - char* _start; - char* _end; -}; - - -/* - A dynamic array of Plain Old Data. Doesn't support constructors, etc. - Has a small initial memory pool, so that low or no usage will not - cause a call to new/delete -*/ -template -class CC_DLL DynArray -{ -public: - DynArray< T, INIT >() { - _mem = _pool; - _allocated = INIT; - _size = 0; - } - - ~DynArray() { - if ( _mem != _pool ) { - delete [] _mem; - } - } - - void Push( T t ) { - EnsureCapacity( _size+1 ); - _mem[_size++] = t; - } - - T* PushArr( int count ) { - EnsureCapacity( _size+count ); - T* ret = &_mem[_size]; - _size += count; - return ret; - } - - T Pop() { - return _mem[--_size]; - } - - void PopArr( int count ) { - TIXMLASSERT( _size >= count ); - _size -= count; - } - - bool Empty() const { - return _size == 0; - } - - T& operator[](int i) { - TIXMLASSERT( i>= 0 && i < _size ); - return _mem[i]; - } - - const T& operator[](int i) const { - TIXMLASSERT( i>= 0 && i < _size ); - return _mem[i]; - } - - int Size() const { - return _size; - } - - int Capacity() const { - return _allocated; - } - - const T* Mem() const { - return _mem; - } - - T* Mem() { - return _mem; - } - -private: - void EnsureCapacity( int cap ) { - if ( cap > _allocated ) { - int newAllocated = cap * 2; - T* newMem = new T[newAllocated]; - memcpy( newMem, _mem, sizeof(T)*_size ); // warning: not using constructors, only works for PODs - if ( _mem != _pool ) { - delete [] _mem; - } - _mem = newMem; - _allocated = newAllocated; - } - } - - T* _mem; - T _pool[INIT]; - int _allocated; // objects allocated - int _size; // number objects in use -}; - - -/* - Parent virtual class of a pool for fast allocation - and deallocation of objects. -*/ -class CC_DLL MemPool -{ -public: - MemPool() {} - virtual ~MemPool() {} - - virtual int ItemSize() const = 0; - virtual void* Alloc() = 0; - virtual void Free( void* ) = 0; - virtual void SetTracked() = 0; -}; - - -/* - Template child class to create pools of the correct type. -*/ -template< int SIZE > -class CC_DLL MemPoolT : public MemPool -{ -public: - MemPoolT() : _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {} - ~MemPoolT() { - // Delete the blocks. - for( int i=0; i<_blockPtrs.Size(); ++i ) { - delete _blockPtrs[i]; - } - } - - virtual int ItemSize() const { - return SIZE; - } - int CurrentAllocs() const { - return _currentAllocs; - } - - virtual void* Alloc() { - if ( !_root ) { - // Need a new block. - Block* block = new Block(); - _blockPtrs.Push( block ); - - for( int i=0; ichunk[i].next = &block->chunk[i+1]; - } - block->chunk[COUNT-1].next = 0; - _root = block->chunk; - } - void* result = _root; - _root = _root->next; - - ++_currentAllocs; - if ( _currentAllocs > _maxAllocs ) { - _maxAllocs = _currentAllocs; - } - _nAllocs++; - _nUntracked++; - return result; - } - virtual void Free( void* mem ) { - if ( !mem ) { - return; - } - --_currentAllocs; - Chunk* chunk = (Chunk*)mem; -#ifdef DEBUG - memset( chunk, 0xfe, sizeof(Chunk) ); -#endif - chunk->next = _root; - _root = chunk; - } - void Trace( const char* name ) { - printf( "Mempool %s watermark=%d [%dk] current=%d size=%d nAlloc=%d blocks=%d\n", - name, _maxAllocs, _maxAllocs*SIZE/1024, _currentAllocs, SIZE, _nAllocs, _blockPtrs.Size() ); - } - - void SetTracked() { - _nUntracked--; - } - - int Untracked() const { - return _nUntracked; - } - - enum { COUNT = 1024/SIZE }; // Some compilers do not accept to use COUNT in private part if COUNT is private - -private: - union Chunk { - Chunk* next; - char mem[SIZE]; - }; - struct Block { - Chunk chunk[COUNT]; - }; - DynArray< Block*, 10 > _blockPtrs; - Chunk* _root; - - int _currentAllocs; - int _nAllocs; - int _maxAllocs; - int _nUntracked; -}; - - - -/** - Implements the interface to the "Visitor pattern" (see the Accept() method.) - If you call the Accept() method, it requires being passed a XMLVisitor - class to handle callbacks. For nodes that contain other nodes (Document, Element) - you will get called with a VisitEnter/VisitExit pair. Nodes that are always leafs - are simply called with Visit(). - - If you return 'true' from a Visit method, recursive parsing will continue. If you return - false, no children of this node or its sibilings will be visited. - - All flavors of Visit methods have a default implementation that returns 'true' (continue - visiting). You need to only override methods that are interesting to you. - - Generally Accept() is called on the TiXmlDocument, although all nodes support visiting. - - You should never change the document from a callback. - - @sa XMLNode::Accept() -*/ -class CC_DLL XMLVisitor -{ -public: - virtual ~XMLVisitor() {} - - /// Visit a document. - virtual bool VisitEnter( const XMLDocument& /*doc*/ ) { - return true; - } - /// Visit a document. - virtual bool VisitExit( const XMLDocument& /*doc*/ ) { - return true; - } - - /// Visit an element. - virtual bool VisitEnter( const XMLElement& /*element*/, const XMLAttribute* /*firstAttribute*/ ) { - return true; - } - /// Visit an element. - virtual bool VisitExit( const XMLElement& /*element*/ ) { - return true; - } - - /// Visit a declaration. - virtual bool Visit( const XMLDeclaration& /*declaration*/ ) { - return true; - } - /// Visit a text node. - virtual bool Visit( const XMLText& /*text*/ ) { - return true; - } - /// Visit a comment node. - virtual bool Visit( const XMLComment& /*comment*/ ) { - return true; - } - /// Visit an unknown node. - virtual bool Visit( const XMLUnknown& /*unknown*/ ) { - return true; - } -}; - - -/* - Utility functionality. -*/ -class CC_DLL XMLUtil -{ -public: - // Anything in the high order range of UTF-8 is assumed to not be whitespace. This isn't - // correct, but simple, and usually works. - static const char* SkipWhiteSpace( const char* p ) { - while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast(p) ) ) { - ++p; - } - return p; - } - static char* SkipWhiteSpace( char* p ) { - while( !IsUTF8Continuation(*p) && isspace( *reinterpret_cast(p) ) ) { - ++p; - } - return p; - } - static bool IsWhiteSpace( char p ) { - return !IsUTF8Continuation(p) && isspace( static_cast(p) ); - } - - inline static bool StringEqual( const char* p, const char* q, int nChar=INT_MAX ) { - int n = 0; - if ( p == q ) { - return true; - } - while( *p && *q && *p == *q && n(const_cast(this)->FirstChildElement( value )); - } - - /// Get the last child node, or null if none exists. - const XMLNode* LastChild() const { - return _lastChild; - } - - XMLNode* LastChild() { - return const_cast(const_cast(this)->LastChild() ); - } - - /** Get the last child element or optionally the last child - element with the specified name. - */ - const XMLElement* LastChildElement( const char* value=0 ) const; - - XMLElement* LastChildElement( const char* value=0 ) { - return const_cast(const_cast(this)->LastChildElement(value) ); - } - - /// Get the previous (left) sibling node of this node. - const XMLNode* PreviousSibling() const { - return _prev; - } - - XMLNode* PreviousSibling() { - return _prev; - } - - /// Get the previous (left) sibling element of this node, with an opitionally supplied name. - const XMLElement* PreviousSiblingElement( const char* value=0 ) const ; - - XMLElement* PreviousSiblingElement( const char* value=0 ) { - return const_cast(const_cast(this)->PreviousSiblingElement( value ) ); - } - - /// Get the next (right) sibling node of this node. - const XMLNode* NextSibling() const { - return _next; - } - - XMLNode* NextSibling() { - return _next; - } - - /// Get the next (right) sibling element of this node, with an opitionally supplied name. - const XMLElement* NextSiblingElement( const char* value=0 ) const; - - XMLElement* NextSiblingElement( const char* value=0 ) { - return const_cast(const_cast(this)->NextSiblingElement( value ) ); - } - - /** - Add a child node as the last (right) child. - */ - XMLNode* InsertEndChild( XMLNode* addThis ); - - XMLNode* LinkEndChild( XMLNode* addThis ) { - return InsertEndChild( addThis ); - } - /** - Add a child node as the first (left) child. - */ - XMLNode* InsertFirstChild( XMLNode* addThis ); - /** - Add a node after the specified child node. - */ - XMLNode* InsertAfterChild( XMLNode* afterThis, XMLNode* addThis ); - - /** - Delete all the children of this node. - */ - void DeleteChildren(); - - /** - Delete a child of this node. - */ - void DeleteChild( XMLNode* node ); - - /** - Make a copy of this node, but not its children. - You may pass in a Document pointer that will be - the owner of the new Node. If the 'document' is - null, then the node returned will be allocated - from the current Document. (this->GetDocument()) - - Note: if called on a XMLDocument, this will return null. - */ - virtual XMLNode* ShallowClone( XMLDocument* document ) const = 0; - - /** - Test if 2 nodes are the same, but don't test children. - The 2 nodes do not need to be in the same Document. - - Note: if called on a XMLDocument, this will return false. - */ - virtual bool ShallowEqual( const XMLNode* compare ) const = 0; - - /** Accept a hierarchical visit of the nodes in the TinyXML DOM. Every node in the - XML tree will be conditionally visited and the host will be called back - via the TiXmlVisitor interface. - - This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse - the XML for the callbacks, so the performance of TinyXML is unchanged by using this - interface versus any other.) - - The interface has been based on ideas from: - - - http://www.saxproject.org/ - - http://c2.com/cgi/wiki?HierarchicalVisitorPattern - - Which are both good references for "visiting". - - An example of using Accept(): - @verbatim - TiXmlPrinter printer; - tinyxmlDoc.Accept( &printer ); - const char* xmlcstr = printer.CStr(); - @endverbatim - */ - virtual bool Accept( XMLVisitor* visitor ) const = 0; - - // internal - virtual char* ParseDeep( char*, StrPair* ); - -protected: - XMLNode( XMLDocument* ); - virtual ~XMLNode(); - XMLNode( const XMLNode& ); // not supported - XMLNode& operator=( const XMLNode& ); // not supported - - XMLDocument* _document; - XMLNode* _parent; - mutable StrPair _value; - - XMLNode* _firstChild; - XMLNode* _lastChild; - - XMLNode* _prev; - XMLNode* _next; - -private: - MemPool* _memPool; - void Unlink( XMLNode* child ); -}; - - -/** XML text. - - Note that a text node can have child element nodes, for example: - @verbatim - This is bold - @endverbatim - - A text node can have 2 ways to output the next. "normal" output - and CDATA. It will default to the mode it was parsed from the XML file and - you generally want to leave it alone, but you can change the output mode with - SetCDATA() and query it with CDATA(). -*/ -class CC_DLL XMLText : public XMLNode -{ - friend class XMLBase; - friend class XMLDocument; -public: - virtual bool Accept( XMLVisitor* visitor ) const; - - virtual XMLText* ToText() { - return this; - } - virtual const XMLText* ToText() const { - return this; - } - - /// Declare whether this should be CDATA or standard text. - void SetCData( bool isCData ) { - _isCData = isCData; - } - /// Returns true if this is a CDATA text element. - bool CData() const { - return _isCData; - } - - char* ParseDeep( char*, StrPair* endTag ); - virtual XMLNode* ShallowClone( XMLDocument* document ) const; - virtual bool ShallowEqual( const XMLNode* compare ) const; - -protected: - XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {} - virtual ~XMLText() {} - XMLText( const XMLText& ); // not supported - XMLText& operator=( const XMLText& ); // not supported - -private: - bool _isCData; -}; - - -/** An XML Comment. */ -class CC_DLL XMLComment : public XMLNode -{ - friend class XMLDocument; -public: - virtual XMLComment* ToComment() { - return this; - } - virtual const XMLComment* ToComment() const { - return this; - } - - virtual bool Accept( XMLVisitor* visitor ) const; - - char* ParseDeep( char*, StrPair* endTag ); - virtual XMLNode* ShallowClone( XMLDocument* document ) const; - virtual bool ShallowEqual( const XMLNode* compare ) const; - -protected: - XMLComment( XMLDocument* doc ); - virtual ~XMLComment(); - XMLComment( const XMLComment& ); // not supported - XMLComment& operator=( const XMLComment& ); // not supported - -private: -}; - - -/** In correct XML the declaration is the first entry in the file. - @verbatim - - @endverbatim - - TinyXML2 will happily read or write files without a declaration, - however. - - The text of the declaration isn't interpreted. It is parsed - and written as a string. -*/ -class CC_DLL XMLDeclaration : public XMLNode -{ - friend class XMLDocument; -public: - virtual XMLDeclaration* ToDeclaration() { - return this; - } - virtual const XMLDeclaration* ToDeclaration() const { - return this; - } - - virtual bool Accept( XMLVisitor* visitor ) const; - - char* ParseDeep( char*, StrPair* endTag ); - virtual XMLNode* ShallowClone( XMLDocument* document ) const; - virtual bool ShallowEqual( const XMLNode* compare ) const; - -protected: - XMLDeclaration( XMLDocument* doc ); - virtual ~XMLDeclaration(); - XMLDeclaration( const XMLDeclaration& ); // not supported - XMLDeclaration& operator=( const XMLDeclaration& ); // not supported -}; - - -/** Any tag that tinyXml doesn't recognize is saved as an - unknown. It is a tag of text, but should not be modified. - It will be written back to the XML, unchanged, when the file - is saved. - - DTD tags get thrown into TiXmlUnknowns. -*/ -class CC_DLL XMLUnknown : public XMLNode -{ - friend class XMLDocument; -public: - virtual XMLUnknown* ToUnknown() { - return this; - } - virtual const XMLUnknown* ToUnknown() const { - return this; - } - - virtual bool Accept( XMLVisitor* visitor ) const; - - char* ParseDeep( char*, StrPair* endTag ); - virtual XMLNode* ShallowClone( XMLDocument* document ) const; - virtual bool ShallowEqual( const XMLNode* compare ) const; - -protected: - XMLUnknown( XMLDocument* doc ); - virtual ~XMLUnknown(); - XMLUnknown( const XMLUnknown& ); // not supported - XMLUnknown& operator=( const XMLUnknown& ); // not supported -}; - - -enum XMLError { - XML_NO_ERROR = 0, - XML_SUCCESS = 0, - - XML_NO_ATTRIBUTE, - XML_WRONG_ATTRIBUTE_TYPE, - - XML_ERROR_FILE_NOT_FOUND, - XML_ERROR_FILE_COULD_NOT_BE_OPENED, - XML_ERROR_FILE_READ_ERROR, - XML_ERROR_ELEMENT_MISMATCH, - XML_ERROR_PARSING_ELEMENT, - XML_ERROR_PARSING_ATTRIBUTE, - XML_ERROR_IDENTIFYING_TAG, - XML_ERROR_PARSING_TEXT, - XML_ERROR_PARSING_CDATA, - XML_ERROR_PARSING_COMMENT, - XML_ERROR_PARSING_DECLARATION, - XML_ERROR_PARSING_UNKNOWN, - XML_ERROR_EMPTY_DOCUMENT, - XML_ERROR_MISMATCHED_ELEMENT, - XML_ERROR_PARSING, - - XML_CAN_NOT_CONVERT_TEXT, - XML_NO_TEXT_NODE -}; - - -/** An attribute is a name-value pair. Elements have an arbitrary - number of attributes, each with a unique name. - - @note The attributes are not XMLNodes. You may only query the - Next() attribute in a list. -*/ -class CC_DLL XMLAttribute -{ - friend class XMLElement; -public: - /// The name of the attribute. - const char* Name() const { - return _name.GetStr(); - } - /// The value of the attribute. - const char* Value() const { - return _value.GetStr(); - } - /// The next attribute in the list. - const XMLAttribute* Next() const { - return _next; - } - - /** IntAttribute interprets the attribute as an integer, and returns the value. - If the value isn't an integer, 0 will be returned. There is no error checking; - use QueryIntAttribute() if you need error checking. - */ - int IntValue() const { - int i=0; - QueryIntValue( &i ); - return i; - } - /// Query as an unsigned integer. See IntAttribute() - unsigned UnsignedValue() const { - unsigned i=0; - QueryUnsignedValue( &i ); - return i; - } - /// Query as a boolean. See IntAttribute() - bool BoolValue() const { - bool b=false; - QueryBoolValue( &b ); - return b; - } - /// Query as a double. See IntAttribute() - double DoubleValue() const { - double d=0; - QueryDoubleValue( &d ); - return d; - } - /// Query as a float. See IntAttribute() - float FloatValue() const { - float f=0; - QueryFloatValue( &f ); - return f; - } - - /** QueryIntAttribute interprets the attribute as an integer, and returns the value - in the provided paremeter. The function will return XML_NO_ERROR on success, - and XML_WRONG_ATTRIBUTE_TYPE if the conversion is not successful. - */ - XMLError QueryIntValue( int* value ) const; - /// See QueryIntAttribute - XMLError QueryUnsignedValue( unsigned int* value ) const; - /// See QueryIntAttribute - XMLError QueryBoolValue( bool* value ) const; - /// See QueryIntAttribute - XMLError QueryDoubleValue( double* value ) const; - /// See QueryIntAttribute - XMLError QueryFloatValue( float* value ) const; - - /// Set the attribute to a string value. - void SetAttribute( const char* value ); - /// Set the attribute to value. - void SetAttribute( int value ); - /// Set the attribute to value. - void SetAttribute( unsigned value ); - /// Set the attribute to value. - void SetAttribute( bool value ); - /// Set the attribute to value. - void SetAttribute( double value ); - /// Set the attribute to value. - void SetAttribute( float value ); - -private: - enum { BUF_SIZE = 200 }; - - XMLAttribute() : _next( 0 ) {} - virtual ~XMLAttribute() {} - - XMLAttribute( const XMLAttribute& ); // not supported - void operator=( const XMLAttribute& ); // not supported - void SetName( const char* name ); - - char* ParseDeep( char* p, bool processEntities ); - - mutable StrPair _name; - mutable StrPair _value; - XMLAttribute* _next; - MemPool* _memPool; -}; - - -/** The element is a container class. It has a value, the element name, - and can contain other elements, text, comments, and unknowns. - Elements also contain an arbitrary number of attributes. -*/ -class CC_DLL XMLElement : public XMLNode -{ - friend class XMLBase; - friend class XMLDocument; -public: - /// Get the name of an element (which is the Value() of the node.) - const char* Name() const { - return Value(); - } - /// Set the name of the element. - void SetName( const char* str, bool staticMem=false ) { - SetValue( str, staticMem ); - } - - virtual XMLElement* ToElement() { - return this; - } - virtual const XMLElement* ToElement() const { - return this; - } - virtual bool Accept( XMLVisitor* visitor ) const; - - /** Given an attribute name, Attribute() returns the value - for the attribute of that name, or null if none - exists. For example: - - @verbatim - const char* value = ele->Attribute( "foo" ); - @endverbatim - - The 'value' parameter is normally null. However, if specified, - the attribute will only be returned if the 'name' and 'value' - match. This allow you to write code: - - @verbatim - if ( ele->Attribute( "foo", "bar" ) ) callFooIsBar(); - @endverbatim - - rather than: - @verbatim - if ( ele->Attribute( "foo" ) ) { - if ( strcmp( ele->Attribute( "foo" ), "bar" ) == 0 ) callFooIsBar(); - } - @endverbatim - */ - const char* Attribute( const char* name, const char* value=0 ) const; - - /** Given an attribute name, IntAttribute() returns the value - of the attribute interpreted as an integer. 0 will be - returned if there is an error. For a method with error - checking, see QueryIntAttribute() - */ - int IntAttribute( const char* name ) const { - int i=0; - QueryIntAttribute( name, &i ); - return i; - } - /// See IntAttribute() - unsigned UnsignedAttribute( const char* name ) const { - unsigned i=0; - QueryUnsignedAttribute( name, &i ); - return i; - } - /// See IntAttribute() - bool BoolAttribute( const char* name ) const { - bool b=false; - QueryBoolAttribute( name, &b ); - return b; - } - /// See IntAttribute() - double DoubleAttribute( const char* name ) const { - double d=0; - QueryDoubleAttribute( name, &d ); - return d; - } - /// See IntAttribute() - float FloatAttribute( const char* name ) const { - float f=0; - QueryFloatAttribute( name, &f ); - return f; - } - - /** Given an attribute name, QueryIntAttribute() returns - XML_NO_ERROR, XML_WRONG_ATTRIBUTE_TYPE if the conversion - can't be performed, or XML_NO_ATTRIBUTE if the attribute - doesn't exist. If successful, the result of the conversion - will be written to 'value'. If not successful, nothing will - be written to 'value'. This allows you to provide default - value: - - @verbatim - int value = 10; - QueryIntAttribute( "foo", &value ); // if "foo" isn't found, value will still be 10 - @endverbatim - */ - XMLError QueryIntAttribute( const char* name, int* value ) const { - const XMLAttribute* a = FindAttribute( name ); - if ( !a ) { - return XML_NO_ATTRIBUTE; - } - return a->QueryIntValue( value ); - } - /// See QueryIntAttribute() - XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const { - const XMLAttribute* a = FindAttribute( name ); - if ( !a ) { - return XML_NO_ATTRIBUTE; - } - return a->QueryUnsignedValue( value ); - } - /// See QueryIntAttribute() - XMLError QueryBoolAttribute( const char* name, bool* value ) const { - const XMLAttribute* a = FindAttribute( name ); - if ( !a ) { - return XML_NO_ATTRIBUTE; - } - return a->QueryBoolValue( value ); - } - /// See QueryIntAttribute() - XMLError QueryDoubleAttribute( const char* name, double* value ) const { - const XMLAttribute* a = FindAttribute( name ); - if ( !a ) { - return XML_NO_ATTRIBUTE; - } - return a->QueryDoubleValue( value ); - } - /// See QueryIntAttribute() - XMLError QueryFloatAttribute( const char* name, float* value ) const { - const XMLAttribute* a = FindAttribute( name ); - if ( !a ) { - return XML_NO_ATTRIBUTE; - } - return a->QueryFloatValue( value ); - } - - /// Sets the named attribute to value. - void SetAttribute( const char* name, const char* value ) { - XMLAttribute* a = FindOrCreateAttribute( name ); - a->SetAttribute( value ); - } - /// Sets the named attribute to value. - void SetAttribute( const char* name, int value ) { - XMLAttribute* a = FindOrCreateAttribute( name ); - a->SetAttribute( value ); - } - /// Sets the named attribute to value. - void SetAttribute( const char* name, unsigned value ) { - XMLAttribute* a = FindOrCreateAttribute( name ); - a->SetAttribute( value ); - } - /// Sets the named attribute to value. - void SetAttribute( const char* name, bool value ) { - XMLAttribute* a = FindOrCreateAttribute( name ); - a->SetAttribute( value ); - } - /// Sets the named attribute to value. - void SetAttribute( const char* name, double value ) { - XMLAttribute* a = FindOrCreateAttribute( name ); - a->SetAttribute( value ); - } - - /** - Delete an attribute. - */ - void DeleteAttribute( const char* name ); - - /// Return the first attribute in the list. - const XMLAttribute* FirstAttribute() const { - return _rootAttribute; - } - /// Query a specific attribute in the list. - const XMLAttribute* FindAttribute( const char* name ) const; - - /** Convenience function for easy access to the text inside an element. Although easy - and concise, GetText() is limited compared to getting the TiXmlText child - and accessing it directly. - - If the first child of 'this' is a TiXmlText, the GetText() - returns the character string of the Text node, else null is returned. - - This is a convenient method for getting the text of simple contained text: - @verbatim - This is text - const char* str = fooElement->GetText(); - @endverbatim - - 'str' will be a pointer to "This is text". - - Note that this function can be misleading. If the element foo was created from - this XML: - @verbatim - This is text - @endverbatim - - then the value of str would be null. The first child node isn't a text node, it is - another element. From this XML: - @verbatim - This is text - @endverbatim - GetText() will return "This is ". - */ - const char* GetText() const; - - /** - Convenience method to query the value of a child text node. This is probably best - shown by example. Given you have a document is this form: - @verbatim - - 1 - 1.4 - - @endverbatim - - The QueryIntText() and similar functions provide a safe and easier way to get to the - "value" of x and y. - - @verbatim - int x = 0; - float y = 0; // types of x and y are contrived for example - const XMLElement* xElement = pointElement->FirstChildElement( "x" ); - const XMLElement* yElement = pointElement->FirstChildElement( "y" ); - xElement->QueryIntText( &x ); - yElement->QueryFloatText( &y ); - @endverbatim - - @returns XML_SUCCESS (0) on success, XML_CAN_NOT_CONVERT_TEXT if the text cannot be converted - to the requested type, and XML_NO_TEXT_NODE if there is no child text to query. - - */ - XMLError QueryIntText( int* ival ) const; - /// See QueryIntText() - XMLError QueryUnsignedText( unsigned* uval ) const; - /// See QueryIntText() - XMLError QueryBoolText( bool* bval ) const; - /// See QueryIntText() - XMLError QueryDoubleText( double* dval ) const; - /// See QueryIntText() - XMLError QueryFloatText( float* fval ) const; - - // internal: - enum { - OPEN, // - CLOSED, // - CLOSING // - }; - int ClosingType() const { - return _closingType; - } - char* ParseDeep( char* p, StrPair* endTag ); - virtual XMLNode* ShallowClone( XMLDocument* document ) const; - virtual bool ShallowEqual( const XMLNode* compare ) const; - -private: - XMLElement( XMLDocument* doc ); - virtual ~XMLElement(); - XMLElement( const XMLElement& ); // not supported - void operator=( const XMLElement& ); // not supported - - XMLAttribute* FindAttribute( const char* name ); - XMLAttribute* FindOrCreateAttribute( const char* name ); - //void LinkAttribute( XMLAttribute* attrib ); - char* ParseAttributes( char* p ); - - int _closingType; - // The attribute list is ordered; there is no 'lastAttribute' - // because the list needs to be scanned for dupes before adding - // a new attribute. - XMLAttribute* _rootAttribute; -}; - - -enum Whitespace { - PRESERVE_WHITESPACE, - COLLAPSE_WHITESPACE -}; - - -/** A Document binds together all the functionality. - It can be saved, loaded, and printed to the screen. - All Nodes are connected and allocated to a Document. - If the Document is deleted, all its Nodes are also deleted. -*/ -class CC_DLL XMLDocument : public XMLNode -{ - friend class XMLElement; -public: - /// constructor - XMLDocument( bool processEntities = true, Whitespace = PRESERVE_WHITESPACE ); - ~XMLDocument(); - - virtual XMLDocument* ToDocument() { - return this; - } - virtual const XMLDocument* ToDocument() const { - return this; - } - - /** - Parse an XML file from a character string. - Returns XML_NO_ERROR (0) on success, or - an errorID. - - You may optionally pass in the 'nBytes', which is - the number of bytes which will be parsed. If not - specified, TinyXML will assume 'xml' points to a - null terminated string. - */ - XMLError Parse( const char* xml, size_t nBytes=(size_t)(-1) ); - - /** - Load an XML file from disk. - Returns XML_NO_ERROR (0) on success, or - an errorID. - */ - XMLError LoadFile( const char* filename ); - - /** - Load an XML file from disk. You are responsible - for providing and closing the FILE*. - - Returns XML_NO_ERROR (0) on success, or - an errorID. - */ - XMLError LoadFile( FILE* ); - - /** - Save the XML file to disk. - Returns XML_NO_ERROR (0) on success, or - an errorID. - */ - XMLError SaveFile( const char* filename, bool compact = false ); - - /** - Save the XML file to disk. You are responsible - for providing and closing the FILE*. - - Returns XML_NO_ERROR (0) on success, or - an errorID. - */ - XMLError SaveFile( FILE* fp, bool compact = false ); - - bool ProcessEntities() const { - return _processEntities; - } - Whitespace WhitespaceMode() const { - return _whitespace; - } - - /** - Returns true if this document has a leading Byte Order Mark of UTF8. - */ - bool HasBOM() const { - return _writeBOM; - } - /** Sets whether to write the BOM when writing the file. - */ - void SetBOM( bool useBOM ) { - _writeBOM = useBOM; - } - - /** Return the root element of DOM. Equivalent to FirstChildElement(). - To get the first node, use FirstChild(). - */ - XMLElement* RootElement() { - return FirstChildElement(); - } - const XMLElement* RootElement() const { - return FirstChildElement(); - } - - /** Print the Document. If the Printer is not provided, it will - print to stdout. If you provide Printer, this can print to a file: - @verbatim - XMLPrinter printer( fp ); - doc.Print( &printer ); - @endverbatim - - Or you can use a printer to print to memory: - @verbatim - XMLPrinter printer; - doc->Print( &printer ); - // printer.CStr() has a const char* to the XML - @endverbatim - */ - void Print( XMLPrinter* streamer=0 ); - virtual bool Accept( XMLVisitor* visitor ) const; - - /** - Create a new Element associated with - this Document. The memory for the Element - is managed by the Document. - */ - XMLElement* NewElement( const char* name ); - /** - Create a new Comment associated with - this Document. The memory for the Comment - is managed by the Document. - */ - XMLComment* NewComment( const char* comment ); - /** - Create a new Text associated with - this Document. The memory for the Text - is managed by the Document. - */ - XMLText* NewText( const char* text ); - /** - Create a new Declaration associated with - this Document. The memory for the object - is managed by the Document. - - If the 'text' param is null, the standard - declaration is used.: - @verbatim - - @endverbatim - */ - XMLDeclaration* NewDeclaration( const char* text=0 ); - /** - Create a new Unknown associated with - this Document. The memory forthe object - is managed by the Document. - */ - XMLUnknown* NewUnknown( const char* text ); - - /** - Delete a node associated with this document. - It will be unlinked from the DOM. - */ - void DeleteNode( XMLNode* node ) { - node->_parent->DeleteChild( node ); - } - - void SetError( XMLError error, const char* str1, const char* str2 ); - - /// Return true if there was an error parsing the document. - bool Error() const { - return _errorID != XML_NO_ERROR; - } - /// Return the errorID. - XMLError ErrorID() const { - return _errorID; - } - /// Return a possibly helpful diagnostic location or string. - const char* GetErrorStr1() const { - return _errorStr1; - } - /// Return a possibly helpful secondary diagnostic location or string. - const char* GetErrorStr2() const { - return _errorStr2; - } - /// If there is an error, print it to stdout. - void PrintError() const; - - // internal - char* Identify( char* p, XMLNode** node ); - - virtual XMLNode* ShallowClone( XMLDocument* /*document*/ ) const { - return 0; - } - virtual bool ShallowEqual( const XMLNode* /*compare*/ ) const { - return false; - } - -private: - XMLDocument( const XMLDocument& ); // not supported - void operator=( const XMLDocument& ); // not supported - void InitDocument(); - - bool _writeBOM; - bool _processEntities; - XMLError _errorID; - Whitespace _whitespace; - const char* _errorStr1; - const char* _errorStr2; - char* _charBuffer; - - MemPoolT< sizeof(XMLElement) > _elementPool; - MemPoolT< sizeof(XMLAttribute) > _attributePool; - MemPoolT< sizeof(XMLText) > _textPool; - MemPoolT< sizeof(XMLComment) > _commentPool; -}; - - -/** - A XMLHandle is a class that wraps a node pointer with null checks; this is - an incredibly useful thing. Note that XMLHandle is not part of the TinyXML - DOM structure. It is a separate utility class. - - Take an example: - @verbatim - - - - - - - @endverbatim - - Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very - easy to write a *lot* of code that looks like: - - @verbatim - XMLElement* root = document.FirstChildElement( "Document" ); - if ( root ) - { - XMLElement* element = root->FirstChildElement( "Element" ); - if ( element ) - { - XMLElement* child = element->FirstChildElement( "Child" ); - if ( child ) - { - XMLElement* child2 = child->NextSiblingElement( "Child" ); - if ( child2 ) - { - // Finally do something useful. - @endverbatim - - And that doesn't even cover "else" cases. XMLHandle addresses the verbosity - of such code. A XMLHandle checks for null pointers so it is perfectly safe - and correct to use: - - @verbatim - XMLHandle docHandle( &document ); - XMLElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild().NextSibling().ToElement(); - if ( child2 ) - { - // do something useful - @endverbatim - - Which is MUCH more concise and useful. - - It is also safe to copy handles - internally they are nothing more than node pointers. - @verbatim - XMLHandle handleCopy = handle; - @endverbatim - - See also XMLConstHandle, which is the same as XMLHandle, but operates on const objects. -*/ -class CC_DLL XMLHandle -{ -public: - /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. - XMLHandle( XMLNode* node ) { - _node = node; - } - /// Create a handle from a node. - XMLHandle( XMLNode& node ) { - _node = &node; - } - /// Copy constructor - XMLHandle( const XMLHandle& ref ) { - _node = ref._node; - } - /// Assignment - XMLHandle& operator=( const XMLHandle& ref ) { - _node = ref._node; - return *this; - } - - /// Get the first child of this handle. - XMLHandle FirstChild() { - return XMLHandle( _node ? _node->FirstChild() : 0 ); - } - /// Get the first child element of this handle. - XMLHandle FirstChildElement( const char* value=0 ) { - return XMLHandle( _node ? _node->FirstChildElement( value ) : 0 ); - } - /// Get the last child of this handle. - XMLHandle LastChild() { - return XMLHandle( _node ? _node->LastChild() : 0 ); - } - /// Get the last child element of this handle. - XMLHandle LastChildElement( const char* _value=0 ) { - return XMLHandle( _node ? _node->LastChildElement( _value ) : 0 ); - } - /// Get the previous sibling of this handle. - XMLHandle PreviousSibling() { - return XMLHandle( _node ? _node->PreviousSibling() : 0 ); - } - /// Get the previous sibling element of this handle. - XMLHandle PreviousSiblingElement( const char* _value=0 ) { - return XMLHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 ); - } - /// Get the next sibling of this handle. - XMLHandle NextSibling() { - return XMLHandle( _node ? _node->NextSibling() : 0 ); - } - /// Get the next sibling element of this handle. - XMLHandle NextSiblingElement( const char* _value=0 ) { - return XMLHandle( _node ? _node->NextSiblingElement( _value ) : 0 ); - } - - /// Safe cast to XMLNode. This can return null. - XMLNode* ToNode() { - return _node; - } - /// Safe cast to XMLElement. This can return null. - XMLElement* ToElement() { - return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 ); - } - /// Safe cast to XMLText. This can return null. - XMLText* ToText() { - return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 ); - } - /// Safe cast to XMLUnknown. This can return null. - XMLUnknown* ToUnknown() { - return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 ); - } - /// Safe cast to XMLDeclaration. This can return null. - XMLDeclaration* ToDeclaration() { - return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 ); - } - -private: - XMLNode* _node; -}; - - -/** - A variant of the XMLHandle class for working with const XMLNodes and Documents. It is the - same in all regards, except for the 'const' qualifiers. See XMLHandle for API. -*/ -class CC_DLL XMLConstHandle -{ -public: - XMLConstHandle( const XMLNode* node ) { - _node = node; - } - XMLConstHandle( const XMLNode& node ) { - _node = &node; - } - XMLConstHandle( const XMLConstHandle& ref ) { - _node = ref._node; - } - - XMLConstHandle& operator=( const XMLConstHandle& ref ) { - _node = ref._node; - return *this; - } - - const XMLConstHandle FirstChild() const { - return XMLConstHandle( _node ? _node->FirstChild() : 0 ); - } - const XMLConstHandle FirstChildElement( const char* value=0 ) const { - return XMLConstHandle( _node ? _node->FirstChildElement( value ) : 0 ); - } - const XMLConstHandle LastChild() const { - return XMLConstHandle( _node ? _node->LastChild() : 0 ); - } - const XMLConstHandle LastChildElement( const char* _value=0 ) const { - return XMLConstHandle( _node ? _node->LastChildElement( _value ) : 0 ); - } - const XMLConstHandle PreviousSibling() const { - return XMLConstHandle( _node ? _node->PreviousSibling() : 0 ); - } - const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const { - return XMLConstHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 ); - } - const XMLConstHandle NextSibling() const { - return XMLConstHandle( _node ? _node->NextSibling() : 0 ); - } - const XMLConstHandle NextSiblingElement( const char* _value=0 ) const { - return XMLConstHandle( _node ? _node->NextSiblingElement( _value ) : 0 ); - } - - - const XMLNode* ToNode() const { - return _node; - } - const XMLElement* ToElement() const { - return ( ( _node && _node->ToElement() ) ? _node->ToElement() : 0 ); - } - const XMLText* ToText() const { - return ( ( _node && _node->ToText() ) ? _node->ToText() : 0 ); - } - const XMLUnknown* ToUnknown() const { - return ( ( _node && _node->ToUnknown() ) ? _node->ToUnknown() : 0 ); - } - const XMLDeclaration* ToDeclaration() const { - return ( ( _node && _node->ToDeclaration() ) ? _node->ToDeclaration() : 0 ); - } - -private: - const XMLNode* _node; -}; - - -/** - Printing functionality. The XMLPrinter gives you more - options than the XMLDocument::Print() method. - - It can: - -# Print to memory. - -# Print to a file you provide. - -# Print XML without a XMLDocument. - - Print to Memory - - @verbatim - XMLPrinter printer; - doc->Print( &printer ); - SomeFunction( printer.CStr() ); - @endverbatim - - Print to a File - - You provide the file pointer. - @verbatim - XMLPrinter printer( fp ); - doc.Print( &printer ); - @endverbatim - - Print without a XMLDocument - - When loading, an XML parser is very useful. However, sometimes - when saving, it just gets in the way. The code is often set up - for streaming, and constructing the DOM is just overhead. - - The Printer supports the streaming case. The following code - prints out a trivially simple XML file without ever creating - an XML document. - - @verbatim - XMLPrinter printer( fp ); - printer.OpenElement( "foo" ); - printer.PushAttribute( "foo", "bar" ); - printer.CloseElement(); - @endverbatim -*/ -class CC_DLL XMLPrinter : public XMLVisitor -{ -public: - /** Construct the printer. If the FILE* is specified, - this will print to the FILE. Else it will print - to memory, and the result is available in CStr(). - If 'compact' is set to true, then output is created - with only required whitespace and newlines. - */ - XMLPrinter( FILE* file=0, bool compact = false ); - ~XMLPrinter() {} - - /** If streaming, write the BOM and declaration. */ - void PushHeader( bool writeBOM, bool writeDeclaration ); - /** If streaming, start writing an element. - The element must be closed with CloseElement() - */ - void OpenElement( const char* name ); - /// If streaming, add an attribute to an open element. - void PushAttribute( const char* name, const char* value ); - void PushAttribute( const char* name, int value ); - void PushAttribute( const char* name, unsigned value ); - void PushAttribute( const char* name, bool value ); - void PushAttribute( const char* name, double value ); - /// If streaming, close the Element. - void CloseElement(); - - /// Add a text node. - void PushText( const char* text, bool cdata=false ); - /// Add a text node from an integer. - void PushText( int value ); - /// Add a text node from an unsigned. - void PushText( unsigned value ); - /// Add a text node from a bool. - void PushText( bool value ); - /// Add a text node from a float. - void PushText( float value ); - /// Add a text node from a double. - void PushText( double value ); - - /// Add a comment - void PushComment( const char* comment ); - - void PushDeclaration( const char* value ); - void PushUnknown( const char* value ); - - virtual bool VisitEnter( const XMLDocument& /*doc*/ ); - virtual bool VisitExit( const XMLDocument& /*doc*/ ) { - return true; - } - - virtual bool VisitEnter( const XMLElement& element, const XMLAttribute* attribute ); - virtual bool VisitExit( const XMLElement& element ); - - virtual bool Visit( const XMLText& text ); - virtual bool Visit( const XMLComment& comment ); - virtual bool Visit( const XMLDeclaration& declaration ); - virtual bool Visit( const XMLUnknown& unknown ); - - /** - If in print to memory mode, return a pointer to - the XML file in memory. - */ - const char* CStr() const { - return _buffer.Mem(); - } - /** - If in print to memory mode, return the size - of the XML file in memory. (Note the size returned - includes the terminating null.) - */ - int CStrSize() const { - return _buffer.Size(); - } - -private: - void SealElement(); - void PrintSpace( int depth ); - void PrintString( const char*, bool restrictedEntitySet ); // prints out, after detecting entities. - void Print( const char* format, ... ); - - bool _elementJustOpened; - bool _firstElement; - FILE* _fp; - int _depth; - int _textDepth; - bool _processEntities; - bool _compactMode; - - enum { - ENTITY_RANGE = 64, - BUF_SIZE = 200 - }; - bool _entityFlag[ENTITY_RANGE]; - bool _restrictedEntityFlag[ENTITY_RANGE]; - - DynArray< const char*, 10 > _stack; - DynArray< char, 20 > _buffer; -#ifdef _MSC_VER - DynArray< char, 20 > _accumulator; -#endif -}; - - -} // tinyxml2 - - -#endif // TINYXML2_INCLUDED diff --git a/cocos/2d/support/zip_support/ioapi.cpp b/cocos/2d/support/zip_support/ioapi.cpp deleted file mode 100644 index 669ea36927..0000000000 --- a/cocos/2d/support/zip_support/ioapi.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - -*/ - -#include "ioapi.h" - -namespace cocos2d { - -voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) -{ - if (pfilefunc->zfile_func64.zopen64_file != NULL) - return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); - else - { - return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); - } -} - -long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) -{ - if (pfilefunc->zfile_func64.zseek64_file != NULL) - return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); - else - { - uLong offsetTruncated = (uLong)offset; - if (offsetTruncated != offset) - return -1; - else - return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); - } -} - -ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) -{ - if (pfilefunc->zfile_func64.zseek64_file != NULL) - return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); - else - { - uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); - if ((tell_uLong) == ((uLong)-1)) - return (ZPOS64_T)-1; - else - return tell_uLong; - } -} - -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) -{ - p_filefunc64_32->zfile_func64.zopen64_file = NULL; - p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; - p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; - p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; - p_filefunc64_32->zfile_func64.ztell64_file = NULL; - p_filefunc64_32->zfile_func64.zseek64_file = NULL; - p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; - p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; - p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; - p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; -} - - - -static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); -static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); -static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); -static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); -static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); - -static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) -{ - FILE* file = NULL; - const char* mode_fopen = NULL; - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; - else - if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; - else - if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; - - if ((filename!=NULL) && (mode_fopen != NULL)) - file = fopen(filename, mode_fopen); - return file; -} - -static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) -{ - FILE* file = NULL; - const char* mode_fopen = NULL; - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; - else - if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; - else - if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; - - if ((filename!=NULL) && (mode_fopen != NULL)) - { -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE || CC_TARGET_PLATFORM == CC_PLATFORM_BADA || CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY || CC_TARGET_PLATFORM == CC_PLATFORM_NACL || CC_TARGET_PLATFORM == CC_PLATFORM_EMSCRIPTEN) - file = NULL; -#else - file = fopen64((const char*)filename, mode_fopen); -#endif - } - - return file; -} - - -static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) -{ - uLong ret; - ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); - return ret; -} - -static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) -{ - uLong ret; - ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); - return ret; -} - -static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) -{ - long ret; - ret = ftell((FILE *)stream); - return ret; -} - - -static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) -{ - ZPOS64_T ret; -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE || CC_TARGET_PLATFORM == CC_PLATFORM_BADA || CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY || CC_TARGET_PLATFORM == CC_PLATFORM_NACL || CC_TARGET_PLATFORM == CC_PLATFORM_EMSCRIPTEN) - ret = 0; -#else - ret = ftello64((FILE *)stream); -#endif - return ret; -} - -static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) -{ - int fseek_origin=0; - long ret; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - fseek_origin = SEEK_CUR; - break; - case ZLIB_FILEFUNC_SEEK_END : - fseek_origin = SEEK_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - fseek_origin = SEEK_SET; - break; - default: return -1; - } - ret = 0; - if (fseek((FILE *)stream, offset, fseek_origin) != 0) - ret = -1; - return ret; -} - -static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) -{ -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE || CC_TARGET_PLATFORM == CC_PLATFORM_BADA || CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY || CC_TARGET_PLATFORM == CC_PLATFORM_NACL || CC_TARGET_PLATFORM == CC_PLATFORM_EMSCRIPTEN) - return -1; -#else - int fseek_origin=0; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - fseek_origin = SEEK_CUR; - break; - case ZLIB_FILEFUNC_SEEK_END : - fseek_origin = SEEK_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - fseek_origin = SEEK_SET; - break; - default: return -1; - } - if(fseeko64((FILE *)stream, offset, fseek_origin) != 0) - return -1; - return 0; -#endif -} - - -static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) -{ - int ret; - ret = fclose((FILE *)stream); - return ret; -} - -static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) -{ - int ret; - ret = ferror((FILE *)stream); - return ret; -} - -void fill_fopen_filefunc (zlib_filefunc_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen_file = fopen_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; - pzlib_filefunc_def->zwrite_file = fwrite_file_func; - pzlib_filefunc_def->ztell_file = ftell_file_func; - pzlib_filefunc_def->zseek_file = fseek_file_func; - pzlib_filefunc_def->zclose_file = fclose_file_func; - pzlib_filefunc_def->zerror_file = ferror_file_func; - pzlib_filefunc_def->opaque = NULL; -} - -void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen64_file = fopen64_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; - pzlib_filefunc_def->zwrite_file = fwrite_file_func; - pzlib_filefunc_def->ztell64_file = ftell64_file_func; - pzlib_filefunc_def->zseek64_file = fseek64_file_func; - pzlib_filefunc_def->zclose_file = fclose_file_func; - pzlib_filefunc_def->zerror_file = ferror_file_func; - pzlib_filefunc_def->opaque = NULL; -} - -} // end of namespace cocos2d diff --git a/cocos/2d/support/zip_support/ioapi.h b/cocos/2d/support/zip_support/ioapi.h deleted file mode 100644 index 575f44ece4..0000000000 --- a/cocos/2d/support/zip_support/ioapi.h +++ /dev/null @@ -1,201 +0,0 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - Changes - - Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) - Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. - More if/def section may be needed to support other platforms - Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. - (but you should use iowin32.c for windows instead) - -*/ - -#ifndef _ZLIBIOAPI64_H -#define _ZLIBIOAPI64_H - -#include "platform/CCPlatformConfig.h" - -#if (!defined(_WIN32)) && (!defined(WIN32)) - - // Linux needs this to support file operation on files larger then 4+GB - // But might need better if/def to select just the platforms that needs them. - - #ifndef __USE_FILE_OFFSET64 - #define __USE_FILE_OFFSET64 - #endif - #ifndef __USE_LARGEFILE64 - #define __USE_LARGEFILE64 - #endif - #ifndef _LARGEFILE64_SOURCE - #define _LARGEFILE64_SOURCE - #endif - #ifndef _FILE_OFFSET_BIT - #define _FILE_OFFSET_BIT 64 - #endif -#endif - -#include -#include -#include "zlib.h" - -namespace cocos2d { - -#ifndef OF -#define OF _Z_OF -#endif - -#if defined(USE_FILE32API) -#define fopen64 fopen -#define ftello64 ftell -#define fseeko64 fseek -#else -#ifdef _MSC_VER - #define fopen64 fopen - #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) - #define ftello64 _ftelli64 - #define fseeko64 _fseeki64 - #else // old MSC - #define ftello64 ftell - #define fseeko64 fseek - #endif -#endif -#endif - -/* -#ifndef ZPOS64_T - #ifdef _WIN32 - #define ZPOS64_T fpos_t - #else - #include - #define ZPOS64_T uint64_t - #endif -#endif -*/ - -#ifdef HAVE_MINIZIP64_CONF_H -#include "mz64conf.h" -#endif - -/* a type chosen by DEFINE */ -#ifdef HAVE_64BIT_INT_CUSTOM -typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; -#else -#ifdef HAS_STDINT_H -#include "stdint.h" -typedef uint64_t ZPOS64_T; -#else - - -#if defined(_MSC_VER) || defined(__BORLANDC__) -typedef unsigned __int64 ZPOS64_T; -#else -typedef unsigned long long int ZPOS64_T; -#endif -#endif -#endif - - - -#define ZLIB_FILEFUNC_SEEK_CUR (1) -#define ZLIB_FILEFUNC_SEEK_END (2) -#define ZLIB_FILEFUNC_SEEK_SET (0) - -#define ZLIB_FILEFUNC_MODE_READ (1) -#define ZLIB_FILEFUNC_MODE_WRITE (2) -#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) - -#define ZLIB_FILEFUNC_MODE_EXISTING (4) -#define ZLIB_FILEFUNC_MODE_CREATE (8) - - -#ifndef ZCALLBACK - #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) - #define ZCALLBACK CALLBACK - #else - #define ZCALLBACK - #endif -#endif - - - - -typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); -typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); -typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); - -typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); - - -/* here is the "old" 32 bits structure structure */ -typedef struct zlib_filefunc_def_s -{ - open_file_func zopen_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell_file_func ztell_file; - seek_file_func zseek_file; - close_file_func zclose_file; - testerror_file_func zerror_file; - voidpf opaque; -} zlib_filefunc_def; - -typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); - -typedef struct zlib_filefunc64_def_s -{ - open64_file_func zopen64_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell64_file_func ztell64_file; - seek64_file_func zseek64_file; - close_file_func zclose_file; - testerror_file_func zerror_file; - voidpf opaque; -} zlib_filefunc64_def; - -void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); -void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); - -/* now internal definition, only for zip.c and unzip.h */ -typedef struct zlib_filefunc64_32_def_s -{ - zlib_filefunc64_def zfile_func64; - open_file_func zopen32_file; - tell_file_func ztell32_file; - seek_file_func zseek32_file; -} zlib_filefunc64_32_def; - - -#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) -#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) -//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) -//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) -#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) -#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) - -voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); -long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); -ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); - -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); - -#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) -#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) -#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) - -} // end of namespace cocos2d - -#endif diff --git a/cocos/2d/support/zip_support/unzip.cpp b/cocos/2d/support/zip_support/unzip.cpp deleted file mode 100644 index 66cfeff16a..0000000000 --- a/cocos/2d/support/zip_support/unzip.cpp +++ /dev/null @@ -1,2161 +0,0 @@ -/* unzip.c -- IO for uncompress .zip files using zlib - Version 1.1, February 14h, 2010 - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications of Unzip for Zip64 - Copyright (C) 2007-2008 Even Rouault - - Modifications for Zip64 support on both zip and unzip - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - - ------------------------------------------------------------------------------------ - Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of - compatibility with older software. The following is from the original crypt.c. - Code woven in by Terry Thorsen 1/2003. - - Copyright (c) 1990-2000 Info-ZIP. All rights reserved. - - See the accompanying file LICENSE, version 2000-Apr-09 or later - (the contents of which are also included in zip.h) for terms of use. - If, for some reason, all these files are missing, the Info-ZIP license - also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html - - crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] - - The encryption/decryption parts of this source code (as opposed to the - non-echoing password parts) were originally written in Europe. The - whole source package can be freely distributed, including from the USA. - (Prior to January 2000, re-export from the US was a violation of US law.) - - This encryption code is a direct transcription of the algorithm from - Roger Schlafly, described by Phil Katz in the file appnote.txt. This - file (appnote.txt) is distributed with the PKZIP program (even in the - version without encryption capabilities). - - ------------------------------------------------------------------------------------ - - Changes in unzip.c - - 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos - 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz* - 2007-2008 - Even Rouault - Remove old C style function prototypes - 2007-2008 - Even Rouault - Add unzip support for ZIP64 - - Copyright (C) 2007-2008 Even Rouault - - - Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). - Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G - should only read the compressed/uncompressed size from the Zip64 format if - the size from normal header was 0xFFFFFFFF - Oct-2009 - Mathias Svensson - Applied some bug fixes from patches received from Gilles Vollant - Oct-2009 - Mathias Svensson - Applied support to unzip files with compression method BZIP2 (bzip2 lib is required) - Patch created by Daniel Borca - - Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer - - Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson - -*/ - - -#include -#include -#include - -#ifndef NOUNCRYPT - #define NOUNCRYPT -#endif - -#include "zlib.h" -#include "unzip.h" - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - -namespace cocos2d { - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - - -#ifndef CASESENSITIVITYDEFAULT_NO -# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) -# define CASESENSITIVITYDEFAULT_NO -# endif -#endif - - -#ifndef UNZ_BUFSIZE -#define UNZ_BUFSIZE (16384) -#endif - -#ifndef UNZ_MAXFILENAMEINZIP -#define UNZ_MAXFILENAMEINZIP (256) -#endif - -#ifndef ALLOC -# define ALLOC(size) (malloc(size)) -#endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif - -#define SIZECENTRALDIRITEM (0x2e) -#define SIZEZIPLOCALHEADER (0x1e) - - -const char unz_copyright[] = - " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; - -/* unz_file_info_interntal contain internal info about a file in zipfile*/ -typedef struct unz_file_info64_internal_s -{ - ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ -} unz_file_info64_internal; - - -/* file_in_zip_read_info_s contain internal information about a file in zipfile, - when reading and decompress it */ -typedef struct -{ - char *read_buffer; /* internal buffer for compressed data */ - z_stream stream; /* zLib stream structure for inflate */ - -#ifdef HAVE_BZIP2 - bz_stream bstream; /* bzLib stream structure for bziped */ -#endif - - ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ - uLong stream_initialised; /* flag set if stream structure is initialized*/ - - ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ - uInt size_local_extrafield;/* size of the local extra field */ - ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/ - ZPOS64_T total_out_64; - - uLong crc32; /* crc32 of all data uncompressed */ - uLong crc32_wait; /* crc32 we must obtain after decompress all */ - ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ - ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ - zlib_filefunc64_32_def z_filefunc; - voidpf filestream; /* io structure of the zipfile */ - uLong compression_method; /* compression method (0==store) */ - ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - int raw; -} file_in_zip64_read_info_s; - - -/* unz64_s contain internal information about the zipfile -*/ -typedef struct -{ - zlib_filefunc64_32_def z_filefunc; - int is64bitOpenFunction; - voidpf filestream; /* io structure of the zipfile */ - unz_global_info64 gi; /* public global information */ - ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - ZPOS64_T num_file; /* number of the current file in the zipfile*/ - ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/ - ZPOS64_T current_file_ok; /* flag about the usability of the current file*/ - ZPOS64_T central_pos; /* position of the beginning of the central dir*/ - - ZPOS64_T size_central_dir; /* size of the central directory */ - ZPOS64_T offset_central_dir; /* offset of start of central directory with - respect to the starting disk number */ - - unz_file_info64 cur_file_info; /* public info about the current file in zip*/ - unz_file_info64_internal cur_file_info_internal; /* private info about it*/ - file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current - file if we are decompressing it */ - int encrypted; - - int isZip64; - -# ifndef NOUNCRYPT - unsigned long keys[3]; /* keys defining the pseudo-random sequence */ - const unsigned long* pcrc_32_tab; -# endif -} unz64_s; - - -#ifndef NOUNCRYPT -#include "crypt.h" -#endif - -/* =========================================================================== - Read a byte from a gz_stream; update next_in and avail_in. Return EOF - for end of file. - IN assertion: the stream s has been successfully opened for reading. -*/ - - -local int unz64local_getByte OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - int *pi)); - -local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) -{ - unsigned char c; - int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); - if (err==1) - { - *pi = (int)c; - return UNZ_OK; - } - else - { - if (ZERROR64(*pzlib_filefunc_def,filestream)) - return UNZ_ERRNO; - else - return UNZ_EOF; - } -} - - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets -*/ -local int unz64local_getShort OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX) -{ - uLong x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<8; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int unz64local_getLong OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX) -{ - uLong x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<8; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<16; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<24; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int unz64local_getLong64 OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - ZPOS64_T *pX)); - - -local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - ZPOS64_T *pX) -{ - ZPOS64_T x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (ZPOS64_T)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<8; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<16; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<24; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<32; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<40; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<48; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<56; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -/* My own strcmpi / strcasecmp */ -local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) -{ - for (;;) - { - char c1=*(fileName1++); - char c2=*(fileName2++); - if ((c1>='a') && (c1<='z')) - c1 -= 0x20; - if ((c2>='a') && (c2<='z')) - c2 -= 0x20; - if (c1=='\0') - return ((c2=='\0') ? 0 : -1); - if (c2=='\0') - return 1; - if (c1c2) - return 1; - } -} - - -#ifdef CASESENSITIVITYDEFAULT_NO -#define CASESENSITIVITYDEFAULTVALUE 2 -#else -#define CASESENSITIVITYDEFAULTVALUE 1 -#endif - -#ifndef STRCMPCASENOSENTIVEFUNCTION -#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal -#endif - -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparison is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparison is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is default of your operating system - (like 1 on Unix, 2 on Windows) - -*/ -int ZEXPORT unzStringFileNameCompare (const char* fileName1, - const char* fileName2, - int iCaseSensitivity) - -{ - if (iCaseSensitivity==0) - iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; - - if (iCaseSensitivity==1) - return strcmp(fileName1,fileName2); - - return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); -} - -#ifndef BUFREADCOMMENT -#define BUFREADCOMMENT (0x400) -#endif - -/* - Locate the Central directory of a zipfile (at the end, just before - the global comment) -*/ -local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); -local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) -{ - unsigned char* buf; - ZPOS64_T uSizeFile; - ZPOS64_T uBackRead; - ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ - ZPOS64_T uPosFound=0; - - if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; - - - uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); - if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) - break; - - if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - return uPosFound; -} - - -/* - Locate the Central directory 64 of a zipfile (at the end, just before - the global comment) -*/ -local ZPOS64_T unz64local_SearchCentralDir64 OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream)); - -local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream) -{ - unsigned char* buf; - ZPOS64_T uSizeFile; - ZPOS64_T uBackRead; - ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ - ZPOS64_T uPosFound=0; - uLong uL; - ZPOS64_T relativeOffset; - - if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; - - - uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); - if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) - break; - - if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - if (uPosFound == 0) - return 0; - - /* Zip64 end of central directory locator */ - if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) - return 0; - - /* the signature, already checked */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - - /* number of the disk with the start of the zip64 end of central directory */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - if (uL != 0) - return 0; - - /* relative offset of the zip64 end of central directory record */ - if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) - return 0; - - /* total number of disks */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - if (uL != 1) - return 0; - - /* Goto end of central directory record */ - if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) - return 0; - - /* the signature */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - - if (uL != 0x06064b50) - return 0; - - return relativeOffset; -} - -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer - "zlib/zlib114.zip". - If the zipfile cannot be opened (file doesn't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. -*/ -local unzFile unzOpenInternal (const void *path, - zlib_filefunc64_32_def* pzlib_filefunc64_32_def, - int is64bitOpenFunction) -{ - unz64_s us; - unz64_s *s; - ZPOS64_T central_pos; - uLong uL; - - uLong number_disk; /* number of the current dist, used for - spanning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used - for spanning ZIP, unsupported, always 0*/ - ZPOS64_T number_entry_CD; /* total number of entries in - the central dir - (same than number_entry on nospan) */ - - int err=UNZ_OK; - - if (unz_copyright[0]!=' ') - return NULL; - - us.z_filefunc.zseek32_file = NULL; - us.z_filefunc.ztell32_file = NULL; - if (pzlib_filefunc64_32_def==NULL) - fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); - else - us.z_filefunc = *pzlib_filefunc64_32_def; - us.is64bitOpenFunction = is64bitOpenFunction; - - - - us.filestream = ZOPEN64(us.z_filefunc, - path, - ZLIB_FILEFUNC_MODE_READ | - ZLIB_FILEFUNC_MODE_EXISTING); - if (us.filestream==NULL) - return NULL; - - central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); - if (central_pos) - { - uLong uS; - ZPOS64_T uL64; - - us.isZip64 = 1; - - if (ZSEEK64(us.z_filefunc, us.filestream, - central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=UNZ_ERRNO; - - /* the signature, already checked */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - - /* size of zip64 end of central directory record */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK) - err=UNZ_ERRNO; - - /* version made by */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) - err=UNZ_ERRNO; - - /* version needed to extract */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of this disk */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of the disk with the start of the central directory */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central directory on this disk */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central directory */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - if ((number_entry_CD!=us.gi.number_entry) || - (number_disk_with_CD!=0) || - (number_disk!=0)) - err=UNZ_BADZIPFILE; - - /* size of the central directory */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - /* offset of start of central directory with respect to the - starting disk number */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - us.gi.size_comment = 0; - } - else - { - central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); - if (central_pos==0) - err=UNZ_ERRNO; - - us.isZip64 = 0; - - if (ZSEEK64(us.z_filefunc, us.filestream, - central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=UNZ_ERRNO; - - /* the signature, already checked */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of this disk */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of the disk with the start of the central directory */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central dir on this disk */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - us.gi.number_entry = uL; - - /* total number of entries in the central dir */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - number_entry_CD = uL; - - if ((number_entry_CD!=us.gi.number_entry) || - (number_disk_with_CD!=0) || - (number_disk!=0)) - err=UNZ_BADZIPFILE; - - /* size of the central directory */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - us.size_central_dir = uL; - - /* offset of start of central directory with respect to the - starting disk number */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - us.offset_central_dir = uL; - - /* zipfile comment length */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) - err=UNZ_ERRNO; - } - - if ((central_pospfile_in_zip_read!=NULL) - unzCloseCurrentFile(file); - - ZCLOSE64(s->z_filefunc, s->filestream); - TRYFREE(s); - return UNZ_OK; -} - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ -int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) -{ - unz64_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - *pglobal_info=s->gi; - return UNZ_OK; -} - -int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) -{ - unz64_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - /* to do : check if number_entry is not truncated */ - pglobal_info32->number_entry = (uLong)s->gi.number_entry; - pglobal_info32->size_comment = s->gi.size_comment; - return UNZ_OK; -} -/* - Translate date/time from Dos format to tm_unz (readable more easily) -*/ -local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) -{ - ZPOS64_T uDate; - uDate = (ZPOS64_T)(ulDosDate>>16); - ptm->tm_mday = (uInt)(uDate&0x1f) ; - ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; - ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; - - ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); - ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; - ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; -} - -/* - Get Info about the current file in the zipfile, with internal only info -*/ -local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, - unz_file_info64 *pfile_info, - unz_file_info64_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -local int unz64local_GetCurrentFileInfoInternal (unzFile file, - unz_file_info64 *pfile_info, - unz_file_info64_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize) -{ - unz64_s* s; - unz_file_info64 file_info; - unz_file_info64_internal file_info_internal; - int err=UNZ_OK; - uLong uMagic; - long lSeek=0; - uLong uL; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (ZSEEK64(s->z_filefunc, s->filestream, - s->pos_in_central_dir+s->byte_before_the_zipfile, - ZLIB_FILEFUNC_SEEK_SET)!=0) - err=UNZ_ERRNO; - - - /* we check the magic */ - if (err==UNZ_OK) - { - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x02014b50) - err=UNZ_BADZIPFILE; - } - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) - err=UNZ_ERRNO; - - unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - file_info.compressed_size = uL; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - file_info.uncompressed_size = uL; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) - err=UNZ_ERRNO; - - // relative offset of local header - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - file_info_internal.offset_curfile = uL; - - lSeek+=file_info.size_filename; - if ((err==UNZ_OK) && (szFileName!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_filename0) && (fileNameBufferSize>0)) - if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - lSeek -= uSizeRead; - } - - // Read extrafield - if ((err==UNZ_OK) && (extraField!=NULL)) - { - ZPOS64_T uSizeRead ; - if (file_info.size_file_extraz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - } - - if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) - if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - - lSeek += file_info.size_file_extra - (uLong)uSizeRead; - } - else - lSeek += file_info.size_file_extra; - - - if ((err==UNZ_OK) && (file_info.size_file_extra != 0)) - { - uLong acc = 0; - - // since lSeek now points to after the extra field we need to move back - lSeek -= file_info.size_file_extra; - - if (lSeek!=0) - { - if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - } - - while(acc < file_info.size_file_extra) - { - uLong headerId; - uLong dataSize; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK) - err=UNZ_ERRNO; - - /* ZIP64 extra fields */ - if (headerId == 0x0001) - { - uLong uL; - - if(file_info.uncompressed_size == (ZPOS64_T)(unsigned long)-1) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info.compressed_size == (ZPOS64_T)(unsigned long)-1) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info_internal.offset_curfile == (ZPOS64_T)(unsigned long)-1) - { - /* Relative Header offset */ - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info.disk_num_start == (unsigned long)-1) - { - /* Disk Start Number */ - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - } - - } - else - { - if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0) - err=UNZ_ERRNO; - } - - acc += 2 + 2 + dataSize; - } - } - - if ((err==UNZ_OK) && (szComment!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_file_commentz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) { - //lSeek=0; - } - else - err=UNZ_ERRNO; - } - - if ((file_info.size_file_comment>0) && (commentBufferSize>0)) - if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - //lSeek+=file_info.size_file_comment - uSizeRead; - } - //else - // lSeek+=file_info.size_file_comment; - - - if ((err==UNZ_OK) && (pfile_info!=NULL)) - *pfile_info=file_info; - - if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) - *pfile_info_internal=file_info_internal; - - return err; -} - - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. -*/ -int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, - unz_file_info64 * pfile_info, - char * szFileName, uLong fileNameBufferSize, - void *extraField, uLong extraFieldBufferSize, - char* szComment, uLong commentBufferSize) -{ - return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, - szFileName,fileNameBufferSize, - extraField,extraFieldBufferSize, - szComment,commentBufferSize); -} - -int ZEXPORT unzGetCurrentFileInfo (unzFile file, - unz_file_info * pfile_info, - char * szFileName, uLong fileNameBufferSize, - void *extraField, uLong extraFieldBufferSize, - char* szComment, uLong commentBufferSize) -{ - int err; - unz_file_info64 file_info64; - err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, - szFileName,fileNameBufferSize, - extraField,extraFieldBufferSize, - szComment,commentBufferSize); - if (err==UNZ_OK) - { - pfile_info->version = file_info64.version; - pfile_info->version_needed = file_info64.version_needed; - pfile_info->flag = file_info64.flag; - pfile_info->compression_method = file_info64.compression_method; - pfile_info->dosDate = file_info64.dosDate; - pfile_info->crc = file_info64.crc; - - pfile_info->size_filename = file_info64.size_filename; - pfile_info->size_file_extra = file_info64.size_file_extra; - pfile_info->size_file_comment = file_info64.size_file_comment; - - pfile_info->disk_num_start = file_info64.disk_num_start; - pfile_info->internal_fa = file_info64.internal_fa; - pfile_info->external_fa = file_info64.external_fa; - - pfile_info->tmu_date = file_info64.tmu_date, - - - pfile_info->compressed_size = (uLong)file_info64.compressed_size; - pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size; - - } - return err; -} - -/* - Set the current file of the zipfile to the first file - with retrieving an information about the file. - return UNZ_OK if there is no problem -*/ -int ZEXPORT unzGoToFirstFile64 (unzFile file, - unz_file_info64 *pfile_info, - char *szFileName, - uLong fileNameBufferSize) -{ - int err=UNZ_OK; - unz64_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - s->pos_in_central_dir=s->offset_central_dir; - s->num_file=0; - err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - szFileName,fileNameBufferSize,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - if (pfile_info) - *pfile_info = s->cur_file_info; - return err; -} - -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ -int ZEXPORT unzGoToFirstFile (unzFile file) -{ - return unzGoToFirstFile64(file, NULL, NULL, 0); -} - -/* - Set the current file of the zipfile to the next file - with retrieving an information about the file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ -int ZEXPORT unzGoToNextFile64 (unzFile file, - unz_file_info64 *pfile_info, - char *szFileName, - uLong fileNameBufferSize) -{ - unz64_s* s; - int err; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ - if (s->num_file+1==s->gi.number_entry) - return UNZ_END_OF_LIST_OF_FILE; - - s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + - s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; - s->num_file++; - err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - szFileName,fileNameBufferSize,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - if (pfile_info) - *pfile_info = s->cur_file_info; - return err; -} - -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ -int ZEXPORT unzGoToNextFile (unzFile file) -{ - return unzGoToNextFile64(file, NULL, NULL, 0); -} - - -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzipStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ -int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) -{ - unz64_s* s; - int err; - - /* We remember the 'current' position in the file so that we can jump - * back there if we fail. - */ - unz_file_info64 cur_file_infoSaved; - unz_file_info64_internal cur_file_info_internalSaved; - ZPOS64_T num_fileSaved; - ZPOS64_T pos_in_central_dirSaved; - - - if (file==NULL) - return UNZ_PARAMERROR; - - if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) - return UNZ_PARAMERROR; - - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - - /* Save the current state */ - num_fileSaved = s->num_file; - pos_in_central_dirSaved = s->pos_in_central_dir; - cur_file_infoSaved = s->cur_file_info; - cur_file_info_internalSaved = s->cur_file_info_internal; - - err = unzGoToFirstFile(file); - - while (err == UNZ_OK) - { - char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; - err = unzGetCurrentFileInfo64(file,NULL, - szCurrentFileName,sizeof(szCurrentFileName)-1, - NULL,0,NULL,0); - if (err == UNZ_OK) - { - if (unzStringFileNameCompare(szCurrentFileName, - szFileName,iCaseSensitivity)==0) - return UNZ_OK; - err = unzGoToNextFile(file); - } - } - - /* We failed, so restore the state of the 'current file' to where we - * were. - */ - s->num_file = num_fileSaved ; - s->pos_in_central_dir = pos_in_central_dirSaved ; - s->cur_file_info = cur_file_infoSaved; - s->cur_file_info_internal = cur_file_info_internalSaved; - return err; -} - - -/* -/////////////////////////////////////////// -// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) -// I need random access -// -// Further optimization could be realized by adding an ability -// to cache the directory in memory. The goal being a single -// comprehensive file read to put the file I need in a memory. -*/ - -/* -typedef struct unz_file_pos_s -{ - ZPOS64_T pos_in_zip_directory; // offset in file - ZPOS64_T num_of_file; // # of file -} unz_file_pos; -*/ - -int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) -{ - unz64_s* s; - - if (file==NULL || file_pos==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - - file_pos->pos_in_zip_directory = s->pos_in_central_dir; - file_pos->num_of_file = s->num_file; - - return UNZ_OK; -} - -int ZEXPORT unzGetFilePos( - unzFile file, - unz_file_pos* file_pos) -{ - unz64_file_pos file_pos64; - int err = unzGetFilePos64(file,&file_pos64); - if (err==UNZ_OK) - { - file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory; - file_pos->num_of_file = (uLong)file_pos64.num_of_file; - } - return err; -} - -int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) -{ - unz64_s* s; - int err; - - if (file==NULL || file_pos==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - - /* jump to the right spot */ - s->pos_in_central_dir = file_pos->pos_in_zip_directory; - s->num_file = file_pos->num_of_file; - - /* set the current file */ - err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - /* return results */ - s->current_file_ok = (err == UNZ_OK); - return err; -} - -int ZEXPORT unzGoToFilePos( - unzFile file, - unz_file_pos* file_pos) -{ - unz64_file_pos file_pos64; - if (file_pos == NULL) - return UNZ_PARAMERROR; - - file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory; - file_pos64.num_of_file = file_pos->num_of_file; - return unzGoToFilePos64(file,&file_pos64); -} - -/* -// Unzip Helper Functions - should be here? -/////////////////////////////////////////// -*/ - -/* - Read the local header of the current zipfile - Check the coherency of the local header and info in the end of central - directory about this file - store in *piSizeVar the size of extra info in local header - (filename and size of extra field data) -*/ -local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar, - ZPOS64_T * poffset_local_extrafield, - uInt * psize_local_extrafield) -{ - uLong uMagic,uData,uFlags; - uLong size_filename; - uLong size_extra_field; - int err=UNZ_OK; - - *piSizeVar = 0; - *poffset_local_extrafield = 0; - *psize_local_extrafield = 0; - - if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + - s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - - if (err==UNZ_OK) - { - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x04034b50) - err=UNZ_BADZIPFILE; - } - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) - err=UNZ_ERRNO; -/* - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) - err=UNZ_BADZIPFILE; -*/ - if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) - err=UNZ_BADZIPFILE; - - if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && -/* #ifdef HAVE_BZIP2 */ - (s->cur_file_info.compression_method!=Z_BZIP2ED) && -/* #endif */ - (s->cur_file_info.compression_method!=Z_DEFLATED)) - err=UNZ_BADZIPFILE; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ - err=UNZ_ERRNO; - else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ - err=UNZ_ERRNO; - else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) - err=UNZ_BADZIPFILE; - - *piSizeVar += (uInt)size_filename; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) - err=UNZ_ERRNO; - *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + - SIZEZIPLOCALHEADER + size_filename; - *psize_local_extrafield = (uInt)size_extra_field; - - *piSizeVar += (uInt)size_extra_field; - - return err; -} - -/* - Open for reading data the current file in the zipfile. - If there is no error and the file is opened, the return value is UNZ_OK. -*/ -int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, - int* level, int raw, const char* password) -{ - int err=UNZ_OK; - uInt iSizeVar; - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - ZPOS64_T offset_local_extrafield; /* offset of the local extra field */ - uInt size_local_extrafield; /* size of the local extra field */ -# ifndef NOUNCRYPT - char source[12]; -# else - if (password != NULL) - return UNZ_PARAMERROR; -# endif - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_PARAMERROR; - - if (s->pfile_in_zip_read != NULL) - unzCloseCurrentFile(file); - - if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) - return UNZ_BADZIPFILE; - - pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s)); - if (pfile_in_zip_read_info==NULL) - return UNZ_INTERNALERROR; - - pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); - pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; - pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; - pfile_in_zip_read_info->pos_local_extrafield=0; - pfile_in_zip_read_info->raw=raw; - - if (pfile_in_zip_read_info->read_buffer==NULL) - { - TRYFREE(pfile_in_zip_read_info); - return UNZ_INTERNALERROR; - } - - pfile_in_zip_read_info->stream_initialised=0; - - if (method!=NULL) - *method = (int)s->cur_file_info.compression_method; - - if (level!=NULL) - { - *level = 6; - switch (s->cur_file_info.flag & 0x06) - { - case 6 : *level = 1; break; - case 4 : *level = 2; break; - case 2 : *level = 9; break; - } - } - - if ((s->cur_file_info.compression_method!=0) && -/* #ifdef HAVE_BZIP2 */ - (s->cur_file_info.compression_method!=Z_BZIP2ED) && -/* #endif */ - (s->cur_file_info.compression_method!=Z_DEFLATED)) { - - //err=UNZ_BADZIPFILE; - } - pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; - pfile_in_zip_read_info->crc32=0; - pfile_in_zip_read_info->total_out_64=0; - pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method; - pfile_in_zip_read_info->filestream=s->filestream; - pfile_in_zip_read_info->z_filefunc=s->z_filefunc; - pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; - - pfile_in_zip_read_info->stream.total_out = 0; - - if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw)) - { -#ifdef HAVE_BZIP2 - pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0; - pfile_in_zip_read_info->bstream.bzfree = (free_func)0; - pfile_in_zip_read_info->bstream.opaque = (voidpf)0; - pfile_in_zip_read_info->bstream.state = (voidpf)0; - - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; - pfile_in_zip_read_info->stream.zfree = (free_func)0; - pfile_in_zip_read_info->stream.opaque = (voidpf)0; - pfile_in_zip_read_info->stream.next_in = (voidpf)0; - pfile_in_zip_read_info->stream.avail_in = 0; - - err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0); - if (err == Z_OK) - pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; - else - { - TRYFREE(pfile_in_zip_read_info); - return err; - } -#else - pfile_in_zip_read_info->raw=1; -#endif - } - else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) - { - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; - pfile_in_zip_read_info->stream.zfree = (free_func)0; - pfile_in_zip_read_info->stream.opaque = (voidpf)0; - pfile_in_zip_read_info->stream.next_in = 0; - pfile_in_zip_read_info->stream.avail_in = 0; - - err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); - if (err == Z_OK) - pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; - else - { - TRYFREE(pfile_in_zip_read_info); - return err; - } - /* windowBits is passed < 0 to tell that there is no zlib header. - * Note that in this case inflate *requires* an extra "dummy" byte - * after the compressed stream in order to complete decompression and - * return Z_STREAM_END. - * In unzip, i don't wait absolutely Z_STREAM_END because I known the - * size of both compressed and uncompressed data - */ - } - pfile_in_zip_read_info->rest_read_compressed = - s->cur_file_info.compressed_size ; - pfile_in_zip_read_info->rest_read_uncompressed = - s->cur_file_info.uncompressed_size ; - - - pfile_in_zip_read_info->pos_in_zipfile = - s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + - iSizeVar; - - pfile_in_zip_read_info->stream.avail_in = (uInt)0; - - s->pfile_in_zip_read = pfile_in_zip_read_info; - s->encrypted = 0; - -# ifndef NOUNCRYPT - if (password != NULL) - { - int i; - s->pcrc_32_tab = get_crc_table(); - init_keys(password,s->keys,s->pcrc_32_tab); - if (ZSEEK64(s->z_filefunc, s->filestream, - s->pfile_in_zip_read->pos_in_zipfile + - s->pfile_in_zip_read->byte_before_the_zipfile, - SEEK_SET)!=0) - return UNZ_INTERNALERROR; - if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12) - return UNZ_INTERNALERROR; - - for (i = 0; i<12; i++) - zdecode(s->keys,s->pcrc_32_tab,source[i]); - - s->pfile_in_zip_read->pos_in_zipfile+=12; - s->encrypted=1; - } -# endif - - - return UNZ_OK; -} - -int ZEXPORT unzOpenCurrentFile (unzFile file) -{ - return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); -} - -int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password) -{ - return unzOpenCurrentFile3(file, NULL, NULL, 0, password); -} - -int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw) -{ - return unzOpenCurrentFile3(file, method, level, raw, NULL); -} - -/** Addition for GDAL : START */ - -ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - s=(unz64_s*)file; - if (file==NULL) - return 0; //UNZ_PARAMERROR; - pfile_in_zip_read_info=s->pfile_in_zip_read; - if (pfile_in_zip_read_info==NULL) - return 0; //UNZ_PARAMERROR; - return pfile_in_zip_read_info->pos_in_zipfile + - pfile_in_zip_read_info->byte_before_the_zipfile; -} - -/** Addition for GDAL : END */ - -/* - Read bytes from the current file. - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if some bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ -int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) -{ - int err=UNZ_OK; - uInt iRead = 0; - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if (pfile_in_zip_read_info->read_buffer == NULL) - return UNZ_END_OF_LIST_OF_FILE; - if (len==0) - return 0; - - pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; - - pfile_in_zip_read_info->stream.avail_out = (uInt)len; - - if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && - (!(pfile_in_zip_read_info->raw))) - pfile_in_zip_read_info->stream.avail_out = - (uInt)pfile_in_zip_read_info->rest_read_uncompressed; - - if ((len>pfile_in_zip_read_info->rest_read_compressed+ - pfile_in_zip_read_info->stream.avail_in) && - (pfile_in_zip_read_info->raw)) - pfile_in_zip_read_info->stream.avail_out = - (uInt)pfile_in_zip_read_info->rest_read_compressed+ - pfile_in_zip_read_info->stream.avail_in; - - while (pfile_in_zip_read_info->stream.avail_out>0) - { - if ((pfile_in_zip_read_info->stream.avail_in==0) && - (pfile_in_zip_read_info->rest_read_compressed>0)) - { - uInt uReadThis = UNZ_BUFSIZE; - if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; - if (uReadThis == 0) - return UNZ_EOF; - if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - pfile_in_zip_read_info->pos_in_zipfile + - pfile_in_zip_read_info->byte_before_the_zipfile, - ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - if (ZREAD64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - pfile_in_zip_read_info->read_buffer, - uReadThis)!=uReadThis) - return UNZ_ERRNO; - - -# ifndef NOUNCRYPT - if(s->encrypted) - { - uInt i; - for(i=0;iread_buffer[i] = - zdecode(s->keys,s->pcrc_32_tab, - pfile_in_zip_read_info->read_buffer[i]); - } -# endif - - - pfile_in_zip_read_info->pos_in_zipfile += uReadThis; - - pfile_in_zip_read_info->rest_read_compressed-=uReadThis; - - pfile_in_zip_read_info->stream.next_in = - (Bytef*)pfile_in_zip_read_info->read_buffer; - pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; - } - - if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) - { - uInt uDoCopy,i ; - - if ((pfile_in_zip_read_info->stream.avail_in == 0) && - (pfile_in_zip_read_info->rest_read_compressed == 0)) - return (iRead==0) ? UNZ_EOF : iRead; - - if (pfile_in_zip_read_info->stream.avail_out < - pfile_in_zip_read_info->stream.avail_in) - uDoCopy = pfile_in_zip_read_info->stream.avail_out ; - else - uDoCopy = pfile_in_zip_read_info->stream.avail_in ; - - for (i=0;istream.next_out+i) = - *(pfile_in_zip_read_info->stream.next_in+i); - - pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy; - - pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, - pfile_in_zip_read_info->stream.next_out, - uDoCopy); - pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; - pfile_in_zip_read_info->stream.avail_in -= uDoCopy; - pfile_in_zip_read_info->stream.avail_out -= uDoCopy; - pfile_in_zip_read_info->stream.next_out += uDoCopy; - pfile_in_zip_read_info->stream.next_in += uDoCopy; - pfile_in_zip_read_info->stream.total_out += uDoCopy; - iRead += uDoCopy; - } - else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) - { -#ifdef HAVE_BZIP2 - uLong uTotalOutBefore,uTotalOutAfter; - const Bytef *bufBefore; - uLong uOutThis; - - pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in; - pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in; - pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in; - pfile_in_zip_read_info->bstream.total_in_hi32 = 0; - pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out; - pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out; - pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out; - pfile_in_zip_read_info->bstream.total_out_hi32 = 0; - - uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32; - bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out; - - err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream); - - uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32; - uOutThis = uTotalOutAfter-uTotalOutBefore; - - pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; - - pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis)); - pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; - iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); - - pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in; - pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in; - pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32; - pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out; - pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out; - pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32; - - if (err==BZ_STREAM_END) - return (iRead==0) ? UNZ_EOF : iRead; - if (err!=BZ_OK) - break; -#endif - } // end Z_BZIP2ED - else - { - ZPOS64_T uTotalOutBefore,uTotalOutAfter; - const Bytef *bufBefore; - ZPOS64_T uOutThis; - int flush=Z_SYNC_FLUSH; - - uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; - bufBefore = pfile_in_zip_read_info->stream.next_out; - - /* - if ((pfile_in_zip_read_info->rest_read_uncompressed == - pfile_in_zip_read_info->stream.avail_out) && - (pfile_in_zip_read_info->rest_read_compressed == 0)) - flush = Z_FINISH; - */ - err=inflate(&pfile_in_zip_read_info->stream,flush); - - if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) - err = Z_DATA_ERROR; - - uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; - uOutThis = uTotalOutAfter-uTotalOutBefore; - - pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; - - pfile_in_zip_read_info->crc32 = - crc32(pfile_in_zip_read_info->crc32,bufBefore, - (uInt)(uOutThis)); - - pfile_in_zip_read_info->rest_read_uncompressed -= - uOutThis; - - iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); - - if (err==Z_STREAM_END) - return (iRead==0) ? UNZ_EOF : iRead; - if (err!=Z_OK) - break; - } - } - - if (err==Z_OK) - return iRead; - return err; -} - - -/* - Give the current position in uncompressed data -*/ -z_off_t ZEXPORT unztell (unzFile file) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - return (z_off_t)pfile_in_zip_read_info->stream.total_out; -} - -ZPOS64_T ZEXPORT unztell64 (unzFile file) -{ - - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return (ZPOS64_T)-1; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return (ZPOS64_T)-1; - - return pfile_in_zip_read_info->total_out_64; -} - - -/* - return 1 if the end of file was reached, 0 elsewhere -*/ -int ZEXPORT unzeof (unzFile file) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - if (pfile_in_zip_read_info->rest_read_uncompressed == 0) - return 1; - else - return 0; -} - - - -/* -Read extra field from the current file (opened by unzOpenCurrentFile) -This is the local-header version of the extra field (sometimes, there is -more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field that can be read - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ -int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - uInt read_now; - ZPOS64_T size_to_read; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - size_to_read = (pfile_in_zip_read_info->size_local_extrafield - - pfile_in_zip_read_info->pos_local_extrafield); - - if (buf==NULL) - return (int)size_to_read; - - if (len>size_to_read) - read_now = (uInt)size_to_read; - else - read_now = (uInt)len ; - - if (read_now==0) - return 0; - - if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - pfile_in_zip_read_info->offset_local_extrafield + - pfile_in_zip_read_info->pos_local_extrafield, - ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - if (ZREAD64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - buf,read_now)!=read_now) - return UNZ_ERRNO; - - return (int)read_now; -} - -/* - Close the file in zip opened with unzipOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ -int ZEXPORT unzCloseCurrentFile (unzFile file) -{ - int err=UNZ_OK; - - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && - (!pfile_in_zip_read_info->raw)) - { - if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) - err=UNZ_CRCERROR; - } - - - TRYFREE(pfile_in_zip_read_info->read_buffer); - pfile_in_zip_read_info->read_buffer = NULL; - if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) - inflateEnd(&pfile_in_zip_read_info->stream); -#ifdef HAVE_BZIP2 - else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED) - BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream); -#endif - - - pfile_in_zip_read_info->stream_initialised = 0; - TRYFREE(pfile_in_zip_read_info); - - s->pfile_in_zip_read=NULL; - - return err; -} - - -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ -int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) -{ - unz64_s* s; - uLong uReadThis ; - if (file==NULL) - return (int)UNZ_PARAMERROR; - s=(unz64_s*)file; - - uReadThis = uSizeBuf; - if (uReadThis>s->gi.size_comment) - uReadThis = s->gi.size_comment; - - if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - if (uReadThis>0) - { - *szComment='\0'; - if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) - return UNZ_ERRNO; - } - - if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) - *(szComment+s->gi.size_comment)='\0'; - return (int)uReadThis; -} - -/* Additions by RX '2004 */ -ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) -{ - unz64_s* s; - - if (file==NULL) - return 0; //UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return 0; - if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) - if (s->num_file==s->gi.number_entry) - return 0; - return s->pos_in_central_dir; -} - -uLong ZEXPORT unzGetOffset (unzFile file) -{ - ZPOS64_T offset64; - - if (file==NULL) - return 0; //UNZ_PARAMERROR; - offset64 = unzGetOffset64(file); - return (uLong)offset64; -} - -int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) -{ - unz64_s* s; - int err; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - - s->pos_in_central_dir = pos; - s->num_file = s->gi.number_entry; /* hack */ - err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - return err; -} - -int ZEXPORT unzSetOffset (unzFile file, uLong pos) -{ - return unzSetOffset64(file,pos); -} - -} // end of namespace cocos2d diff --git a/cocos/2d/support/zip_support/unzip.h b/cocos/2d/support/zip_support/unzip.h deleted file mode 100644 index 54e73a55ea..0000000000 --- a/cocos/2d/support/zip_support/unzip.h +++ /dev/null @@ -1,455 +0,0 @@ -/* unzip.h -- IO for uncompress .zip files using zlib - Version 1.1, February 14h, 2010 - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications of Unzip for Zip64 - Copyright (C) 2007-2008 Even Rouault - - Modifications for Zip64 support on both zip and unzip - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - --------------------------------------------------------------------------------- - - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - --------------------------------------------------------------------------------- - - Changes - - See header of unzip64.c - -*/ - -#ifndef _unz64_H -#define _unz64_H - -#include "CCPlatformDefine.h" - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#ifndef _ZLIBIOAPI_H -#include "ioapi.h" -#endif - -#ifdef HAVE_BZIP2 -#include "bzlib.h" -#endif - -#define Z_BZIP2ED 12 - -#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagunzFile__ { int unused; } unzFile__; -typedef unzFile__ *unzFile; -#else -typedef voidp unzFile; -#endif - - -#define UNZ_OK (0) -#define UNZ_END_OF_LIST_OF_FILE (-100) -#define UNZ_ERRNO (Z_ERRNO) -#define UNZ_EOF (0) -#define UNZ_PARAMERROR (-102) -#define UNZ_BADZIPFILE (-103) -#define UNZ_INTERNALERROR (-104) -#define UNZ_CRCERROR (-105) - -namespace cocos2d { - -/* tm_unz contain date/time info */ -typedef struct tm_unz_s -{ - uInt tm_sec; /* seconds after the minute - [0,59] */ - uInt tm_min; /* minutes after the hour - [0,59] */ - uInt tm_hour; /* hours since midnight - [0,23] */ - uInt tm_mday; /* day of the month - [1,31] */ - uInt tm_mon; /* months since January - [0,11] */ - uInt tm_year; /* years - [1980..2044] */ -} tm_unz; - -/* unz_global_info structure contain global data about the ZIPfile - These data comes from the end of central dir */ -typedef struct unz_global_info64_s -{ - ZPOS64_T number_entry; /* total number of entries in - the central dir on this disk */ - uLong size_comment; /* size of the global comment of the zipfile */ -} unz_global_info64; - -typedef struct unz_global_info_s -{ - uLong number_entry; /* total number of entries in - the central dir on this disk */ - uLong size_comment; /* size of the global comment of the zipfile */ -} unz_global_info; - -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_info64_s -{ - uLong version; /* version made by 2 bytes */ - uLong version_needed; /* version needed to extract 2 bytes */ - uLong flag; /* general purpose bit flag 2 bytes */ - uLong compression_method; /* compression method 2 bytes */ - uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ - uLong crc; /* crc-32 4 bytes */ - ZPOS64_T compressed_size; /* compressed size 8 bytes */ - ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ - uLong size_filename; /* filename length 2 bytes */ - uLong size_file_extra; /* extra field length 2 bytes */ - uLong size_file_comment; /* file comment length 2 bytes */ - - uLong disk_num_start; /* disk number start 2 bytes */ - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ - - tm_unz tmu_date; -} unz_file_info64; - -typedef struct unz_file_info_s -{ - uLong version; /* version made by 2 bytes */ - uLong version_needed; /* version needed to extract 2 bytes */ - uLong flag; /* general purpose bit flag 2 bytes */ - uLong compression_method; /* compression method 2 bytes */ - uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ - uLong crc; /* crc-32 4 bytes */ - uLong compressed_size; /* compressed size 4 bytes */ - uLong uncompressed_size; /* uncompressed size 4 bytes */ - uLong size_filename; /* filename length 2 bytes */ - uLong size_file_extra; /* extra field length 2 bytes */ - uLong size_file_comment; /* file comment length 2 bytes */ - - uLong disk_num_start; /* disk number start 2 bytes */ - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ - - tm_unz tmu_date; -} unz_file_info; - -int CC_DLL unzStringFileNameCompare OF ((const char* fileName1, - const char* fileName2, - int iCaseSensitivity)); -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparison is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparison is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is default of your operating system - (like 1 on Unix, 2 on Windows) -*/ - - -unzFile CC_DLL unzOpen OF((const char *path)); -unzFile CC_DLL unzOpen64 OF((const void *path)); -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer - "zlib/zlib113.zip". - If the zipfile cannot be opened (file don't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. - the "64" function take a const void* pointer, because the path is just the - value passed to the open64_file_func callback. - Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path - is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* - does not describe the reality -*/ - - -unzFile CC_DLL unzOpen2 OF((const char *path, - zlib_filefunc_def* pzlib_filefunc_def)); -/* - Open a Zip file, like unzOpen, but provide a set of file low level API - for read/write the zip file (see ioapi.h) -*/ - -unzFile CC_DLL unzOpen2_64 OF((const void *path, - zlib_filefunc64_def* pzlib_filefunc_def)); -/* - Open a Zip file, like unz64Open, but provide a set of file low level API - for read/write the zip file (see ioapi.h) -*/ - -int CC_DLL unzClose OF((unzFile file)); -/* - Close a ZipFile opened with unzipOpen. - If there is files inside the .Zip opened with unzOpenCurrentFile (see later), - these files MUST be closed with unzipCloseCurrentFile before call unzipClose. - return UNZ_OK if there is no problem. */ - -int CC_DLL unzGetGlobalInfo OF((unzFile file, - unz_global_info *pglobal_info)); - -int CC_DLL unzGetGlobalInfo64 OF((unzFile file, - unz_global_info64 *pglobal_info)); -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ - - -int CC_DLL unzGetGlobalComment OF((unzFile file, - char *szComment, - uLong uSizeBuf)); -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ - - -/***************************************************************************/ -/* Unzip package allow you browse the directory of the zipfile */ - -int CC_DLL unzGoToFirstFile OF((unzFile file)); - -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ - -int CC_DLL unzGoToFirstFile64 OF((unzFile file, - unz_file_info64 *pfile_info, - char *szFileName, - uLong fileNameBufferSize)); -/* - Set the current file of the zipfile to the first file - with retrieving an information about the file. - return UNZ_OK if there is no problem -*/ - -int CC_DLL unzGoToNextFile OF((unzFile file)); -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ - -int CC_DLL unzGoToNextFile64 OF((unzFile file, - unz_file_info64 *pfile_info, - char *szFileName, - uLong fileNameBufferSize)); -/* - Set the current file of the zipfile to the next file - with retrieving an information about the file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ - -int CC_DLL unzLocateFile OF((unzFile file, - const char *szFileName, - int iCaseSensitivity)); -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ - - -/* ****************************************** */ -/* Ryan supplied functions */ -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_pos_s -{ - uLong pos_in_zip_directory; /* offset in zip file directory */ - uLong num_of_file; /* # of file */ -} unz_file_pos; - -int CC_DLL unzGetFilePos( - unzFile file, - unz_file_pos* file_pos); - -int CC_DLL unzGoToFilePos( - unzFile file, - unz_file_pos* file_pos); - -typedef struct unz64_file_pos_s -{ - ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ - ZPOS64_T num_of_file; /* # of file */ -} unz64_file_pos; - -int CC_DLL unzGetFilePos64( - unzFile file, - unz64_file_pos* file_pos); - -int CC_DLL unzGoToFilePos64( - unzFile file, - const unz64_file_pos* file_pos); - -/* ****************************************** */ - -int CC_DLL unzGetCurrentFileInfo64 OF((unzFile file, - unz_file_info64 *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -int CC_DLL unzGetCurrentFileInfo OF((unzFile file, - unz_file_info *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); -/* - Get Info about the current file - if pfile_info!=NULL, the *pfile_info structure will contain some info about - the current file - if szFileName!=NULL, the filename string will be copied in szFileName - (fileNameBufferSize is the size of the buffer) - if extraField!=NULL, the extra field information will be copied in extraField - (extraFieldBufferSize is the size of the buffer). - This is the Central-header version of the extra field - if szComment!=NULL, the comment string of the file will be copied in szComment - (commentBufferSize is the size of the buffer) -*/ - - -/** Addition for GDAL : START */ - -ZPOS64_T CC_DLL unzGetCurrentFileZStreamPos64 OF((unzFile file)); - -/** Addition for GDAL : END */ - - -/***************************************************************************/ -/* for reading the content of the current zipfile, you can open it, read data - from it, and close it (you can close it before reading all the file) - */ - -int CC_DLL unzOpenCurrentFile OF((unzFile file)); -/* - Open for reading data the current file in the zipfile. - If there is no error, the return value is UNZ_OK. -*/ - -int CC_DLL unzOpenCurrentFilePassword OF((unzFile file, - const char* password)); -/* - Open for reading data the current file in the zipfile. - password is a crypting password - If there is no error, the return value is UNZ_OK. -*/ - -int CC_DLL unzOpenCurrentFile2 OF((unzFile file, - int* method, - int* level, - int raw)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - -int CC_DLL unzOpenCurrentFile3 OF((unzFile file, - int* method, - int* level, - int raw, - const char* password)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - - -int CC_DLL unzCloseCurrentFile OF((unzFile file)); -/* - Close the file in zip opened with unzOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ - -int CC_DLL unzReadCurrentFile OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read bytes from the current file (opened by unzOpenCurrentFile) - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if some bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ - -z_off_t CC_DLL unztell OF((unzFile file)); - -ZPOS64_T CC_DLL unztell64 OF((unzFile file)); -/* - Give the current position in uncompressed data -*/ - -int CC_DLL unzeof OF((unzFile file)); -/* - return 1 if the end of file was reached, 0 elsewhere -*/ - -int CC_DLL unzGetLocalExtrafield OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read extra field from the current file (opened by unzOpenCurrentFile) - This is the local-header version of the extra field (sometimes, there is - more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ - -/***************************************************************************/ - -/* Get the current file offset */ -ZPOS64_T CC_DLL unzGetOffset64 (unzFile file); -uLong CC_DLL unzGetOffset (unzFile file); - -/* Set the current file offset */ -int CC_DLL unzSetOffset64 (unzFile file, ZPOS64_T pos); -int CC_DLL unzSetOffset (unzFile file, uLong pos); - -} // end of namespace cocos2d - -#endif /* _unz64_H */ diff --git a/cocos/2d/support/data_support/uthash.h b/cocos/2d/uthash.h similarity index 100% rename from cocos/2d/support/data_support/uthash.h rename to cocos/2d/uthash.h diff --git a/cocos/2d/support/data_support/utlist.h b/cocos/2d/utlist.h similarity index 100% rename from cocos/2d/support/data_support/utlist.h rename to cocos/2d/utlist.h diff --git a/cocos/platform/CCPlatformConfig.h b/cocos/platform/CCPlatformConfig.h deleted file mode 100644 index 5ba0757dac..0000000000 --- a/cocos/platform/CCPlatformConfig.h +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __CC_PLATFORM_CONFIG_H__ -#define __CC_PLATFORM_CONFIG_H__ - -/** -Config of cocos2d-x project, per target platform. -*/ - -////////////////////////////////////////////////////////////////////////// -// pre configure -////////////////////////////////////////////////////////////////////////// - -// define supported target platform macro which CC uses. -#define CC_PLATFORM_UNKNOWN 0 -#define CC_PLATFORM_IOS 1 -#define CC_PLATFORM_ANDROID 2 -#define CC_PLATFORM_WIN32 3 -#define CC_PLATFORM_MARMALADE 4 -#define CC_PLATFORM_LINUX 5 -#define CC_PLATFORM_BADA 6 -#define CC_PLATFORM_BLACKBERRY 7 -#define CC_PLATFORM_MAC 8 -#define CC_PLATFORM_NACL 9 -#define CC_PLATFORM_EMSCRIPTEN 10 -#define CC_PLATFORM_TIZEN 11 -#define CC_PLATFORM_QT5 12 - -// Determine target platform by compile environment macro. -#define CC_TARGET_PLATFORM CC_PLATFORM_UNKNOWN - -// mac -#if defined(CC_TARGET_OS_MAC) -#undef CC_TARGET_PLATFORM -#define CC_TARGET_PLATFORM CC_PLATFORM_MAC -#endif - -// iphone -#if defined(CC_TARGET_OS_IPHONE) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_IOS -#endif - -// android -#if defined(ANDROID) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_ANDROID -#endif - -// win32 -#if defined(WIN32) && defined(_WINDOWS) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_WIN32 -#endif - -// linux -#if defined(LINUX) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_LINUX -#endif - -// marmalade -#if defined(MARMALADE) -#undef CC_TARGET_PLATFORM -#define CC_TARGET_PLATFORM CC_PLATFORM_MARMALADE -#endif - -// bada -#if defined(SHP) -#undef CC_TARGET_PLATFORM -#define CC_TARGET_PLATFORM CC_PLATFORM_BADA -#endif - -// qnx -#if defined(__QNX__) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_BLACKBERRY -#endif - -// native client -#if defined(__native_client__) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_NACL -#endif - -// Emscripten -#if defined(EMSCRIPTEN) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_EMSCRIPTEN -#endif - -// tizen -#if defined(TIZEN) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_TIZEN -#endif - -// qt5 -#if defined(CC_TARGET_QT5) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_QT5 -#endif - -////////////////////////////////////////////////////////////////////////// -// post configure -////////////////////////////////////////////////////////////////////////// - -// check user set platform -#if ! CC_TARGET_PLATFORM - #error "Cannot recognize the target platform; are you targeting an unsupported platform?" -#endif - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) -#pragma warning (disable:4127) -#endif // CC_PLATFORM_WIN32 - -#endif // __CC_PLATFORM_CONFIG_H__ - diff --git a/cocos/platform/CCPlatformMacros.h b/cocos/platform/CCPlatformMacros.h deleted file mode 100644 index fca1255c0d..0000000000 --- a/cocos/platform/CCPlatformMacros.h +++ /dev/null @@ -1,301 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -#ifndef __CC_PLATFORM_MACROS_H__ -#define __CC_PLATFORM_MACROS_H__ - -/** - * define some platform specific macros - */ -#include "ccConfig.h" -#include "CCPlatformConfig.h" -#include "CCPlatformDefine.h" - -/** - * define a create function for a specific type, such as Layer - * @param \__TYPE__ class type to add create(), such as Layer - */ -#define CREATE_FUNC(__TYPE__) \ -static __TYPE__* create() \ -{ \ - __TYPE__ *pRet = new __TYPE__(); \ - if (pRet && pRet->init()) \ - { \ - pRet->autorelease(); \ - return pRet; \ - } \ - else \ - { \ - delete pRet; \ - pRet = NULL; \ - return NULL; \ - } \ -} - -/** - * define a node function for a specific type, such as Layer - * @param \__TYPE__ class type to add node(), such as Layer - * @deprecated This interface will be deprecated sooner or later. - */ -#define NODE_FUNC(__TYPE__) \ -CC_DEPRECATED_ATTRIBUTE static __TYPE__* node() \ -{ \ - __TYPE__ *pRet = new __TYPE__(); \ - if (pRet && pRet->init()) \ - { \ - pRet->autorelease(); \ - return pRet; \ - } \ - else \ - { \ - delete pRet; \ - pRet = NULL; \ - return NULL; \ - } \ -} - -/** @def CC_ENABLE_CACHE_TEXTURE_DATA -Enable it if you want to cache the texture data. -Not enabling for Emscripten any more -- doesn't seem necessary and don't want -to be different from other platforms unless there's a good reason. - -It's new in cocos2d-x since v0.99.5 -*/ -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) - #define CC_ENABLE_CACHE_TEXTURE_DATA 1 -#else - #define CC_ENABLE_CACHE_TEXTURE_DATA 0 -#endif - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_EMSCRIPTEN) - /* Application will crash in glDrawElements function on some win32 computers and some android devices. - Indices should be bound again while drawing to avoid this bug. - */ - #define CC_REBIND_INDICES_BUFFER 1 -#else - #define CC_REBIND_INDICES_BUFFER 0 -#endif - -// generic macros - -// namespace cocos2d {} -#ifdef __cplusplus - #define NS_CC_BEGIN namespace cocos2d { - #define NS_CC_END } - #define USING_NS_CC using namespace cocos2d -#else - #define NS_CC_BEGIN - #define NS_CC_END - #define USING_NS_CC -#endif - -/** CC_PROPERTY_READONLY is used to declare a protected variable. - We can use getter to read the variable. - @param varType the type of variable. - @param varName variable name. - @param funName "get + funName" will be the name of the getter. - @warning The getter is a public virtual function, you should rewrite it first. - The variables and methods declared after CC_PROPERTY_READONLY are all public. - If you need protected or private, please declare. - */ -#define CC_PROPERTY_READONLY(varType, varName, funName)\ -protected: varType varName;\ -public: virtual varType get##funName(void) const; - -#define CC_PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName)\ -protected: varType varName;\ -public: virtual const varType& get##funName(void) const; - -/** CC_PROPERTY is used to declare a protected variable. - We can use getter to read the variable, and use the setter to change the variable. - @param varType the type of variable. - @param varName variable name. - @param funName "get + funName" will be the name of the getter. - "set + funName" will be the name of the setter. - @warning The getter and setter are public virtual functions, you should rewrite them first. - The variables and methods declared after CC_PROPERTY are all public. - If you need protected or private, please declare. - */ -#define CC_PROPERTY(varType, varName, funName)\ -protected: varType varName;\ -public: virtual varType get##funName(void);\ -public: virtual void set##funName(varType var); - -#define CC_PROPERTY_PASS_BY_REF(varType, varName, funName)\ -protected: varType varName;\ -public: virtual const varType& get##funName(void) const;\ -public: virtual void set##funName(const varType& var); - -/** CC_SYNTHESIZE_READONLY is used to declare a protected variable. - We can use getter to read the variable. - @param varType the type of variable. - @param varName variable name. - @param funName "get + funName" will be the name of the getter. - @warning The getter is a public inline function. - The variables and methods declared after CC_SYNTHESIZE_READONLY are all public. - If you need protected or private, please declare. - */ -#define CC_SYNTHESIZE_READONLY(varType, varName, funName)\ -protected: varType varName;\ -public: virtual varType get##funName(void) const { return varName; } - -#define CC_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\ -protected: varType varName;\ -public: virtual const varType& get##funName(void) const { return varName; } - -/** CC_SYNTHESIZE is used to declare a protected variable. - We can use getter to read the variable, and use the setter to change the variable. - @param varType the type of variable. - @param varName variable name. - @param funName "get + funName" will be the name of the getter. - "set + funName" will be the name of the setter. - @warning The getter and setter are public inline functions. - The variables and methods declared after CC_SYNTHESIZE are all public. - If you need protected or private, please declare. - */ -#define CC_SYNTHESIZE(varType, varName, funName)\ -protected: varType varName;\ -public: virtual varType get##funName(void) const { return varName; }\ -public: virtual void set##funName(varType var){ varName = var; } - -#define CC_SYNTHESIZE_PASS_BY_REF(varType, varName, funName)\ -protected: varType varName;\ -public: virtual const varType& get##funName(void) const { return varName; }\ -public: virtual void set##funName(const varType& var){ varName = var; } - -#define CC_SYNTHESIZE_RETAIN(varType, varName, funName) \ -private: varType varName; \ -public: virtual varType get##funName(void) const { return varName; } \ -public: virtual void set##funName(varType var) \ -{ \ - if (varName != var) \ - { \ - CC_SAFE_RETAIN(var); \ - CC_SAFE_RELEASE(varName); \ - varName = var; \ - } \ -} - -#define CC_SAFE_DELETE(p) do { delete (p); (p) = nullptr; } while(0) -#define CC_SAFE_DELETE_ARRAY(p) do { if(p) { delete[] (p); (p) = nullptr; } } while(0) -#define CC_SAFE_FREE(p) do { if(p) { free(p); (p) = nullptr; } } while(0) -#define CC_SAFE_RELEASE(p) do { if(p) { (p)->release(); } } while(0) -#define CC_SAFE_RELEASE_NULL(p) do { if(p) { (p)->release(); (p) = nullptr; } } while(0) -#define CC_SAFE_RETAIN(p) do { if(p) { (p)->retain(); } } while(0) -#define CC_BREAK_IF(cond) if(cond) break - -#define __CCLOGWITHFUNCTION(s, ...) \ - log("%s : %s",__FUNCTION__, String::createWithFormat(s, ##__VA_ARGS__)->getCString()) - -// cocos2d debug -#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 -#define CCLOG(...) do {} while (0) -#define CCLOGINFO(...) do {} while (0) -#define CCLOGERROR(...) do {} while (0) -#define CCLOGWARN(...) do {} while (0) - -#elif COCOS2D_DEBUG == 1 -#define CCLOG(format, ...) cocos2d::log(format, ##__VA_ARGS__) -#define CCLOGERROR(format,...) cocos2d::log(format, ##__VA_ARGS__) -#define CCLOGINFO(format,...) do {} while (0) -#define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__) - -#elif COCOS2D_DEBUG > 1 -#define CCLOG(format, ...) cocos2d::log(format, ##__VA_ARGS__) -#define CCLOGERROR(format,...) cocos2d::log(format, ##__VA_ARGS__) -#define CCLOGINFO(format,...) cocos2d::log(format, ##__VA_ARGS__) -#define CCLOGWARN(...) __CCLOGWITHFUNCTION(__VA_ARGS__) -#endif // COCOS2D_DEBUG - -// Lua engine debug -#if !defined(COCOS2D_DEBUG) || COCOS2D_DEBUG == 0 || CC_LUA_ENGINE_DEBUG == 0 -#define LUALOG(...) -#else -#define LUALOG(format, ...) cocos2d::log(format, ##__VA_ARGS__) -#endif // Lua engine debug - -#if defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUG__ == 4) && (__GNUC_MINOR__ >= 4))) \ - || (defined(__clang__) && (__clang_major__ >= 3)) -#define CC_DISABLE_COPY(Class) \ -private: \ - Class(const Class &) = delete; \ - Class &operator =(const Class &) = delete; -#else -#define CC_DISABLE_COPY(Class) \ -private: \ - Class(const Class &); \ - Class &operator =(const Class &); -#endif - -/* - * only certain compilers support __attribute__((deprecated)) - */ -#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) - #define CC_DEPRECATED_ATTRIBUTE __attribute__((deprecated)) -#elif _MSC_VER >= 1400 //vs 2005 or higher - #define CC_DEPRECATED_ATTRIBUTE __declspec(deprecated) -#else - #define CC_DEPRECATED_ATTRIBUTE -#endif - -/* - * only certain compiler support __attribute__((format)) - * formatPos - 1-based position of format string argument - * argPos - 1-based position of first format-dependent argument - */ -#if defined(__GNUC__) && (__GNUC__ >= 4) -#define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos))) -#elif defined(__has_attribute) - #if __has_attribute(format) - #define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos))) - #endif // __has_attribute(format) -#else -#define CC_FORMAT_PRINTF(formatPos, argPos) -#endif - -#if defined(_MSC_VER) -#define CC_FORMAT_PRINTF_SIZE_T "%08lX" -#else -#define CC_FORMAT_PRINTF_SIZE_T "%08zX" -#endif - -#ifdef __GNUC__ -#define CC_UNUSED __attribute__ ((unused)) -#else -#define CC_UNUSED -#endif - -// -// CC_REQUIRES_NULL_TERMINATION -// -#if !defined(CC_REQUIRES_NULL_TERMINATION) - #if defined(__APPLE_CC__) && (__APPLE_CC__ >= 5549) - #define CC_REQUIRES_NULL_TERMINATION __attribute__((sentinel(0,1))) - #elif defined(__GNUC__) - #define CC_REQUIRES_NULL_TERMINATION __attribute__((sentinel)) - #else - #define CC_REQUIRES_NULL_TERMINATION - #endif -#endif - -#endif // __CC_PLATFORM_MACROS_H__ diff --git a/cocos/platform/cocoa/CCAffineTransform.cpp b/cocos/platform/cocoa/CCAffineTransform.cpp deleted file mode 100644 index 2e39f344cc..0000000000 --- a/cocos/platform/cocoa/CCAffineTransform.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "CCAffineTransform.h" -#include -#include - -using namespace std; - - -NS_CC_BEGIN - -AffineTransform __CCAffineTransformMake(float a, float b, float c, float d, float tx, float ty) -{ - AffineTransform t; - t.a = a; t.b = b; t.c = c; t.d = d; t.tx = tx; t.ty = ty; - return t; -} - -Point __CCPointApplyAffineTransform(const Point& point, const AffineTransform& t) -{ - Point p; - p.x = (float)((double)t.a * point.x + (double)t.c * point.y + t.tx); - p.y = (float)((double)t.b * point.x + (double)t.d * point.y + t.ty); - return p; -} - -Size __CCSizeApplyAffineTransform(const Size& size, const AffineTransform& t) -{ - Size s; - s.width = (float)((double)t.a * size.width + (double)t.c * size.height); - s.height = (float)((double)t.b * size.width + (double)t.d * size.height); - return s; -} - - -AffineTransform AffineTransformMakeIdentity() -{ - return __CCAffineTransformMake(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); -} - -extern const AffineTransform AffineTransformIdentity = AffineTransformMakeIdentity(); -const AffineTransform AffineTransform::IDENTITY = AffineTransformMakeIdentity(); - -Rect RectApplyAffineTransform(const Rect& rect, const AffineTransform& anAffineTransform) -{ - float top = rect.getMinY(); - float left = rect.getMinX(); - float right = rect.getMaxX(); - float bottom = rect.getMaxY(); - - Point topLeft = PointApplyAffineTransform(Point(left, top), anAffineTransform); - Point topRight = PointApplyAffineTransform(Point(right, top), anAffineTransform); - Point bottomLeft = PointApplyAffineTransform(Point(left, bottom), anAffineTransform); - Point bottomRight = PointApplyAffineTransform(Point(right, bottom), anAffineTransform); - - float minX = min(min(topLeft.x, topRight.x), min(bottomLeft.x, bottomRight.x)); - float maxX = max(max(topLeft.x, topRight.x), max(bottomLeft.x, bottomRight.x)); - float minY = min(min(topLeft.y, topRight.y), min(bottomLeft.y, bottomRight.y)); - float maxY = max(max(topLeft.y, topRight.y), max(bottomLeft.y, bottomRight.y)); - - return Rect(minX, minY, (maxX - minX), (maxY - minY)); -} - -AffineTransform AffineTransformTranslate(const AffineTransform& t, float tx, float ty) -{ - return __CCAffineTransformMake(t.a, t.b, t.c, t.d, t.tx + t.a * tx + t.c * ty, t.ty + t.b * tx + t.d * ty); -} - -AffineTransform AffineTransformScale(const AffineTransform& t, float sx, float sy) -{ - return __CCAffineTransformMake(t.a * sx, t.b * sx, t.c * sy, t.d * sy, t.tx, t.ty); -} - -AffineTransform AffineTransformRotate(const AffineTransform& t, float anAngle) -{ - float sine = sinf(anAngle); - float cosine = cosf(anAngle); - - return __CCAffineTransformMake( t.a * cosine + t.c * sine, - t.b * cosine + t.d * sine, - t.c * cosine - t.a * sine, - t.d * cosine - t.b * sine, - t.tx, - t.ty); -} - -/* Concatenate `t2' to `t1' and return the result: - t' = t1 * t2 */ -AffineTransform AffineTransformConcat(const AffineTransform& t1, const AffineTransform& t2) -{ - return __CCAffineTransformMake( t1.a * t2.a + t1.b * t2.c, t1.a * t2.b + t1.b * t2.d, //a,b - t1.c * t2.a + t1.d * t2.c, t1.c * t2.b + t1.d * t2.d, //c,d - t1.tx * t2.a + t1.ty * t2.c + t2.tx, //tx - t1.tx * t2.b + t1.ty * t2.d + t2.ty); //ty -} - -/* Return true if `t1' and `t2' are equal, false otherwise. */ -bool AffineTransformEqualToTransform(const AffineTransform& t1, const AffineTransform& t2) -{ - return (t1.a == t2.a && t1.b == t2.b && t1.c == t2.c && t1.d == t2.d && t1.tx == t2.tx && t1.ty == t2.ty); -} - -AffineTransform AffineTransformInvert(const AffineTransform& t) -{ - float determinant = 1 / (t.a * t.d - t.b * t.c); - - return __CCAffineTransformMake(determinant * t.d, -determinant * t.b, -determinant * t.c, determinant * t.a, - determinant * (t.c * t.ty - t.d * t.tx), determinant * (t.b * t.tx - t.a * t.ty) ); -} - -NS_CC_END diff --git a/cocos/platform/cocoa/CCAffineTransform.h b/cocos/platform/cocoa/CCAffineTransform.h deleted file mode 100644 index 667b5d9b46..0000000000 --- a/cocos/platform/cocoa/CCAffineTransform.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __COCOA_CGAFFINETRANSFORM_H__ -#define __COCOA_CGAFFINETRANSFORM_H__ - -#include "CCGeometry.h" -#include "platform/CCPlatformMacros.h" - -NS_CC_BEGIN - -struct AffineTransform { - float a, b, c, d; - float tx, ty; - - static const AffineTransform IDENTITY; -}; - -CC_DLL AffineTransform __CCAffineTransformMake(float a, float b, float c, float d, float tx, float ty); -#define AffineTransformMake __CCAffineTransformMake - -CC_DLL Point __CCPointApplyAffineTransform(const Point& point, const AffineTransform& t); -#define PointApplyAffineTransform __CCPointApplyAffineTransform - -CC_DLL Size __CCSizeApplyAffineTransform(const Size& size, const AffineTransform& t); -#define SizeApplyAffineTransform __CCSizeApplyAffineTransform - -CC_DLL AffineTransform AffineTransformMakeIdentity(); -CC_DLL Rect RectApplyAffineTransform(const Rect& rect, const AffineTransform& anAffineTransform); - -CC_DLL AffineTransform AffineTransformTranslate(const AffineTransform& t, float tx, float ty); -CC_DLL AffineTransform AffineTransformRotate(const AffineTransform& aTransform, float anAngle); -CC_DLL AffineTransform AffineTransformScale(const AffineTransform& t, float sx, float sy); -CC_DLL AffineTransform AffineTransformConcat(const AffineTransform& t1, const AffineTransform& t2); -CC_DLL bool AffineTransformEqualToTransform(const AffineTransform& t1, const AffineTransform& t2); -CC_DLL AffineTransform AffineTransformInvert(const AffineTransform& t); - -extern CC_DLL const AffineTransform AffineTransformIdentity; - -NS_CC_END - -#endif // __COCOA_CGAFFINETRANSFORM_H__ diff --git a/cocos/platform/cocoa/CCArray.cpp b/cocos/platform/cocoa/CCArray.cpp deleted file mode 100644 index 3a55d6050d..0000000000 --- a/cocos/platform/cocoa/CCArray.cpp +++ /dev/null @@ -1,754 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 ForzeField Studios S.L. http://forzefield.com -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "CCArray.h" -#include "CCString.h" -#include "platform/CCFileUtils.h" - -NS_CC_BEGIN - - -#if CC_USE_ARRAY_VECTOR - -// ---------------------------------------------------------------------------------- -// std::vector implementation -// ---------------------------------------------------------------------------------- - -Array::Array() -: data(NULL) -{ - init(); -} - -Array* Array::create() -{ - Array* array = new Array(); - - if (array && array->initWithCapacity(7)) - { - array->autorelease(); - } - else - { - CC_SAFE_DELETE(array); - } - - return array; -} - -Array* Array::createWithObject(Object* object) -{ - Array* array = new Array(); - - if (array && array->initWithObject(object)) - { - array->autorelease(); - } - else - { - CC_SAFE_DELETE(array); - } - - return array; -} - -Array* Array::create(Object* object, ...) -{ - va_list args; - va_start(args,object); - - Array* array = create(); - if (array && object) - { - array->addObject(object); - Object *i = va_arg(args, Object*); - while (i) - { - array->addObject(i); - i = va_arg(args, Object*); - } - } - else - { - CC_SAFE_DELETE(array); - } - - va_end(args); - - return array; -} - -Array* Array::createWithArray(Array* otherArray) -{ - return otherArray->clone(); -} - -Array* Array::createWithCapacity(int capacity) -{ - CCASSERT(capacity>=0, "Invalid capacity"); - - Array* array = new Array(); - - if (array && array->initWithCapacity(capacity)) - { - array->autorelease(); - } - else - { - CC_SAFE_DELETE(array); - } - - return array; -} - -Array* Array::createWithContentsOfFile(const char* fileName) -{ - Array* ret = Array::createWithContentsOfFileThreadSafe(fileName); - if (ret != nullptr) - { - ret->autorelease(); - } - return ret; -} - -Array* Array::createWithContentsOfFileThreadSafe(const char* fileName) -{ - return FileUtils::getInstance()->createArrayWithContentsOfFile(fileName); -} - -bool Array::init() -{ - return initWithCapacity(7); -} - -bool Array::initWithObject(Object* object) -{ - bool ret = initWithCapacity(7); - if (ret) - { - addObject(object); - } - return ret; -} - -/** Initializes an array with some objects */ -bool Array::initWithObjects(Object* object, ...) -{ - bool ret = false; - do - { - CC_BREAK_IF(object == nullptr); - - va_list args; - va_start(args, object); - - if (object) - { - this->addObject(object); - Object* i = va_arg(args, Object*); - while (i) - { - this->addObject(i); - i = va_arg(args, Object*); - } - ret = true; - } - va_end(args); - - } while (false); - - return ret; -} - -bool Array::initWithCapacity(int capacity) -{ - CCASSERT(capacity>=0, "Invalid capacity"); - - data.reserve(capacity); - return true; -} - -bool Array::initWithArray(Array* otherArray) -{ - data = otherArray->data; - return true; -} - -int Array::getIndexOfObject(Object* object) const -{ - auto it = data.begin(); - - for (int i = 0; it != data.end(); ++it, ++i) - { - if (it->get() == object) - { - return i; - } - } - - return -1; -} - -Object* Array::getRandomObject() -{ - if (data.size()==0) - { - return nullptr; - } - - float r = CCRANDOM_0_1(); - - if (r == 1) // to prevent from accessing data-arr[data->num], out of range. - { - r = 0; - } - - r *= data.size(); - - return data[r].get(); -} - -bool Array::containsObject(Object* object) const -{ - int i = this->getIndexOfObject(object); - return (i >=0); -} - -bool Array::isEqualToArray(Array* otherArray) -{ - for (int i = 0; i< this->count(); i++) - { - if (!this->getObjectAtIndex(i)->isEqual(otherArray->getObjectAtIndex(i))) - { - return false; - } - } - return true; -} - -void Array::addObject(Object* object) -{ - data.push_back( RCPtr(object) ); -} - -void Array::addObjectsFromArray(Array* otherArray) -{ - data.insert(data.end(), otherArray->data.begin(), otherArray->data.end()); -} - -void Array::insertObject(Object* object, int index) -{ - data.insert( std::begin(data) + index, RCPtr(object) ); -} - -void Array::setObject(Object* object, int index) -{ - data[index] = RCPtr(object); -} - -void Array::removeLastObject(bool releaseObj) -{ - CCASSERT(data.size(), "no objects added"); - data.pop_back(); -} - -void Array::removeObject(Object* object, bool releaseObj /* ignored */) -{ - data.erase( std::remove( data.begin(), data.end(), object ) ); -} - -void Array::removeObjectAtIndex(int index, bool releaseObj /* ignored */) -{ - auto obj = data[index]; - data.erase( data.begin() + index ); -} - -void Array::removeObjectsInArray(Array* otherArray) -{ - CCASSERT(false, "not implemented"); -} - -void Array::removeAllObjects() -{ - data.erase(std::begin(data), std::end(data)); -} - -void Array::fastRemoveObjectAtIndex(int index) -{ - removeObjectAtIndex(index); -} - -void Array::fastRemoveObject(Object* object) -{ - removeObject(object); -} - -void Array::exchangeObject(Object* object1, Object* object2) -{ - int idx1 = getIndexOfObject(object1); - int idx2 = getIndexOfObject(object2); - - CCASSERT(idx1>=0 && idx2>=2, "invalid object index"); - - std::swap( data[idx1], data[idx2] ); -} - -void Array::exchangeObjectAtIndex(int index1, int index2) -{ - std::swap( data[index1], data[index2] ); -} - -void Array::replaceObjectAtIndex(int index, Object* object, bool releaseObject /* ignored */) -{ - data[index] = object; -} - -void Array::reverseObjects() -{ - std::reverse( std::begin(data), std::end(data) ); -} - -void Array::reduceMemoryFootprint() -{ - // N/A -} - -Array::~Array() -{ - CCLOGINFO("deallocing Array: %p - len: %d", this, count() ); -} - -Array* Array::clone() const -{ - Array* ret = new Array(); - ret->autorelease(); - ret->initWithCapacity(this->data.size() > 0 ? this->data.size() : 1); - - Object* obj = nullptr; - Object* tmpObj = nullptr; - Clonable* clonable = nullptr; - CCARRAY_FOREACH(this, obj) - { - clonable = dynamic_cast(obj); - if (clonable) - { - tmpObj = dynamic_cast(clonable->clone()); - if (tmpObj) - { - ret->addObject(tmpObj); - } - } - else - { - CCLOGWARN("%s isn't clonable.", typeid(*obj).name()); - } - } - return ret; -} - -void Array::acceptVisitor(DataVisitor &visitor) -{ - visitor.visit(this); -} - -// ---------------------------------------------------------------------------------- -// ccArray implementation -// ---------------------------------------------------------------------------------- - -#else - -Array::Array() -: data(nullptr) -{ -// init(); -} - -Array* Array::create() -{ - Array* array = new Array(); - - if (array && array->initWithCapacity(7)) - { - array->autorelease(); - } - else - { - CC_SAFE_DELETE(array); - } - - return array; -} - -Array* Array::createWithObject(Object* object) -{ - Array* array = new Array(); - - if (array && array->initWithObject(object)) - { - array->autorelease(); - } - else - { - CC_SAFE_DELETE(array); - } - - return array; -} - -Array* Array::create(Object* object, ...) -{ - va_list args; - va_start(args,object); - - Array* array = create(); - if (array && object) - { - array->addObject(object); - Object *i = va_arg(args, Object*); - while (i) - { - array->addObject(i); - i = va_arg(args, Object*); - } - } - else - { - CC_SAFE_DELETE(array); - } - - va_end(args); - - return array; -} - -Array* Array::createWithArray(Array* otherArray) -{ - return otherArray->clone(); -} - -Array* Array::createWithCapacity(int capacity) -{ - CCASSERT(capacity>=0, "Invalid capacity"); - - Array* array = new Array(); - - if (array && array->initWithCapacity(capacity)) - { - array->autorelease(); - } - else - { - CC_SAFE_DELETE(array); - } - - return array; -} - -Array* Array::createWithContentsOfFile(const char* fileName) -{ - Array* ret = Array::createWithContentsOfFileThreadSafe(fileName); - if (ret != nullptr) - { - ret->autorelease(); - } - return ret; -} - -Array* Array::createWithContentsOfFileThreadSafe(const char* fileName) -{ - return FileUtils::getInstance()->createArrayWithContentsOfFile(fileName); -} - -bool Array::init() -{ - CCASSERT(!data, "Array cannot be re-initialized"); - - return initWithCapacity(7); -} - -bool Array::initWithObject(Object* object) -{ - CCASSERT(!data, "Array cannot be re-initialized"); - - bool ret = initWithCapacity(7); - if (ret) - { - addObject(object); - } - return ret; -} - -/** Initializes an array with some objects */ -bool Array::initWithObjects(Object* object, ...) -{ - CCASSERT(!data, "Array cannot be re-initialized"); - - bool ret = false; - do - { - CC_BREAK_IF(object == nullptr); - - va_list args; - va_start(args, object); - - if (object) - { - this->addObject(object); - Object* i = va_arg(args, Object*); - while (i) - { - this->addObject(i); - i = va_arg(args, Object*); - } - ret = true; - } - va_end(args); - - } while (false); - - return ret; -} - -bool Array::initWithCapacity(int capacity) -{ - CCASSERT(capacity>=0 && !data, "Array cannot be re-initialized"); - - data = ccArrayNew(capacity); - return true; -} - -bool Array::initWithArray(Array* otherArray) -{ - CCASSERT(!data, "Array cannot be re-initialized"); - - bool ret = false; - do - { - CC_BREAK_IF(! initWithCapacity(otherArray->data->num)); - - addObjectsFromArray(otherArray); - ret = true; - } while (0); - - return ret; -} - -int Array::getIndexOfObject(Object* object) const -{ - return ccArrayGetIndexOfObject(data, object); -} - -Object* Array::getRandomObject() -{ - if (data->num == 0) - { - return nullptr; - } - - float r = CCRANDOM_0_1(); - - if (r == 1) // to prevent from accessing data-arr[data->num], out of range. - { - r = 0; - } - - return data->arr[(int)(data->num * r)]; -} - -bool Array::containsObject(Object* object) const -{ - return ccArrayContainsObject(data, object); -} - -bool Array::isEqualToArray(Array* otherArray) -{ - for (int i = 0; i< this->count(); i++) - { - if (!this->getObjectAtIndex(i)->isEqual(otherArray->getObjectAtIndex(i))) - { - return false; - } - } - return true; -} - -void Array::addObject(Object* object) -{ - CCASSERT(data, "Array not initialized"); - ccArrayAppendObjectWithResize(data, object); -} - -void Array::addObjectsFromArray(Array* otherArray) -{ - CCASSERT(data, "Array not initialized"); - ccArrayAppendArrayWithResize(data, otherArray->data); -} - -void Array::insertObject(Object* object, int index) -{ - CCASSERT(data, "Array not initialized"); - ccArrayInsertObjectAtIndex(data, object, index); -} - -void Array::setObject(Object* object, int index) -{ - CCASSERT(index>=0 && index < count(), "Invalid index"); - - if (object != data->arr[index]) - { - data->arr[index]->release(); - data->arr[index] = object; - object->retain(); - } -} - -void Array::removeLastObject(bool releaseObj) -{ - CCASSERT(data->num, "no objects added"); - ccArrayRemoveObjectAtIndex(data, data->num-1, releaseObj); -} - -void Array::removeObject(Object* object, bool releaseObj/* = true*/) -{ - ccArrayRemoveObject(data, object, releaseObj); -} - -void Array::removeObjectAtIndex(int index, bool releaseObj) -{ - ccArrayRemoveObjectAtIndex(data, index, releaseObj); -} - -void Array::removeObjectsInArray(Array* otherArray) -{ - ccArrayRemoveArray(data, otherArray->data); -} - -void Array::removeAllObjects() -{ - ccArrayRemoveAllObjects(data); -} - -void Array::fastRemoveObjectAtIndex(int index) -{ - ccArrayFastRemoveObjectAtIndex(data, index); -} - -void Array::fastRemoveObject(Object* object) -{ - ccArrayFastRemoveObject(data, object); -} - -void Array::exchangeObject(Object* object1, Object* object2) -{ - int index1 = ccArrayGetIndexOfObject(data, object1); - if (index1 == UINT_MAX) - { - return; - } - - int index2 = ccArrayGetIndexOfObject(data, object2); - if (index2 == UINT_MAX) - { - return; - } - - ccArraySwapObjectsAtIndexes(data, index1, index2); -} - -void Array::exchangeObjectAtIndex(int index1, int index2) -{ - ccArraySwapObjectsAtIndexes(data, index1, index2); -} - -void Array::replaceObjectAtIndex(int index, Object* object, bool releaseObject/* = true*/) -{ - ccArrayInsertObjectAtIndex(data, object, index); - ccArrayRemoveObjectAtIndex(data, index+1); -} - -void Array::reverseObjects() -{ - if (data->num > 1) - { - // floorf(), since in the case of an even number, the number of swaps stays the same - int count = (int) floorf(data->num/2.f); - int maxIndex = data->num - 1; - - for (int i = 0; i < count ; i++) - { - ccArraySwapObjectsAtIndexes(data, i, maxIndex); - --maxIndex; - } - } -} - -void Array::reduceMemoryFootprint() -{ - ccArrayShrink(data); -} - -Array::~Array() -{ - CCLOGINFO("deallocing Array: %p - len: %d", this, count() ); - - ccArrayFree(data); -} - -Array* Array::clone() const -{ - Array* ret = new Array(); - ret->autorelease(); - ret->initWithCapacity(this->data->num > 0 ? this->data->num : 1); - - Object* obj = nullptr; - Object* tmpObj = nullptr; - Clonable* clonable = nullptr; - CCARRAY_FOREACH(this, obj) - { - clonable = dynamic_cast(obj); - if (clonable) - { - tmpObj = dynamic_cast(clonable->clone()); - if (tmpObj) - { - ret->addObject(tmpObj); - } - } - else - { - CCLOGWARN("%s isn't clonable.", typeid(*obj).name()); - } - } - return ret; -} - -void Array::acceptVisitor(DataVisitor &visitor) -{ - visitor.visit(this); -} - -#endif // uses ccArray - -NS_CC_END diff --git a/cocos/platform/cocoa/CCArray.h b/cocos/platform/cocoa/CCArray.h deleted file mode 100644 index 4f5beea501..0000000000 --- a/cocos/platform/cocoa/CCArray.h +++ /dev/null @@ -1,557 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 ForzeField Studios S.L. http://forzefield.com -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#ifndef __CCARRAY_H__ -#define __CCARRAY_H__ - -#define CC_USE_ARRAY_VECTOR 0 - -#if CC_USE_ARRAY_VECTOR -#include -#include -#include "cocoa/CCObject.h" -#include "ccMacros.h" -#else -#include "support/data_support/ccCArray.h" -#endif - - -#if CC_USE_ARRAY_VECTOR -/** - * A reference counting-managed pointer for classes derived from RCBase which can - * be used as C pointer - * Original code: http://www.codeproject.com/Articles/64111/Building-a-Quick-and-Handy-Reference-Counting-Clas - * License: http://www.codeproject.com/info/cpol10.aspx - */ -template < class T > -class RCPtr -{ -public: - //Construct using a C pointer - //e.g. RCPtr< T > x = new T(); - RCPtr(T* ptr = nullptr) - : _ptr(ptr) - { - if(ptr != nullptr) {ptr->retain();} - } - - //Copy constructor - RCPtr(const RCPtr &ptr) - : _ptr(ptr._ptr) - { -// printf("Array: copy constructor: %p\n", this); - if(_ptr != NULL) {_ptr->retain();} - } - - //Move constructor - RCPtr(RCPtr &&ptr) - : _ptr(ptr._ptr) - { -// printf("Array: Move Constructor: %p\n", this); - ptr._ptr = nullptr; - } - - ~RCPtr() - { -// printf("Array: Destructor: %p\n", this); - if(_ptr != nullptr) {_ptr->release();} - } - - //Assign a pointer - //e.g. x = new T(); - RCPtr &operator=(T* ptr) - { -// printf("Array: operator= T*: %p\n", this); - - //The following grab and release operations have to be performed - //in that order to handle the case where ptr == _ptr - //(See comment below by David Garlisch) - if(ptr != nullptr) {ptr->retain();} - if(_ptr != nullptr) {_ptr->release();} - _ptr = ptr; - return (*this); - } - - //Assign another RCPtr - RCPtr &operator=(const RCPtr &ptr) - { -// printf("Array: operator= const&: %p\n", this); - return (*this) = ptr._ptr; - } - - //Retrieve actual pointer - T* get() const - { - return _ptr; - } - - //Some overloaded operators to facilitate dealing with an RCPtr - //as a conventional C pointer. - //Without these operators, one can still use the less transparent - //get() method to access the pointer. - T* operator->() const {return _ptr;} //x->member - T &operator*() const {return *_ptr;} //*x, (*x).member - explicit operator T*() const {return _ptr;} //T* y = x; - explicit operator bool() const {return _ptr != nullptr;} //if(x) {/*x is not NULL*/} - bool operator==(const RCPtr &ptr) {return _ptr == ptr._ptr;} - bool operator==(const T *ptr) {return _ptr == ptr;} - -private: - T *_ptr; //Actual pointer -}; -#endif // CC_USE_ARRAY_VECTOR - - -/** - * @addtogroup data_structures - * @{ - */ - -/** @def CCARRAY_FOREACH -A convenience macro to iterate over a Array using. It is faster than the "fast enumeration" interface. -@since v0.99.4 -*/ - -/* -In cocos2d-iphone 1.0.0, This macro have been update to like this: - -#define CCARRAY_FOREACH(__array__, __object__) \ -if (__array__ && __array__->data->num > 0) \ -for(id *__arr__ = __array__->data->arr, *end = __array__->data->arr + __array__->data->num-1; \ -__arr__ <= end && ((__object__ = *__arr__) != nil || true); \ -__arr__++) - -I found that it's not work in C++. So it keep what it's look like in version 1.0.0-rc3. ---By Bin -*/ - -#if CC_USE_ARRAY_VECTOR -#define CCARRAY_FOREACH(__array__, __object__) \ - if (__array__) \ - for( auto __it__ = (__array__)->data.begin(); \ - __it__ != (__array__)->data.end() && ((__object__) = __it__->get()) != nullptr; \ - ++__it__) - - -#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \ - if (__array__) \ - for( auto __it__ = (__array__)->data.rbegin(); \ - __it__ != (__array__)->data.rend() && ((__object__) = __it__->get()) != nullptr; \ - ++__it__ ) - - -#define CCARRAY_VERIFY_TYPE(__array__, __type__) void(0) - -#else // ! CC_USE_ARRAY_VECTOR -------------------------- - -#define CCARRAY_FOREACH(__array__, __object__) \ - if ((__array__) && (__array__)->data->num > 0) \ - for(Object** __arr__ = (__array__)->data->arr, **__end__ = (__array__)->data->arr + (__array__)->data->num-1; \ - __arr__ <= __end__ && (((__object__) = *__arr__) != NULL/* || true*/); \ - __arr__++) - -#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \ - if ((__array__) && (__array__)->data->num > 0) \ - for(Object** __arr__ = (__array__)->data->arr + (__array__)->data->num-1, **__end__ = (__array__)->data->arr; \ - __arr__ >= __end__ && (((__object__) = *__arr__) != NULL/* || true*/); \ - __arr__--) - -#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0) -#define CCARRAY_VERIFY_TYPE(__array__, __type__) \ - do { \ - if ((__array__) && (__array__)->data->num > 0) \ - for(Object** __arr__ = (__array__)->data->arr, \ - **__end__ = (__array__)->data->arr + (__array__)->data->num-1; __arr__ <= __end__; __arr__++) \ - CCASSERT(dynamic_cast<__type__>(*__arr__), "element type is wrong!"); \ - } while(false) -#else -#define CCARRAY_VERIFY_TYPE(__array__, __type__) void(0) -#endif - -#endif // ! CC_USE_ARRAY_VECTOR - - -// Common defines ----------------------------------------------------------------------------------------------- - -#define arrayMakeObjectsPerformSelector(pArray, func, elementType) \ -do { \ - if(pArray && pArray->count() > 0) \ - { \ - Object* child; \ - CCARRAY_FOREACH(pArray, child) \ - { \ - elementType pNode = static_cast(child); \ - if(pNode) \ - { \ - pNode->func(); \ - } \ - } \ - } \ -} \ -while(false) - -#define arrayMakeObjectsPerformSelectorWithObject(pArray, func, object, elementType) \ -do { \ - if(pArray && pArray->count() > 0) \ - { \ - Object* child; \ - CCARRAY_FOREACH(pArray, child) \ - { \ - elementType pNode = static_cast(child); \ - if(pNode) \ - { \ - pNode->func(object); \ - } \ - } \ - } \ -} \ -while(false) - - -NS_CC_BEGIN - -class CC_DLL Array : public Object, public Clonable -{ -public: - - /** Creates an empty array. Default capacity is 10 - * @js NA - * @lua NA - */ - static Array* create(); - /** Create an array with objects - * @js NA - */ - static Array* create(Object* object, ...) CC_REQUIRES_NULL_TERMINATION; - /** Create an array with one object - * @js NA - */ - static Array* createWithObject(Object* object); - /** Create an array with a default capacity - * @js NA - */ - static Array* createWithCapacity(int capacity); - /** Create an array with from an existing array - * @js NA - */ - static Array* createWithArray(Array* otherArray); - /** - @brief Generate a Array pointer by file - @param pFileName The file name of *.plist file - @return The Array pointer generated from the file - * @js NA - */ - static Array* createWithContentsOfFile(const char* pFileName); - - /* - @brief The same meaning as arrayWithContentsOfFile(), but it doesn't call autorelease, so the - invoker should call release(). - * @js NA - * @lua NA - */ - static Array* createWithContentsOfFileThreadSafe(const char* pFileName); - /** - * @js NA - * @lua NA - */ - ~Array(); - - /** Initializes an array - * @js NA - * @lua NA - */ - bool init(); - /** Initializes an array with one object - * @js NA - * @lua NA - */ - bool initWithObject(Object* object); - /** Initializes an array with some objects - * @js NA - * @lua NA - */ - bool initWithObjects(Object* object, ...) CC_REQUIRES_NULL_TERMINATION; - /** Initializes an array with capacity - * @js NA - * @lua NA - */ - bool initWithCapacity(int capacity); - /** Initializes an array with an existing array - * @js NA - * @lua NA - */ - bool initWithArray(Array* otherArray); - - // Querying an Array - - /** Returns element count of the array - * @js NA - */ - int count() const - { -#if CC_USE_ARRAY_VECTOR - return data.size(); -#else - return data->num; -#endif - } - /** Returns capacity of the array - * @js NA - */ - int capacity() const - { -#if CC_USE_ARRAY_VECTOR - return data.capacity(); -#else - return data->max; -#endif - } - /** Returns index of a certain object, return UINT_MAX if doesn't contain the object - * @js NA - * @lua NA - */ - int getIndexOfObject(Object* object) const; - /** - * @js NA - */ - CC_DEPRECATED_ATTRIBUTE int indexOfObject(Object* object) const { return getIndexOfObject(object); } - - /** Returns an element with a certain index - * @js NA - * @lua NA - */ - Object* getObjectAtIndex(int index) - { - CCASSERT(index>=0 && index < count(), "index out of range in getObjectAtIndex()"); -#if CC_USE_ARRAY_VECTOR - return data[index].get(); -#else - return data->arr[index]; -#endif - } - CC_DEPRECATED_ATTRIBUTE Object* objectAtIndex(int index) { return getObjectAtIndex(index); } - /** Returns the last element of the array - * @js NA - */ - Object* getLastObject() - { -#if CC_USE_ARRAY_VECTOR - return data.back().get(); -#else - if(data->num > 0) - return data->arr[data->num-1]; - - return nullptr; -#endif - } - /** - * @js NA - */ - CC_DEPRECATED_ATTRIBUTE Object* lastObject() { return getLastObject(); } - /** Returns a random element - * @js NA - * @lua NA - */ - Object* getRandomObject(); - /** - * @js NA - */ - CC_DEPRECATED_ATTRIBUTE Object* randomObject() { return getRandomObject(); } - /** Returns a Boolean value that indicates whether object is present in array. - * @js NA - */ - bool containsObject(Object* object) const; - /** @since 1.1 - * @js NA - */ - bool isEqualToArray(Array* otherArray); - // Adding Objects - - /** Add a certain object - * @js NA - */ - void addObject(Object* object); - /** - * @js NA - */ - /** Add all elements of an existing array - * @js NA - */ - void addObjectsFromArray(Array* otherArray); - /** Insert a certain object at a certain index - * @js NA - */ - void insertObject(Object* object, int index); - /** sets a certain object at a certain index - * @js NA - * @lua NA - */ - void setObject(Object* object, int index); - /** sets a certain object at a certain index without retaining. Use it with caution - * @js NA - * @lua NA - */ - void fastSetObject(Object* object, int index) - { -#if CC_USE_ARRAY_VECTOR - setObject(object, index); -#else - // no retain - data->arr[index] = object; -#endif - } - /** - * @js NA - * @lua NA - */ - void swap( int indexOne, int indexTwo ) - { - CCASSERT(indexOne >=0 && indexOne < count() && indexTwo >= 0 && indexTwo < count(), "Invalid indices"); -#if CC_USE_ARRAY_VECTOR - std::swap(data[indexOne], data[indexTwo]); -#else - std::swap(data->arr[indexOne], data->arr[indexTwo]); -#endif - } - - // Removing Objects - - /** Remove last object - * @js NA - */ - void removeLastObject(bool releaseObj = true); - /** Remove a certain object - * @js NA - */ - void removeObject(Object* object, bool releaseObj = true); - /** Remove an element with a certain index - * @js NA - */ - void removeObjectAtIndex(int index, bool releaseObj = true); - /** Remove all elements - * @js NA - */ - void removeObjectsInArray(Array* otherArray); - /** Remove all objects - * @js NA - */ - void removeAllObjects(); - /** Fast way to remove a certain object - * @js NA - */ - void fastRemoveObject(Object* object); - /** Fast way to remove an element with a certain index - * @js NA - */ - void fastRemoveObjectAtIndex(int index); - - // Rearranging Content - - /** Swap two elements - * @js NA - */ - void exchangeObject(Object* object1, Object* object2); - /** Swap two elements with certain indexes - * @js NA - */ - void exchangeObjectAtIndex(int index1, int index2); - - /** Replace object at index with another object. - * @js NA - */ - void replaceObjectAtIndex(int index, Object* object, bool releaseObject = true); - - /** Revers the array - * @js NA - */ - void reverseObjects(); - /* Shrinks the array so the memory footprint corresponds with the number of items - * @js NA - */ - void reduceMemoryFootprint(); - - /* override functions - * @js NA - */ - virtual void acceptVisitor(DataVisitor &visitor); - /** - * @js NA - * @lua NA - */ - virtual Array* clone() const; - - // ------------------------------------------ - // Iterators - // ------------------------------------------ -#if CC_USE_ARRAY_VECTOR - typedef std::vector>::iterator iterator; - typedef std::vector>::const_iterator const_iterator; - /** - * @js NA - * @lua NA - */ - iterator begin() { return data.begin(); } - /** - * @js NA - * @lua NA - */ - iterator end() { return data.end(); } - const_iterator cbegin() { return data.cbegin(); } - /** - * @js NA - * @lua NA - */ - const_iterator cend() { return data.cend(); } - - std::vector> data; - -#else - /** - * @js NA - * @lua NA - */ - Object** begin() { return &data->arr[0]; } - /** - * @js NA - * @lua NA - */ - Object** end() { return &data->arr[data->num]; } - - ccArray* data; - -#endif - -//protected: - /** - * @js NA - * @lua NA - */ - Array(); -}; - -// end of data_structure group -/// @} - -NS_CC_END - -#endif // __CCARRAY_H__ diff --git a/cocos/platform/cocoa/CCAutoreleasePool.cpp b/cocos/platform/cocoa/CCAutoreleasePool.cpp deleted file mode 100644 index 89a3528f73..0000000000 --- a/cocos/platform/cocoa/CCAutoreleasePool.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "CCAutoreleasePool.h" -#include "ccMacros.h" - -NS_CC_BEGIN - -static PoolManager* s_pPoolManager = NULL; - -AutoreleasePool::AutoreleasePool() -{ - _managedObjectArray = new Array(); - _managedObjectArray->initWithCapacity(150); -} - -AutoreleasePool::~AutoreleasePool() -{ - CCLOGINFO("deallocing AutoreleasePool: %p", this); - CC_SAFE_DELETE(_managedObjectArray); -} - -void AutoreleasePool::addObject(Object* object) -{ - _managedObjectArray->addObject(object); - - CCASSERT(object->_reference > 1, "reference count should be greater than 1"); - ++(object->_autoReleaseCount); - object->release(); // no ref count, in this case autorelease pool added. -} - -void AutoreleasePool::removeObject(Object* object) -{ - for (unsigned int i = 0; i < object->_autoReleaseCount; ++i) - { - _managedObjectArray->removeObject(object, false); - } -} - -void AutoreleasePool::clear() -{ - if(_managedObjectArray->count() > 0) - { - //CCAutoreleasePool* pReleasePool; -#ifdef _DEBUG - int nIndex = _managedObjectArray->count() - 1; -#endif - - Object* pObj = NULL; - CCARRAY_FOREACH_REVERSE(_managedObjectArray, pObj) - { - if(!pObj) - break; - - --(pObj->_autoReleaseCount); - //(*it)->release(); - //delete (*it); -#ifdef _DEBUG - nIndex--; -#endif - } - - _managedObjectArray->removeAllObjects(); - } -} - - -//-------------------------------------------------------------------- -// -// PoolManager -// -//-------------------------------------------------------------------- - -PoolManager* PoolManager::sharedPoolManager() -{ - if (s_pPoolManager == NULL) - { - s_pPoolManager = new PoolManager(); - } - return s_pPoolManager; -} - -void PoolManager::purgePoolManager() -{ - CC_SAFE_DELETE(s_pPoolManager); -} - -PoolManager::PoolManager() -{ - _releasePoolStack = new Array(); - _releasePoolStack->initWithCapacity(150); - _curReleasePool = 0; -} - -PoolManager::~PoolManager() -{ - CCLOGINFO("deallocing PoolManager: %p", this); - finalize(); - - // we only release the last autorelease pool here - _curReleasePool = 0; - _releasePoolStack->removeObjectAtIndex(0); - - CC_SAFE_DELETE(_releasePoolStack); -} - -void PoolManager::finalize() -{ - if(_releasePoolStack->count() > 0) - { - //CCAutoreleasePool* pReleasePool; - Object* pObj = NULL; - CCARRAY_FOREACH(_releasePoolStack, pObj) - { - if(!pObj) - break; - AutoreleasePool* pPool = static_cast(pObj); - pPool->clear(); - } - } -} - -void PoolManager::push() -{ - AutoreleasePool* pPool = new AutoreleasePool(); //ref = 1 - _curReleasePool = pPool; - - _releasePoolStack->addObject(pPool); //ref = 2 - - pPool->release(); //ref = 1 -} - -void PoolManager::pop() -{ - if (! _curReleasePool) - { - return; - } - - int nCount = _releasePoolStack->count(); - - _curReleasePool->clear(); - - if (nCount > 1) - { - _releasePoolStack->removeObjectAtIndex(nCount-1); - -// if(nCount > 1) -// { -// _curReleasePool = _releasePoolStack->getObjectAtIndex(nCount - 2); -// return; -// } - _curReleasePool = (AutoreleasePool*)_releasePoolStack->getObjectAtIndex(nCount - 2); - } - - /*_curReleasePool = NULL;*/ -} - -void PoolManager::removeObject(Object* object) -{ - CCASSERT(_curReleasePool, "current auto release pool should not be null"); - - _curReleasePool->removeObject(object); -} - -void PoolManager::addObject(Object* object) -{ - getCurReleasePool()->addObject(object); -} - - -AutoreleasePool* PoolManager::getCurReleasePool() -{ - if(!_curReleasePool) - { - push(); - } - - CCASSERT(_curReleasePool, "current auto release pool should not be null"); - - return _curReleasePool; -} - -NS_CC_END diff --git a/cocos/platform/cocoa/CCAutoreleasePool.h b/cocos/platform/cocoa/CCAutoreleasePool.h deleted file mode 100644 index e446ceb402..0000000000 --- a/cocos/platform/cocoa/CCAutoreleasePool.h +++ /dev/null @@ -1,181 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#ifndef __AUTORELEASEPOOL_H__ -#define __AUTORELEASEPOOL_H__ - -#include "CCObject.h" -#include "CCArray.h" - -NS_CC_BEGIN - -/** - * @addtogroup base_nodes - * @{ - */ - -class CC_DLL AutoreleasePool : public Object -{ - /** - * The underlying array of object managed by the pool. - * - * Although Array retains the object once when an object is added, proper - * Object::release() is called outside the array to make sure that the pool - * does not affect the managed object's reference count. So an object can - * be destructed properly by calling Object::release() even if the object - * is in the pool. - */ - Array *_managedObjectArray; -public: - /** - * @js NA - * @lua NA - */ - AutoreleasePool(); - /** - * @js NA - * @lua NA - */ - ~AutoreleasePool(); - - /** - * Add a given object to this pool. - * - * The same object may be added several times to the same pool; When the - * pool is destructed, the object's Object::release() method will be called - * for each time it was added. - * - * @param object The object to add to the pool. - * @js NA - * @lua NA - */ - void addObject(Object *object); - - /** - * Remove a given object from this pool. - * - * @param object The object to be removed from the pool. - * @js NA - * @lua NA - */ - void removeObject(Object *object); - - /** - * Clear the autorelease pool. - * - * Object::release() will be called for each time the managed object is - * added to the pool. - * @js NA - * @lua NA - */ - void clear(); -}; - -class CC_DLL PoolManager -{ - Array *_releasePoolStack; - AutoreleasePool *_curReleasePool; - - AutoreleasePool *getCurReleasePool(); -public: - /** - * @js NA - * @lua NA - */ - static PoolManager* sharedPoolManager(); - /** - * @js NA - * @lua NA - */ - static void purgePoolManager(); - /** - * @js NA - * @lua NA - */ - PoolManager(); - /** - * @js NA - * @lua NA - */ - ~PoolManager(); - - /** - * Clear all the AutoreleasePool on the pool stack. - * @js NA - * @lua NA - */ - void finalize(); - - /** - * Push a new AutoreleasePool to the pool stack. - * @js NA - * @lua NA - */ - void push(); - - /** - * Pop one AutoreleasePool from the pool stack. - * - * This method will ensure that there is at least one AutoreleasePool on - * the stack. - * - * The AutoreleasePool being poped is destructed. - * @js NA - * @lua NA - */ - void pop(); - - /** - * Remove a given object from the current autorelease pool. - * - * @param object The object to be removed. - * - * @see AutoreleasePool::removeObject - * @js NA - * @lua NA - */ - void removeObject(Object *object); - - /** - * Add a given object to the current autorelease pool. - * - * @param object The object to add. - * - * @see AutoreleasePool::addObject - * @js NA - * @lua NA - */ - void addObject(Object *object); - /** - * @js NA - * @lua NA - */ - friend class AutoreleasePool; -}; - -// end of base_nodes group -/// @} - -NS_CC_END - -#endif //__AUTORELEASEPOOL_H__ diff --git a/cocos/platform/cocoa/CCBool.h b/cocos/platform/cocoa/CCBool.h deleted file mode 100644 index 32b7b276ee..0000000000 --- a/cocos/platform/cocoa/CCBool.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#ifndef __CCBOOL_H__ -#define __CCBOOL_H__ - -#include "CCObject.h" - -NS_CC_BEGIN - -/** - * @addtogroup data_structures - * @{ - */ - -class CC_DLL Bool : public Object, public Clonable -{ -public: - Bool(bool v) - : _value(v) {} - bool getValue() const {return _value;} - - static Bool* create(bool v) - { - Bool* pRet = new Bool(v); - if (pRet) - { - pRet->autorelease(); - } - return pRet; - } - - /* override functions */ - virtual void acceptVisitor(DataVisitor &visitor) { visitor.visit(this); } - - Bool* clone() const - { - return Bool::create(_value); - } -private: - bool _value; -}; - -// end of data_structure group -/// @} - -NS_CC_END - -#endif /* __CCBOOL_H__ */ diff --git a/cocos/platform/cocoa/CCData.cpp b/cocos/platform/cocoa/CCData.cpp deleted file mode 100644 index 1c42a12ee5..0000000000 --- a/cocos/platform/cocoa/CCData.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#include -#include "CCData.h" -#include "platform/CCCommon.h" - -NS_CC_BEGIN - -Data::Data(unsigned char *pBytes, const unsigned long nSize) -{ - _size = nSize; - _bytes = new unsigned char[_size]; - memcpy(_bytes, pBytes, _size); -} - -Data::Data(Data *pData) -{ - _size = pData->_size; - _bytes = new unsigned char[_size]; - memcpy(_bytes, pData->_bytes, _size); -} - -Data::~Data() -{ - CCLOGINFO("deallocing Data: %p", this); - CC_SAFE_DELETE_ARRAY(_bytes); -} - -unsigned char* Data::getBytes() const -{ - return _bytes; -} - -unsigned long Data::getSize() const -{ - return _size; -} - -NS_CC_END diff --git a/cocos/platform/cocoa/CCData.h b/cocos/platform/cocoa/CCData.h deleted file mode 100644 index 889a2d557b..0000000000 --- a/cocos/platform/cocoa/CCData.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#ifndef __CCDATA_H__ -#define __CCDATA_H__ - -#include "platform/CCPlatformMacros.h" -#include "CCObject.h" - -NS_CC_BEGIN - -class CC_DLL Data : public Object -{ -public: - /** - * @js NA - * @lua NA - */ - Data(unsigned char *pBytes, const unsigned long nSize); - /** - * @js NA - * @lua NA - */ - Data(Data *pData); - /** - * @js NA - * @lua NA - */ - ~Data(); - /** - * @js NA - * @lua NA - */ - static Data* create(unsigned char *pBytes, const unsigned long nSize) - { - Data* pRet = new Data(pBytes, nSize); - if (pRet) - { - pRet->autorelease(); - } - return pRet; - } - /** - * @js NA - * @lua NA - */ - unsigned char* getBytes() const; - /** - * @js NA - * @lua NA - */ - unsigned long getSize() const; - - /** override functions - * @js NA - * @lua NA - */ - virtual void acceptVisitor(DataVisitor &visitor) { visitor.visit(this); } - -private: - unsigned char* _bytes; - unsigned long _size; -}; - -NS_CC_END - -#endif // __CCDATA_H__ diff --git a/cocos/platform/cocoa/CCDataVisitor.cpp b/cocos/platform/cocoa/CCDataVisitor.cpp deleted file mode 100644 index 2d2a1f8121..0000000000 --- a/cocos/platform/cocoa/CCDataVisitor.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#include "CCObject.h" -#include "CCBool.h" -#include "CCInteger.h" -#include "CCFloat.h" -#include "CCDouble.h" -#include "CCString.h" -#include "CCArray.h" -#include "CCDictionary.h" -#include "CCSet.h" -#include "CCData.h" - -NS_CC_BEGIN - -void DataVisitor::visit(const Bool *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const Integer *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const Float *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const Double *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const String *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const Array *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const Dictionary *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const Set *value) -{ - visitObject(value); -} - -void DataVisitor::visit(const Data *value) -{ - visitObject(value); -} - -// PrettyPrinter -PrettyPrinter::PrettyPrinter(int indentLevel/* = 0 */) -{ - setIndentLevel(indentLevel); -} - -void PrettyPrinter::clear() -{ - _result.clear(); -} - -std::string PrettyPrinter::getResult() -{ - return _result; -} - -void PrettyPrinter::visitObject(const Object *p) -{ - char buf[50] = {0}; - sprintf(buf, "%p", p); - _result += buf; -} - -void PrettyPrinter::visit(const Bool * p) -{ - char buf[50] = {0}; - sprintf(buf, "%s", p->getValue() ? "true" : "false"); - _result += buf; -} - -void PrettyPrinter::visit(const Integer *p) -{ - char buf[50] = {0}; - sprintf(buf, "%d", p->getValue()); - _result += buf; -} - -void PrettyPrinter::visit(const Float *p) -{ - char buf[50] = {0}; - sprintf(buf, "%f", p->getValue()); - _result += buf; -} - -void PrettyPrinter::visit(const Double *p) -{ - char buf[50] = {0}; - sprintf(buf, "%lf", p->getValue()); - _result += buf; -} - -void PrettyPrinter::visit(const String *p) -{ - _result += p->getCString(); -} - -void PrettyPrinter::visit(const Array *p) -{ - _result += "\n"; - _result += _indentStr; - _result += "\n"; - - setIndentLevel(_indentLevel+1); - Object* obj; - int i = 0; - char buf[50] = {0}; - CCARRAY_FOREACH(p, obj) - { - if (i > 0) { - _result += "\n"; - } - sprintf(buf, "%s%02d: ", _indentStr.c_str(), i); - _result += buf; - PrettyPrinter v(_indentLevel); - obj->acceptVisitor(v); - _result += v.getResult(); - i++; - } - setIndentLevel(_indentLevel-1); - - _result += "\n"; - _result += _indentStr; - _result += ""; -} - -void PrettyPrinter::visit(const Dictionary *p) -{ - _result += "\n"; - _result += _indentStr; - _result += "\n"; - - setIndentLevel(_indentLevel+1); - DictElement* element; - bool bFirstElement = true; - char buf[1000] = {0}; - CCDICT_FOREACH(p, element) - { - if (!bFirstElement) { - _result += "\n"; - } - sprintf(buf, "%s%s: ", _indentStr.c_str(),element->getStrKey()); - _result += buf; - PrettyPrinter v(_indentLevel); - element->getObject()->acceptVisitor(v); - _result += v.getResult(); - bFirstElement = false; - } - setIndentLevel(_indentLevel-1); - - _result += "\n"; - _result += _indentStr; - _result += ""; -} - -void PrettyPrinter::visit(const Set *p) -{ - _result += "\n"; - _result += _indentStr; - _result += "\n"; - - setIndentLevel(_indentLevel+1); - - int i = 0; - Set* tmp = const_cast(p); - SetIterator it = tmp->begin(); - - for (; it != tmp->end(); ++it, ++i) { - if (i > 0) { - _result += "\n"; - } - _result += _indentStr.c_str(); - PrettyPrinter v(_indentLevel); - (*it)->acceptVisitor(v); - _result += v.getResult(); - } - setIndentLevel(_indentLevel-1); - - _result += "\n"; - _result += _indentStr; - _result += "\n"; -} - -void PrettyPrinter::visit(const Data *p) -{ - //TODO Implement - DataVisitor::visit(p); -} - -void PrettyPrinter::setIndentLevel(int indentLevel) -{ - _indentLevel = indentLevel; - _indentStr.clear(); - for (int i = 0; i < _indentLevel; ++i) { - _indentStr += "\t"; - } -} - -NS_CC_END diff --git a/cocos/platform/cocoa/CCDataVisitor.h b/cocos/platform/cocoa/CCDataVisitor.h deleted file mode 100644 index 3395b43dea..0000000000 --- a/cocos/platform/cocoa/CCDataVisitor.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#ifndef __CCDATAVISITOR_H__ -#define __CCDATAVISITOR_H__ - -#include "platform/CCPlatformMacros.h" -#include - -NS_CC_BEGIN - -class Object; -class Bool; -class Integer; -class Float; -class Double; -class String; -class Array; -class Dictionary; -class Set; -class Data; - -/** - * @addtogroup data_structures - * @{ - */ - -/** - * Visitor that helps to perform action that depends on polymorphic object type - * - * Use cases: - * - data serialization, - * - pretty printing of Object * - * - safe value reading from Array, Dictionary, Set - * - * Usage: - * 1. subclass DataVisitor - * 2. overload visit() methods for object that you need to handle - * 3. handle other objects in visitObject() - * 4. pass your visitor to Object::acceptVisitor() - */ -class CC_DLL DataVisitor -{ -public: - /** - * @js NA - * @lua NA - */ - virtual ~DataVisitor() {} - - /** default method, called from non-overloaded methods and for unrecognized objects */ - virtual void visitObject(const Object *p) = 0; - - virtual void visit(const Bool *p); - virtual void visit(const Integer *p); - virtual void visit(const Float *p); - virtual void visit(const Double *p); - virtual void visit(const String *p); - virtual void visit(const Array *p); - virtual void visit(const Dictionary *p); - virtual void visit(const Set *p); - virtual void visit(const Data *p); -}; - - -class CC_DLL PrettyPrinter : public DataVisitor -{ -public: - PrettyPrinter(int indentLevel = 0); - - virtual void clear(); - virtual std::string getResult(); - - virtual void visitObject(const Object *p); - virtual void visit(const Bool * p); - virtual void visit(const Integer *p); - virtual void visit(const Float *p); - virtual void visit(const Double *p); - virtual void visit(const String *p); - virtual void visit(const Array *p); - virtual void visit(const Dictionary *p); - virtual void visit(const Set *p); - virtual void visit(const Data *p); -private: - void setIndentLevel(int indentLevel); - int _indentLevel; - std::string _indentStr; - std::string _result; -}; - -// end of data_structure group -/// @} - -NS_CC_END - -#endif // __CCDATAVISITOR_H__ diff --git a/cocos/platform/cocoa/CCDictionary.cpp b/cocos/platform/cocoa/CCDictionary.cpp deleted file mode 100644 index 6b8df0febf..0000000000 --- a/cocos/platform/cocoa/CCDictionary.cpp +++ /dev/null @@ -1,454 +0,0 @@ -/**************************************************************************** - Copyright (c) 2012 - 2013 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#include "CCDictionary.h" -#include "CCString.h" -#include "CCInteger.h" -#include "platform/CCFileUtils.h" - -using namespace std; - -NS_CC_BEGIN - -// ----------------------------------------------------------------------- -// DictElement - -DictElement::DictElement(const char* pszKey, Object* pObject) -{ - CCASSERT(pszKey && strlen(pszKey) > 0, "Invalid key value."); - _intKey = 0; - const char* pStart = pszKey; - - size_t len = strlen(pszKey); - if (len > MAX_KEY_LEN ) - { - char* pEnd = (char*)&pszKey[len-1]; - pStart = pEnd - (MAX_KEY_LEN-1); - } - - strcpy(_strKey, pStart); - - _object = pObject; - memset(&hh, 0, sizeof(hh)); -} - -DictElement::DictElement(intptr_t iKey, Object* pObject) -{ - _strKey[0] = '\0'; - _intKey = iKey; - _object = pObject; - memset(&hh, 0, sizeof(hh)); -} - -DictElement::~DictElement() -{ - CCLOGINFO("deallocing DictElement: %p", this); -} - -// ----------------------------------------------------------------------- -// Dictionary - -Dictionary::Dictionary() -: _elements(NULL) -, _dictType(kDictUnknown) -{ - -} - -Dictionary::~Dictionary() -{ - CCLOGINFO("deallocing Dictionary: %p", this); - removeAllObjects(); -} - -unsigned int Dictionary::count() -{ - return HASH_COUNT(_elements); -} - -Array* Dictionary::allKeys() -{ - int iKeyCount = this->count(); - if (iKeyCount <= 0) return NULL; - - Array* pArray = Array::createWithCapacity(iKeyCount); - - DictElement *pElement, *tmp; - if (_dictType == kDictStr) - { - HASH_ITER(hh, _elements, pElement, tmp) - { - String* pOneKey = new String(pElement->_strKey); - pArray->addObject(pOneKey); - CC_SAFE_RELEASE(pOneKey); - } - } - else if (_dictType == kDictInt) - { - HASH_ITER(hh, _elements, pElement, tmp) - { - Integer* pOneKey = new Integer(pElement->_intKey); - pArray->addObject(pOneKey); - CC_SAFE_RELEASE(pOneKey); - } - } - - return pArray; -} - -Array* Dictionary::allKeysForObject(Object* object) -{ - int iKeyCount = this->count(); - if (iKeyCount <= 0) return NULL; - Array* pArray = Array::create(); - - DictElement *pElement, *tmp; - - if (_dictType == kDictStr) - { - HASH_ITER(hh, _elements, pElement, tmp) - { - if (object == pElement->_object) - { - String* pOneKey = new String(pElement->_strKey); - pArray->addObject(pOneKey); - CC_SAFE_RELEASE(pOneKey); - } - } - } - else if (_dictType == kDictInt) - { - HASH_ITER(hh, _elements, pElement, tmp) - { - if (object == pElement->_object) - { - Integer* pOneKey = new Integer(pElement->_intKey); - pArray->addObject(pOneKey); - CC_SAFE_RELEASE(pOneKey); - } - } - } - return pArray; -} - -Object* Dictionary::objectForKey(const std::string& key) -{ - // if dictionary wasn't initialized, return NULL directly. - if (_dictType == kDictUnknown) return NULL; - // Dictionary only supports one kind of key, string or integer. - // This method uses string as key, therefore we should make sure that the key type of this Dictionary is string. - CCASSERT(_dictType == kDictStr, "this dictionary does not use string as key."); - - Object* pRetObject = NULL; - DictElement *pElement = NULL; - HASH_FIND_STR(_elements, key.c_str(), pElement); - if (pElement != NULL) - { - pRetObject = pElement->_object; - } - return pRetObject; -} - -Object* Dictionary::objectForKey(intptr_t key) -{ - // if dictionary wasn't initialized, return NULL directly. - if (_dictType == kDictUnknown) return NULL; - // Dictionary only supports one kind of key, string or integer. - // This method uses integer as key, therefore we should make sure that the key type of this Dictionary is integer. - CCASSERT(_dictType == kDictInt, "this dictionary does not use integer as key."); - - Object* pRetObject = NULL; - DictElement *pElement = NULL; - HASH_FIND_PTR(_elements, &key, pElement); - if (pElement != NULL) - { - pRetObject = pElement->_object; - } - return pRetObject; -} - -const String* Dictionary::valueForKey(const std::string& key) -{ - String* pStr = dynamic_cast(objectForKey(key)); - if (pStr == NULL) - { - pStr = String::create(""); - } - return pStr; -} - -const String* Dictionary::valueForKey(intptr_t key) -{ - String* pStr = dynamic_cast(objectForKey(key)); - if (pStr == NULL) - { - pStr = String::create(""); - } - return pStr; -} - -void Dictionary::setObject(Object* pObject, const std::string& key) -{ - CCASSERT(key.length() > 0 && pObject != NULL, "Invalid Argument!"); - if (_dictType == kDictUnknown) - { - _dictType = kDictStr; - } - - CCASSERT(_dictType == kDictStr, "this dictionary doesn't use string as key."); - - DictElement *pElement = NULL; - HASH_FIND_STR(_elements, key.c_str(), pElement); - if (pElement == NULL) - { - setObjectUnSafe(pObject, key); - } - else if (pElement->_object != pObject) - { - Object* pTmpObj = pElement->_object; - pTmpObj->retain(); - removeObjectForElememt(pElement); - setObjectUnSafe(pObject, key); - pTmpObj->release(); - } -} - -void Dictionary::setObject(Object* pObject, intptr_t key) -{ - CCASSERT(pObject != NULL, "Invalid Argument!"); - if (_dictType == kDictUnknown) - { - _dictType = kDictInt; - } - - CCASSERT(_dictType == kDictInt, "this dictionary doesn't use integer as key."); - - DictElement *pElement = NULL; - HASH_FIND_PTR(_elements, &key, pElement); - if (pElement == NULL) - { - setObjectUnSafe(pObject, key); - } - else if (pElement->_object != pObject) - { - Object* pTmpObj = pElement->_object; - pTmpObj->retain(); - removeObjectForElememt(pElement); - setObjectUnSafe(pObject, key); - pTmpObj->release(); - } - -} - -void Dictionary::removeObjectForKey(const std::string& key) -{ - if (_dictType == kDictUnknown) - { - return; - } - - CCASSERT(_dictType == kDictStr, "this dictionary doesn't use string as its key"); - CCASSERT(key.length() > 0, "Invalid Argument!"); - DictElement *pElement = NULL; - HASH_FIND_STR(_elements, key.c_str(), pElement); - removeObjectForElememt(pElement); -} - -void Dictionary::removeObjectForKey(intptr_t key) -{ - if (_dictType == kDictUnknown) - { - return; - } - - CCASSERT(_dictType == kDictInt, "this dictionary doesn't use integer as its key"); - DictElement *pElement = NULL; - HASH_FIND_PTR(_elements, &key, pElement); - removeObjectForElememt(pElement); -} - -void Dictionary::setObjectUnSafe(Object* pObject, const std::string& key) -{ - pObject->retain(); - DictElement* pElement = new DictElement(key.c_str(), pObject); - HASH_ADD_STR(_elements, _strKey, pElement); -} - -void Dictionary::setObjectUnSafe(Object* pObject, const intptr_t key) -{ - pObject->retain(); - DictElement* pElement = new DictElement(key, pObject); - HASH_ADD_PTR(_elements, _intKey, pElement); -} - -void Dictionary::removeObjectsForKeys(Array* pKeyArray) -{ - Object* pObj = NULL; - CCARRAY_FOREACH(pKeyArray, pObj) - { - String* pStr = static_cast(pObj); - removeObjectForKey(pStr->getCString()); - } -} - -void Dictionary::removeObjectForElememt(DictElement* pElement) -{ - if (pElement != NULL) - { - HASH_DEL(_elements, pElement); - pElement->_object->release(); - CC_SAFE_DELETE(pElement); - } -} - -void Dictionary::removeAllObjects() -{ - DictElement *pElement, *tmp; - HASH_ITER(hh, _elements, pElement, tmp) - { - HASH_DEL(_elements, pElement); - pElement->_object->release(); - CC_SAFE_DELETE(pElement); - - } -} - -Object* Dictionary::randomObject() -{ - if (_dictType == kDictUnknown) - { - return NULL; - } - - Object* key = allKeys()->getRandomObject(); - - if (_dictType == kDictInt) - { - return objectForKey( static_cast(key)->getValue()); - } - else if (_dictType == kDictStr) - { - return objectForKey( static_cast(key)->getCString()); - } - else - { - return NULL; - } -} - -Dictionary* Dictionary::create() -{ - Dictionary* ret = new Dictionary(); - if (ret && ret->init() ) - { - ret->autorelease(); - } - return ret; -} - -bool Dictionary::init() -{ - return true; -} - -Dictionary* Dictionary::createWithDictionary(Dictionary* srcDict) -{ - return srcDict->clone(); -} - -Dictionary* Dictionary::createWithContentsOfFileThreadSafe(const char *pFileName) -{ - return FileUtils::getInstance()->createDictionaryWithContentsOfFile(pFileName); -} - -void Dictionary::acceptVisitor(DataVisitor &visitor) -{ - return visitor.visit(this); -} - -Dictionary* Dictionary::createWithContentsOfFile(const char *pFileName) -{ - auto ret = createWithContentsOfFileThreadSafe(pFileName); - if (ret != nullptr) - { - ret->autorelease(); - } - return ret; -} - -bool Dictionary::writeToFile(const char *fullPath) -{ - return FileUtils::getInstance()->writeToFile(this, fullPath); -} - -Dictionary* Dictionary::clone() const -{ - Dictionary* newDict = Dictionary::create(); - - DictElement* element = NULL; - Object* tmpObj = NULL; - Clonable* obj = NULL; - if (_dictType == kDictInt) - { - CCDICT_FOREACH(this, element) - { - obj = dynamic_cast(element->getObject()); - if (obj) - { - tmpObj = dynamic_cast(obj->clone()); - if (tmpObj) - { - newDict->setObject(tmpObj, element->getIntKey()); - } - } - else - { - CCLOGWARN("%s isn't clonable.", typeid(*element->getObject()).name()); - } - } - } - else if (_dictType == kDictStr) - { - CCDICT_FOREACH(this, element) - { - obj = dynamic_cast(element->getObject()); - if (obj) - { - tmpObj = dynamic_cast(obj->clone()); - if (tmpObj) - { - newDict->setObject(tmpObj, element->getStrKey()); - } - } - else - { - CCLOGWARN("%s isn't clonable.", typeid(*element->getObject()).name()); - } - } - } - - return newDict; -} - -NS_CC_END diff --git a/cocos/platform/cocoa/CCDictionary.h b/cocos/platform/cocoa/CCDictionary.h deleted file mode 100644 index b0f1c98a9c..0000000000 --- a/cocos/platform/cocoa/CCDictionary.h +++ /dev/null @@ -1,458 +0,0 @@ -/**************************************************************************** -Copyright (c) 2012 - 2013 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __CCDICTIONARY_H__ -#define __CCDICTIONARY_H__ - -#include "support/data_support/uthash.h" -#include "CCObject.h" -#include "CCArray.h" -#include "CCString.h" - -NS_CC_BEGIN - -class Dictionary; - -/** - * @addtogroup data_structures - * @{ - */ - - -/** - * DictElement is used for traversing Dictionary. - * - * A DictElement is one element of Dictionary, it contains two properties, key and object. - * Its key has two different type (integer and string). - * - * @note The key type is unique, all the elements in Dictionary has the same key type(integer or string). - * @code - * DictElement* pElement; - * CCDICT_FOREACH(dict, pElement) - * { - * const char*key = pElement->getStrKey(); - * // You certainly know the type of value, so we assume that it's a Sprite. - * Sprite* pSprite = static_cast(pElement->getObject()); - * // ...... - * } - * @endcode - * - */ -class CC_DLL DictElement -{ -private: - /** - * Constructor of DictElement. It's only for internal usage. Dictionary is its friend class. - * - * @param pszKey The string key of this element. - * @param pObject The object of this element. - */ - DictElement(const char* pszKey, Object* pObject); - - /** - * Constructor of DictElement. It's only for internal usage. Dictionary is its friend class. - * - * @param iKey The integer key of this element. - * @param pObject The object of this element. - */ - DictElement(intptr_t iKey, Object* pObject); - -public: - /** - * The destructor of DictElement. - * @js NA - * @lua NA - */ - ~DictElement(); - - // Inline functions need to be implemented in header file on Android. - - /** - * Get the string key of this element. - * @note This method assumes you know the key type in the element. - * If the element's key type is integer, invoking this method will cause an assert. - * - * @return The string key of this element. - */ - inline const char* getStrKey() const - { - CCASSERT(_strKey[0] != '\0', "Should not call this function for integer dictionary"); - return _strKey; - } - - /** - * Get the integer key of this element. - * @note This method assumes you know the key type in the element. - * If the element's key type is string, invoking this method will cause an assert. - * - * @return The integer key of this element. - */ - inline intptr_t getIntKey() const - { - CCASSERT(_strKey[0] == '\0', "Should not call this function for string dictionary"); - return _intKey; - } - - /** - * Get the object of this element. - * - * @return The object of this element. - */ - inline Object* getObject() const { return _object; } - -private: - // The max length of string key. - #define MAX_KEY_LEN 256 - // char array is needed for HASH_ADD_STR in UT_HASH. - // So it's a pain that all elements will allocate 256 bytes for this array. - char _strKey[MAX_KEY_LEN]; // hash key of string type - intptr_t _intKey; // hash key of integer type - Object* _object; // hash value -public: - UT_hash_handle hh; // makes this class hashable - friend class Dictionary; // declare Dictionary as friend class -}; - -/** The macro for traversing dictionary - * - * @note It's faster than getting all keys and traversing keys to get objects by objectForKey. - * It's also safe to remove elements while traversing. - */ -#define CCDICT_FOREACH(__dict__, __el__) \ - DictElement* pTmp##__dict__##__el__ = nullptr; \ - if (__dict__) \ - HASH_ITER(hh, (__dict__)->_elements, __el__, pTmp##__dict__##__el__) - - - -/** - * Dictionary is a class like NSDictionary in Obj-C . - * - * @note Only the pointer of Object or its subclass can be inserted to Dictionary. - * @code - * // Create a dictionary, return an autorelease object. - * Dictionary* pDict = Dictionary::create(); - * - * // Insert objects to dictionary - * String* pValue1 = String::create("100"); - * String* pValue2 = String::create("120"); - * Integer* pValue3 = Integer::create(200); - * pDict->setObject(pValue1, "key1"); - * pDict->setObject(pValue2, "key2"); - * pDict->setObject(pValue3, "key3"); - * - * // Get the object for key - * String* pStr1 = (String*)pDict->objectForKey("key1"); - * log("{ key1: %s }", pStr1->getCString()); - * Integer* pInteger = (Integer*)pDict->objectForKey("key3"); - * log("{ key3: %d }", pInteger->getValue()); - * @endcode - * - */ - -class CC_DLL Dictionary : public Object, public Clonable -{ -public: - /** - * The constructor of Dictionary. - * @js NA - * @lua NA - */ - Dictionary(); - - /** - * The destructor of Dictionary - * @js NA - * @lua NA - */ - ~Dictionary(); - - /** Initializes the dictionary. It returns true if the initializations was successful. - * @js NA - * @lua NA - */ - bool init(); - /** - * Get the count of elements in Dictionary. - * - * @return The count of elements. - * @js NA - */ - unsigned int count(); - - /** - * Return all keys of elements. - * - * @return The array contains all keys of elements. It's an autorelease object yet. - * @js NA - */ - Array* allKeys(); - - /** - * Get all keys according to the specified object. - * @warning We use '==' to compare two objects - * @return The array contains all keys for the specified object. It's an autorelease object yet. - * @js NA - */ - Array* allKeysForObject(Object* object); - - /** - * Get the object according to the specified string key. - * - * @note The dictionary needs to use string as key. If integer is passed, an assert will appear. - * @param key The string key for searching. - * @return The object matches the key. You need to force convert it to the type you know. - * @code - * // Assume that the elements are String* pointers. Convert it by following code. - * String* pStr = (String*)pDict->objectForKey("key1"); - * // Do something about pStr. - * // If you don't know the object type, properly you need to use dynamic_cast to check it. - * String* pStr2 = dynamic_cast(pDict->objectForKey("key1")); - * if (pStr2 != NULL) { - * // Do something about pStr2 - * } - * @endcode - * @see objectForKey(intptr_t) - * @js NA - */ - Object* objectForKey(const std::string& key); - - /** - * Get the object according to the specified integer key. - * - * @note The dictionary needs to use integer as key. If string is passed, an assert will appear. - * @param key The integer key for searching. - * @return The object matches the key. - * @see objectForKey(const std::string&) - * @js NA - */ - Object* objectForKey(intptr_t key); - - /** Get the value according to the specified string key. - * - * @note Be careful to use this function since it assumes the objects in the dictionary are String pointer. - * @param key The string key for searching - * @return An instance of String. - * It will return an empty string if the objects aren't String pointer or the key wasn't found. - * @see valueForKey(intptr_t) - * @js NA - */ - const String* valueForKey(const std::string& key); - - /** Get the value according to the specified integer key. - * - * @note Be careful to use this function since it assumes the objects in the dictionary are String pointer. - * @param key The string key for searching. - * @return An instance of String. - * It will return an empty string if the objects aren't String pointer or the key wasn't found. - * @see valueForKey(intptr_t) - * @js NA - */ - const String* valueForKey(intptr_t key); - - /** Insert an object to dictionary, and match it with the specified string key. - * - * @note Whe the first time this method is invoked, the key type will be set to string. - * After that you can't setObject with an integer key. - * If the dictionary contains the key you passed, the object matching the key will be released and removed from dictionary. - * Then the new object will be inserted after that. - * - * @param pObject The Object to be inserted. - * @param key The string key for searching. - * @see setObject(Object*, intptr_t) - * @js NA - */ - void setObject(Object* pObject, const std::string& key); - - /** Insert an object to dictionary, and match it with the specified string key. - * - * @note Then the first time this method is invoked, the key type will be set to string. - * After that you can't setObject with an integer key. - * If the dictionary contains the key you passed, the object matching the key will be released and removed from dictionary. - * Then the new object will be inserted after that. - * @param pObject The Object to be inserted. - * @param key The string key for searching. - * @see setObject(Object*, const std::string&) - * @js NA - */ - void setObject(Object* pObject, intptr_t key); - - /** - * Remove an object by the specified string key. - * - * @param key The string key for searching. - * @see removeObjectForKey(intptr_t), removeObjectsForKeys(Array*), - * removeObjectForElememt(DictElement*), removeAllObjects(). - * @js NA - */ - void removeObjectForKey(const std::string& key); - - /** - * Remove an object by the specified integer key. - * - * @param key The integer key for searching. - * @see removeObjectForKey(const std::string&), removeObjectsForKeys(Array*), - * removeObjectForElememt(DictElement*), removeAllObjects(). - * @js NA - */ - void removeObjectForKey(intptr_t key); - - /** - * Remove objects by an array of keys. - * - * @param pKeyArray The array contains keys to be removed. - * @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t), - * removeObjectForElememt(DictElement*), removeAllObjects(). - * @js NA - */ - void removeObjectsForKeys(Array* pKeyArray); - - /** - * Remove an object by an element. - * - * @param pElement The element need to be removed. - * @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t), - * removeObjectsForKeys(Array*), removeAllObjects(). - * @js NA - * @lua NA - */ - void removeObjectForElememt(DictElement* pElement); - - /** - * Remove all objects in the dictionary. - * - * @see removeObjectForKey(const std::string&), removeObjectForKey(intptr_t), - * removeObjectsForKeys(Array*), removeObjectForElememt(DictElement*). - * @js NA - */ - void removeAllObjects(); - - /** - * Return a random object in the dictionary. - * - * @return The random object. - * @see objectForKey(intptr_t), objectForKey(const std::string&) - * @js NA - * @lua NA - */ - Object* randomObject(); - - /** - * Create a dictionary. - * @return A dictionary which is an autorelease object. - * @see createWithDictionary(Dictionary*), createWithContentsOfFile(const char*), createWithContentsOfFileThreadSafe(const char*). - * @js NA - */ - static Dictionary* create(); - - /** - * Create a dictionary with an existing dictionary. - * - * @param srcDict The exist dictionary. - * @return A dictionary which is an autorelease object. - * @see create(), createWithContentsOfFile(const char*), createWithContentsOfFileThreadSafe(const char*). - * @js NA - */ - static Dictionary* createWithDictionary(Dictionary* srcDict); - - /** - * Create a dictionary with a plist file. - * @param pFileName The name of the plist file. - * @return A dictionary which is an autorelease object. - * @see create(), createWithDictionary(Dictionary*), createWithContentsOfFileThreadSafe(const char*). - * @js NA - */ - static Dictionary* createWithContentsOfFile(const char *pFileName); - - /** - * Write a dictionary to a plist file. - * @param fullPath The full path of the plist file. You can get writeable path by getWritablePath() - * @return true if successed, false if failed - * @js NA - * @lua NA - */ - bool writeToFile(const char *fullPath); - - /** - * Create a dictionary with a plist file. - * - * @note the return object isn't an autorelease object. - * This can make sure not using autorelease pool in a new thread. - * Therefore, you need to manage the lifecycle of the return object. - * It means that when you don't need it, CC_SAFE_RELEASE needs to be invoked. - * - * @param pFileName The name of the plist file. - * @return A dictionary which isn't an autorelease object. - * @js NA - * @lua NA - */ - static Dictionary* createWithContentsOfFileThreadSafe(const char *pFileName); - - /* override functions - * @js NA - * @lua NA - */ - virtual void acceptVisitor(DataVisitor &visitor); - /** - * @js NA - * @lua NA - */ - virtual Dictionary* clone() const; - -private: - /** - * For internal usage, invoked by setObject. - */ - void setObjectUnSafe(Object* pObject, const std::string& key); - void setObjectUnSafe(Object* pObject, const intptr_t key); - -public: - /** - * All the elements in dictionary. - * - * @note For internal usage, we need to declare this member variable as public since it's used in UT_HASH. - */ - DictElement* _elements; -private: - - /** The support type of dictionary, it's confirmed when setObject is invoked. */ - enum DictType - { - kDictUnknown = 0, - kDictStr, - kDictInt - }; - - /** - * The type of dictionary, it's assigned to kDictUnknown by default. - */ - DictType _dictType; -}; - -// end of data_structure group -/// @} - -NS_CC_END - -#endif /* __CCDICTIONARY_H__ */ diff --git a/cocos/platform/cocoa/CCDouble.h b/cocos/platform/cocoa/CCDouble.h deleted file mode 100644 index 5b45b1d6cf..0000000000 --- a/cocos/platform/cocoa/CCDouble.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#ifndef __CCDOUBLE_H__ -#define __CCDOUBLE_H__ - -#include "CCObject.h" - -NS_CC_BEGIN - -/** - * @addtogroup data_structures - * @{ - */ - -class CC_DLL Double : public Object, public Clonable -{ -public: - Double(double v) - : _value(v) {} - double getValue() const {return _value;} - - static Double* create(double v) - { - Double* pRet = new Double(v); - if (pRet) - { - pRet->autorelease(); - } - return pRet; - } - - /* override functions */ - virtual void acceptVisitor(DataVisitor &visitor) { visitor.visit(this); } - - Double* clone() const - { - return Double::create(_value); - } -private: - double _value; -}; - -// end of data_structure group -/// @} - -NS_CC_END - -#endif /* __CCDOUBLE_H__ */ diff --git a/cocos/platform/cocoa/CCFloat.h b/cocos/platform/cocoa/CCFloat.h deleted file mode 100644 index c85a2e1e70..0000000000 --- a/cocos/platform/cocoa/CCFloat.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#ifndef __CCFLOAT_H__ -#define __CCFLOAT_H__ - -#include "CCObject.h" - -NS_CC_BEGIN - -/** - * @addtogroup data_structures - * @{ - */ - -class CC_DLL Float : public Object, public Clonable -{ -public: - Float(float v) - : _value(v) {} - float getValue() const {return _value;} - - static Float* create(float v) - { - Float* pRet = new Float(v); - if (pRet) - { - pRet->autorelease(); - } - return pRet; - } - - /* override functions */ - virtual void acceptVisitor(DataVisitor &visitor) { visitor.visit(this); } - - Float* clone() const - { - return Float::create(_value); - } - -private: - float _value; -}; - -// end of data_structure group -/// @} - -NS_CC_END - -#endif /* __CCFLOAT_H__ */ diff --git a/cocos/platform/cocoa/CCGeometry.cpp b/cocos/platform/cocoa/CCGeometry.cpp deleted file mode 100644 index cfce9d3fa7..0000000000 --- a/cocos/platform/cocoa/CCGeometry.cpp +++ /dev/null @@ -1,463 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "CCGeometry.h" -#include "ccMacros.h" -#include - -// implementation of Point -NS_CC_BEGIN - -Point::Point(void) : x(0), y(0) -{ -} - -Point::Point(float xx, float yy) : x(xx), y(yy) -{ -} - -Point::Point(const Point& other) : x(other.x), y(other.y) -{ -} - -Point::Point(const Size& size) : x(size.width), y(size.height) -{ -} - -Point& Point::operator= (const Point& other) -{ - setPoint(other.x, other.y); - return *this; -} - -Point& Point::operator= (const Size& size) -{ - setPoint(size.width, size.height); - return *this; -} - -Point Point::operator+(const Point& right) const -{ - return Point(this->x + right.x, this->y + right.y); -} - -Point Point::operator-(const Point& right) const -{ - return Point(this->x - right.x, this->y - right.y); -} - -Point Point::operator-() const -{ - return Point(-x, -y); -} - -Point Point::operator*(float a) const -{ - return Point(this->x * a, this->y * a); -} - -Point Point::operator/(float a) const -{ - CCASSERT(a!=0, "CCPoint division by 0."); - return Point(this->x / a, this->y / a); -} - -void Point::setPoint(float xx, float yy) -{ - this->x = xx; - this->y = yy; -} - -bool Point::equals(const Point& target) const -{ - return (fabs(this->x - target.x) < FLT_EPSILON) - && (fabs(this->y - target.y) < FLT_EPSILON); -} - -bool Point::fuzzyEquals(const Point& b, float var) const -{ - if(x - var <= b.x && b.x <= x + var) - if(y - var <= b.y && b.y <= y + var) - return true; - return false; -} - -float Point::getAngle(const Point& other) const -{ - Point a2 = normalize(); - Point b2 = other.normalize(); - float angle = atan2f(a2.cross(b2), a2.dot(b2)); - if( fabs(angle) < FLT_EPSILON ) return 0.f; - return angle; -} - -Point Point::rotateByAngle(const Point& pivot, float angle) const -{ - return pivot + (*this - pivot).rotate(Point::forAngle(angle)); -} - -bool Point::isOneDemensionSegmentOverlap(float A, float B, float C, float D, float *S, float *E) -{ - float ABmin = MIN(A, B); - float ABmax = MAX(A, B); - float CDmin = MIN(C, D); - float CDmax = MAX(C, D); - - if (ABmax < CDmin || CDmax < ABmin) - { - // ABmin->ABmax->CDmin->CDmax or CDmin->CDmax->ABmin->ABmax - return false; - } - else - { - if (ABmin >= CDmin && ABmin <= CDmax) - { - // CDmin->ABmin->CDmax->ABmax or CDmin->ABmin->ABmax->CDmax - if (S != nullptr) *S = ABmin; - if (E != nullptr) *E = CDmax < ABmax ? CDmax : ABmax; - } - else if (ABmax >= CDmin && ABmax <= CDmax) - { - // ABmin->CDmin->ABmax->CDmax - if (S != nullptr) *S = CDmin; - if (E != nullptr) *E = ABmax; - } - else - { - // ABmin->CDmin->CDmax->ABmax - if (S != nullptr) *S = CDmin; - if (E != nullptr) *E = CDmax; - } - return true; - } -} - -bool Point::isLineIntersect(const Point& A, const Point& B, - const Point& C, const Point& D, - float *S, float *T) -{ - // FAIL: Line undefined - if ( (A.x==B.x && A.y==B.y) || (C.x==D.x && C.y==D.y) ) - { - return false; - } - - const float denom = crossProduct2Vector(A, B, C, D); - - if (denom == 0) - { - // Lines parallel or overlap - return false; - } - - if (S != nullptr) *S = crossProduct2Vector(C, D, C, A) / denom; - if (T != nullptr) *T = crossProduct2Vector(A, B, C, A) / denom; - - return true; -} - -bool Point::isLineParallel(const Point& A, const Point& B, - const Point& C, const Point& D) -{ - // FAIL: Line undefined - if ( (A.x==B.x && A.y==B.y) || (C.x==D.x && C.y==D.y) ) - { - return false; - } - - if (crossProduct2Vector(A, B, C, D) == 0) - { - // line overlap - if (crossProduct2Vector(C, D, C, A) == 0 || crossProduct2Vector(A, B, C, A) == 0) - { - return false; - } - - return true; - } - - return false; -} - -bool Point::isLineOverlap(const Point& A, const Point& B, - const Point& C, const Point& D) -{ - // FAIL: Line undefined - if ( (A.x==B.x && A.y==B.y) || (C.x==D.x && C.y==D.y) ) - { - return false; - } - - if (crossProduct2Vector(A, B, C, D) == 0 && - (crossProduct2Vector(C, D, C, A) == 0 || crossProduct2Vector(A, B, C, A) == 0)) - { - return true; - } - - return false; -} - -bool Point::isSegmentOverlap(const Point& A, const Point& B, const Point& C, const Point& D, Point* S, Point* E) -{ - - if (isLineOverlap(A, B, C, D)) - { - return isOneDemensionSegmentOverlap(A.x, B.x, C.x, D.x, &S->x, &E->x) && - isOneDemensionSegmentOverlap(A.y, B.y, C.y, D.y, &S->y, &E->y); - } - - return false; -} - -bool Point::isSegmentIntersect(const Point& A, const Point& B, const Point& C, const Point& D) -{ - float S, T; - - if (isLineIntersect(A, B, C, D, &S, &T )&& - (S >= 0.0f && S <= 1.0f && T >= 0.0f && T <= 1.0f)) - { - return true; - } - - return false; -} - -Point Point::getIntersectPoint(const Point& A, const Point& B, const Point& C, const Point& D) -{ - float S, T; - - if (isLineIntersect(A, B, C, D, &S, &T)) - { - // Point of intersection - Point P; - P.x = A.x + S * (B.x - A.x); - P.y = A.y + S * (B.y - A.y); - return P; - } - - return Point::ZERO; -} - -const Point Point::ZERO = Point(0, 0); - -// implementation of Size - -Size::Size(void) : width(0), height(0) -{ -} - -Size::Size(float w, float h) : width(w), height(h) -{ -} - -Size::Size(const Size& other) : width(other.width), height(other.height) -{ -} - -Size::Size(const Point& point) : width(point.x), height(point.y) -{ -} - -Size& Size::operator= (const Size& other) -{ - setSize(other.width, other.height); - return *this; -} - -Size& Size::operator= (const Point& point) -{ - setSize(point.x, point.y); - return *this; -} - -Size Size::operator+(const Size& right) const -{ - return Size(this->width + right.width, this->height + right.height); -} - -Size Size::operator-(const Size& right) const -{ - return Size(this->width - right.width, this->height - right.height); -} - -Size Size::operator*(float a) const -{ - return Size(this->width * a, this->height * a); -} - -Size Size::operator/(float a) const -{ - CCASSERT(a!=0, "CCSize division by 0."); - return Size(this->width / a, this->height / a); -} - -void Size::setSize(float w, float h) -{ - this->width = w; - this->height = h; -} - -bool Size::equals(const Size& target) const -{ - return (fabs(this->width - target.width) < FLT_EPSILON) - && (fabs(this->height - target.height) < FLT_EPSILON); -} - -const Size Size::ZERO = Size(0, 0); - -// implementation of Rect - -Rect::Rect(void) -{ - setRect(0.0f, 0.0f, 0.0f, 0.0f); -} - -Rect::Rect(float x, float y, float width, float height) -{ - setRect(x, y, width, height); -} - -Rect::Rect(const Rect& other) -{ - setRect(other.origin.x, other.origin.y, other.size.width, other.size.height); -} - -Rect& Rect::operator= (const Rect& other) -{ - setRect(other.origin.x, other.origin.y, other.size.width, other.size.height); - return *this; -} - -void Rect::setRect(float x, float y, float width, float height) -{ - // CGRect can support width<0 or height<0 - // CCASSERT(width >= 0.0f && height >= 0.0f, "width and height of Rect must not less than 0."); - - origin.x = x; - origin.y = y; - - size.width = width; - size.height = height; -} - -bool Rect::equals(const Rect& rect) const -{ - return (origin.equals(rect.origin) && - size.equals(rect.size)); -} - -float Rect::getMaxX() const -{ - return origin.x + size.width; -} - -float Rect::getMidX() const -{ - return origin.x + size.width / 2.0f; -} - -float Rect::getMinX() const -{ - return origin.x; -} - -float Rect::getMaxY() const -{ - return origin.y + size.height; -} - -float Rect::getMidY() const -{ - return origin.y + size.height / 2.0f; -} - -float Rect::getMinY() const -{ - return origin.y; -} - -bool Rect::containsPoint(const Point& point) const -{ - bool bRet = false; - - if (point.x >= getMinX() && point.x <= getMaxX() - && point.y >= getMinY() && point.y <= getMaxY()) - { - bRet = true; - } - - return bRet; -} - -bool Rect::intersectsRect(const Rect& rect) const -{ - return !( getMaxX() < rect.getMinX() || - rect.getMaxX() < getMinX() || - getMaxY() < rect.getMinY() || - rect.getMaxY() < getMinY()); -} - -Rect Rect::unionWithRect(const Rect & rect) const -{ - float thisLeftX = origin.x; - float thisRightX = origin.x + size.width; - float thisTopY = origin.y + size.height; - float thisBottomY = origin.y; - - if (thisRightX < thisLeftX) - { - std::swap(thisRightX, thisLeftX); // This rect has negative width - } - - if (thisTopY < thisBottomY) - { - std::swap(thisTopY, thisBottomY); // This rect has negative height - } - - float otherLeftX = rect.origin.x; - float otherRightX = rect.origin.x + rect.size.width; - float otherTopY = rect.origin.y + rect.size.height; - float otherBottomY = rect.origin.y; - - if (otherRightX < otherLeftX) - { - std::swap(otherRightX, otherLeftX); // Other rect has negative width - } - - if (otherTopY < otherBottomY) - { - std::swap(otherTopY, otherBottomY); // Other rect has negative height - } - - float combinedLeftX = std::min(thisLeftX, otherLeftX); - float combinedRightX = std::max(thisRightX, otherRightX); - float combinedTopY = std::max(thisTopY, otherTopY); - float combinedBottomY = std::min(thisBottomY, otherBottomY); - - return Rect(combinedLeftX, combinedBottomY, combinedRightX - combinedLeftX, combinedTopY - combinedBottomY); -} - -const Rect Rect::ZERO = Rect(0, 0, 0, 0); - -NS_CC_END diff --git a/cocos/platform/cocoa/CCGeometry.h b/cocos/platform/cocoa/CCGeometry.h deleted file mode 100644 index 47e2fdf9ac..0000000000 --- a/cocos/platform/cocoa/CCGeometry.h +++ /dev/null @@ -1,564 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __CCGEMETRY_H__ -#define __CCGEMETRY_H__ - -#include -#include - -#include "platform/CCPlatformMacros.h" -#include "CCObject.h" -#include "ccMacros.h" - -NS_CC_BEGIN - -/** Clamp a value between from and to. - @since v0.99.1 - */ -inline float clampf(float value, float min_inclusive, float max_inclusive) -{ - if (min_inclusive > max_inclusive) { - CC_SWAP(min_inclusive, max_inclusive, float); - } - return value < min_inclusive ? min_inclusive : value < max_inclusive? value : max_inclusive; -} - -/** - * @addtogroup data_structures - * @{ - */ - -// for Point assignement operator and copy constructor -class CC_DLL Size; - -class CC_DLL Point -{ -public: - float x; - float y; - -public: - /** - * @js NA - */ - Point(); - /** - * @js NA - */ - Point(float x, float y); - /** - * @js NA - * @lua NA - */ - Point(const Point& other); - /** - * @js NA - * @lua NA - */ - explicit Point(const Size& size); - /** - * @js NA - * @lua NA - */ - Point& operator= (const Point& other); - /** - * @js NA - * @lua NA - */ - Point& operator= (const Size& size); - /** - * @js NA - * @lua NA - */ - Point operator+(const Point& right) const; - /** - * @js NA - * @lua NA - */ - Point operator-(const Point& right) const; - /** - * @js NA - * @lua NA - */ - Point operator-() const; - /** - * @js NA - * @lua NA - */ - Point operator*(float a) const; - /** - * @js NA - * @lua NA - */ - Point operator/(float a) const; - /** - * @js NA - * @lua NA - */ - void setPoint(float x, float y); - /** - * @js NA - */ - bool equals(const Point& target) const; - - /** @returns if points have fuzzy equality which means equal with some degree of variance. - @since v2.1.4 - * @js NA - * @lua NA - */ - bool fuzzyEquals(const Point& target, float variance) const; - - /** Calculates distance between point an origin - @return float - @since v2.1.4 - * @js NA - * @lua NA - */ - inline float getLength() const { - return sqrtf(x*x + y*y); - }; - - /** Calculates the square length of a Point (not calling sqrt() ) - @return float - @since v2.1.4 - * @js NA - * @lua NA - */ - inline float getLengthSq() const { - return dot(*this); //x*x + y*y; - }; - - /** Calculates the square distance between two points (not calling sqrt() ) - @return float - @since v2.1.4 - * @js NA - * @lua NA - */ - inline float getDistanceSq(const Point& other) const { - return (*this - other).getLengthSq(); - }; - - /** Calculates the distance between two points - @return float - @since v2.1.4 - * @js NA - * @lua NA - */ - inline float getDistance(const Point& other) const { - return (*this - other).getLength(); - }; - - /** @returns the angle in radians between this vector and the x axis - @since v2.1.4 - * @js NA - * @lua NA - */ - inline float getAngle() const { - return atan2f(y, x); - }; - - /** @returns the angle in radians between two vector directions - @since v2.1.4 - * @js NA - * @lua NA - */ - float getAngle(const Point& other) const; - - /** Calculates dot product of two points. - @return float - @since v2.1.4 - * @js NA - * @lua NA - */ - inline float dot(const Point& other) const { - return x*other.x + y*other.y; - }; - - /** Calculates cross product of two points. - @return float - @since v2.1.4 - * @js NA - * @lua NA - */ - inline float cross(const Point& other) const { - return x*other.y - y*other.x; - }; - - /** Calculates perpendicular of v, rotated 90 degrees counter-clockwise -- cross(v, perp(v)) >= 0 - @return Point - @since v2.1.4 - * @js NA - * @lua NA - */ - inline Point getPerp() const { - return Point(-y, x); - }; - - /** Calculates midpoint between two points. - @return Point - @since v3.0 - * @js NA - * @lua NA - */ - inline Point getMidpoint(const Point& other) const - { - return Point((x + other.x) / 2.0f, (y + other.y) / 2.0f); - } - - /** Clamp a point between from and to. - @since v3.0 - * @js NA - * @lua NA - */ - inline Point getClampPoint(const Point& min_inclusive, const Point& max_inclusive) const - { - return Point(clampf(x,min_inclusive.x,max_inclusive.x), clampf(y, min_inclusive.y, max_inclusive.y)); - } - - /** Run a math operation function on each point component - * absf, fllorf, ceilf, roundf - * any function that has the signature: float func(float); - * For example: let's try to take the floor of x,y - * p.compOp(floorf); - @since v3.0 - * @js NA - * @lua NA - */ - inline Point compOp(std::function function) const - { - return Point(function(x), function(y)); - } - - /** Calculates perpendicular of v, rotated 90 degrees clockwise -- cross(v, rperp(v)) <= 0 - @return Point - @since v2.1.4 - * @js NA - * @lua NA - */ - inline Point getRPerp() const { - return Point(y, -x); - }; - - /** Calculates the projection of this over other. - @return Point - @since v2.1.4 - * @js NA - * @lua NA - */ - inline Point project(const Point& other) const { - return other * (dot(other)/other.dot(other)); - }; - - /** Complex multiplication of two points ("rotates" two points). - @return Point vector with an angle of this.getAngle() + other.getAngle(), - and a length of this.getLength() * other.getLength(). - @since v2.1.4 - * @js NA - * @lua NA - */ - inline Point rotate(const Point& other) const { - return Point(x*other.x - y*other.y, x*other.y + y*other.x); - }; - - /** Unrotates two points. - @return Point vector with an angle of this.getAngle() - other.getAngle(), - and a length of this.getLength() * other.getLength(). - @since v2.1.4 - * @js NA - * @lua NA - */ - inline Point unrotate(const Point& other) const { - return Point(x*other.x + y*other.y, y*other.x - x*other.y); - }; - - /** Returns point multiplied to a length of 1. - * If the point is 0, it returns (1, 0) - @return Point - @since v2.1.4 - * @js NA - * @lua NA - */ - inline Point normalize() const { - float length = getLength(); - if(length == 0.) return Point(1.f, 0); - return *this / getLength(); - }; - - /** Linear Interpolation between two points a and b - @returns - alpha == 0 ? a - alpha == 1 ? b - otherwise a value between a..b - @since v2.1.4 - * @js NA - * @lua NA - */ - inline Point lerp(const Point& other, float alpha) const { - return *this * (1.f - alpha) + other * alpha; - }; - - /** Rotates a point counter clockwise by the angle around a pivot - @param pivot is the pivot, naturally - @param angle is the angle of rotation ccw in radians - @returns the rotated point - @since v2.1.4 - * @js NA - * @lua NA - */ - Point rotateByAngle(const Point& pivot, float angle) const; - - /** - * @js NA - * @lua NA - */ - static inline Point forAngle(const float a) - { - return Point(cosf(a), sinf(a)); - } - - /** A general line-line intersection test - @param A the startpoint for the first line L1 = (A - B) - @param B the endpoint for the first line L1 = (A - B) - @param C the startpoint for the second line L2 = (C - D) - @param D the endpoint for the second line L2 = (C - D) - @param S the range for a hitpoint in L1 (p = A + S*(B - A)) - @param T the range for a hitpoint in L2 (p = C + T*(D - C)) - @returns whether these two lines interects. - - Note that to truly test intersection for segments we have to make - sure that S & T lie within [0..1] and for rays, make sure S & T > 0 - the hit point is C + T * (D - C); - the hit point also is A + S * (B - A); - @since 3.0 - * @js NA - * @lua NA - */ - static bool isLineIntersect(const Point& A, const Point& B, - const Point& C, const Point& D, - float *S = nullptr, float *T = nullptr); - - /** - returns true if Line A-B overlap with segment C-D - @since v3.0 - * @js NA - * @lua NA - */ - static bool isLineOverlap(const Point& A, const Point& B, - const Point& C, const Point& D); - - /** - returns true if Line A-B parallel with segment C-D - @since v3.0 - * @js NA - * @lua NA - */ - static bool isLineParallel(const Point& A, const Point& B, - const Point& C, const Point& D); - - /** - returns true if Segment A-B overlap with segment C-D - @since v3.0 - * @js NA - * @lua NA - */ - static bool isSegmentOverlap(const Point& A, const Point& B, - const Point& C, const Point& D, - Point* S = nullptr, Point* E = nullptr); - - /** - returns true if Segment A-B intersects with segment C-D - @since v3.0 - * @js NA - * @lua NA - */ - static bool isSegmentIntersect(const Point& A, const Point& B, const Point& C, const Point& D); - - /** - returns the intersection point of line A-B, C-D - @since v3.0 - * @js NA - * @lua NA - */ - static Point getIntersectPoint(const Point& A, const Point& B, const Point& C, const Point& D); - - static const Point ZERO; - -private: - // returns true if segment A-B intersects with segment C-D. S->E is the ovderlap part - static bool isOneDemensionSegmentOverlap(float A, float B, float C, float D, float *S, float * E); - - // cross procuct of 2 vector. A->B X C->D - static float crossProduct2Vector(const Point& A, const Point& B, const Point& C, const Point& D) { return (D.y - C.y) * (B.x - A.x) - (D.x - C.x) * (B.y - A.y); } -}; - -class CC_DLL Size -{ -public: - float width; - float height; - -public: - /** - * @js NA - */ - Size(); - /** - * @js NA - */ - Size(float width, float height); - /** - * @js NA - * @lua NA - */ - Size(const Size& other); - /** - * @js NA - * @lua NA - */ - explicit Size(const Point& point); - /** - * @js NA - * @lua NA - */ - Size& operator= (const Size& other); - /** - * @js NA - * @lua NA - */ - Size& operator= (const Point& point); - /** - * @js NA - * @lua NA - */ - Size operator+(const Size& right) const; - /** - * @js NA - * @lua NA - */ - Size operator-(const Size& right) const; - /** - * @js NA - * @lua NA - */ - Size operator*(float a) const; - /** - * @js NA - * @lua NA - */ - Size operator/(float a) const; - /** - * @js NA - * @lua NA - */ - void setSize(float width, float height); - /** - * @js NA - */ - bool equals(const Size& target) const; - - static const Size ZERO; -}; - -class CC_DLL Rect -{ -public: - Point origin; - Size size; - -public: - /** - * @js NA - */ - Rect(); - /** - * @js NA - */ - Rect(float x, float y, float width, float height); - /** - * @js NA - * @lua NA - */ - Rect(const Rect& other); - /** - * @js NA - * @lua NA - */ - Rect& operator= (const Rect& other); - /** - * @js NA - * @lua NA - */ - void setRect(float x, float y, float width, float height); - /** - * @js NA - */ - float getMinX() const; /// return the leftmost x-value of current rect - /** - * @js NA - */ - float getMidX() const; /// return the midpoint x-value of current rect - /** - * @js NA - */ - float getMaxX() const; /// return the rightmost x-value of current rect - /** - * @js NA - */ - float getMinY() const; /// return the bottommost y-value of current rect - /** - * @js NA - */ - float getMidY() const; /// return the midpoint y-value of current rect - /** - * @js NA - */ - float getMaxY() const; /// return the topmost y-value of current rect - /** - * @js NA - */ - bool equals(const Rect& rect) const; - /** - * @js NA - */ - bool containsPoint(const Point& point) const; - /** - * @js NA - */ - bool intersectsRect(const Rect& rect) const; - /** - * @js NA - * @lua NA - */ - Rect unionWithRect(const Rect & rect) const; - - static const Rect ZERO; -}; - -// end of data_structure group -/// @} - -NS_CC_END - -#endif // __CCGEMETRY_H__ diff --git a/cocos/platform/cocoa/CCInteger.h b/cocos/platform/cocoa/CCInteger.h deleted file mode 100644 index 23735627dd..0000000000 --- a/cocos/platform/cocoa/CCInteger.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#ifndef __CCINTEGER_H__ -#define __CCINTEGER_H__ - -#include "CCObject.h" -#include "platform/CCCommon.h" - -NS_CC_BEGIN - -/** - * @addtogroup data_structures - * @{ - */ - -class CC_DLL Integer : public Object, public Clonable -{ -public: - static Integer* create(int v) - { - Integer* pRet = new Integer(v); - pRet->autorelease(); - return pRet; - } - /** - * @js NA - */ - Integer(int v) - : _value(v) {} - int getValue() const {return _value;} - /** - * @js NA - * @lua NA - */ - virtual ~Integer() { - CCLOGINFO("deallocing ~Integer: %p", this); - } - - /* override functions */ - virtual void acceptVisitor(DataVisitor &visitor) { visitor.visit(this); } - - // overrides - virtual Integer* clone() const override - { - return Integer::create(_value); - } - -private: - int _value; -}; - -// end of data_structure group -/// @} - -NS_CC_END - -#endif /* __CCINTEGER_H__ */ diff --git a/cocos/platform/cocoa/CCNS.cpp b/cocos/platform/cocoa/CCNS.cpp deleted file mode 100644 index 8cf496c0b1..0000000000 --- a/cocos/platform/cocoa/CCNS.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#include "CCNS.h" -#include -#include -#include -#include - -using namespace std; - -NS_CC_BEGIN - -typedef std::vector strArray; - -// string toolkit -static inline void split(std::string src, const char* token, strArray& vect) -{ - int nend=0; - int nbegin=0; - while(nend != -1) - { - nend = src.find(token, nbegin); - if(nend == -1) - vect.push_back(src.substr(nbegin, src.length()-nbegin)); - else - vect.push_back(src.substr(nbegin, nend-nbegin)); - nbegin = nend + strlen(token); - } -} - -// first, judge whether the form of the string like this: {x,y} -// if the form is right,the string will be split into the parameter strs; -// or the parameter strs will be empty. -// if the form is right return true,else return false. -static bool splitWithForm(const char* pStr, strArray& strs) -{ - bool bRet = false; - - do - { - CC_BREAK_IF(!pStr); - - // string is empty - std::string content = pStr; - CC_BREAK_IF(content.length() == 0); - - int nPosLeft = content.find('{'); - int nPosRight = content.find('}'); - - // don't have '{' and '}' - CC_BREAK_IF(nPosLeft == (int)std::string::npos || nPosRight == (int)std::string::npos); - // '}' is before '{' - CC_BREAK_IF(nPosLeft > nPosRight); - - std::string pointStr = content.substr(nPosLeft + 1, nPosRight - nPosLeft - 1); - // nothing between '{' and '}' - CC_BREAK_IF(pointStr.length() == 0); - - int nPos1 = pointStr.find('{'); - int nPos2 = pointStr.find('}'); - // contain '{' or '}' - CC_BREAK_IF(nPos1 != (int)std::string::npos || nPos2 != (int)std::string::npos); - - split(pointStr, ",", strs); - if (strs.size() != 2 || strs[0].length() == 0 || strs[1].length() == 0) - { - strs.clear(); - break; - } - - bRet = true; - } while (0); - - return bRet; -} - -// implement the functions - -Rect RectFromString(const char* pszContent) -{ - Rect result = Rect::ZERO; - - do - { - CC_BREAK_IF(!pszContent); - std::string content = pszContent; - - // find the first '{' and the third '}' - int nPosLeft = content.find('{'); - int nPosRight = content.find('}'); - for (int i = 1; i < 3; ++i) - { - if (nPosRight == (int)std::string::npos) - { - break; - } - nPosRight = content.find('}', nPosRight + 1); - } - CC_BREAK_IF(nPosLeft == (int)std::string::npos || nPosRight == (int)std::string::npos); - - content = content.substr(nPosLeft + 1, nPosRight - nPosLeft - 1); - int nPointEnd = content.find('}'); - CC_BREAK_IF(nPointEnd == (int)std::string::npos); - nPointEnd = content.find(',', nPointEnd); - CC_BREAK_IF(nPointEnd == (int)std::string::npos); - - // get the point string and size string - std::string pointStr = content.substr(0, nPointEnd); - std::string sizeStr = content.substr(nPointEnd + 1, content.length() - nPointEnd); - - // split the string with ',' - strArray pointInfo; - CC_BREAK_IF(!splitWithForm(pointStr.c_str(), pointInfo)); - strArray sizeInfo; - CC_BREAK_IF(!splitWithForm(sizeStr.c_str(), sizeInfo)); - - float x = (float) atof(pointInfo[0].c_str()); - float y = (float) atof(pointInfo[1].c_str()); - float width = (float) atof(sizeInfo[0].c_str()); - float height = (float) atof(sizeInfo[1].c_str()); - - result = Rect(x, y, width, height); - } while (0); - - return result; -} - -Point PointFromString(const char* pszContent) -{ - Point ret = Point::ZERO; - - do - { - strArray strs; - CC_BREAK_IF(!splitWithForm(pszContent, strs)); - - float x = (float) atof(strs[0].c_str()); - float y = (float) atof(strs[1].c_str()); - - ret = Point(x, y); - } while (0); - - return ret; -} - -Size SizeFromString(const char* pszContent) -{ - Size ret = Size::ZERO; - - do - { - strArray strs; - CC_BREAK_IF(!splitWithForm(pszContent, strs)); - - float width = (float) atof(strs[0].c_str()); - float height = (float) atof(strs[1].c_str()); - - ret = Size(width, height); - } while (0); - - return ret; -} - -NS_CC_END diff --git a/cocos/platform/cocoa/CCNS.h b/cocos/platform/cocoa/CCNS.h deleted file mode 100644 index 8ce8e1dde6..0000000000 --- a/cocos/platform/cocoa/CCNS.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __PLATFOMR_CCNS_H__ -#define __PLATFOMR_CCNS_H__ - -#include "CCGeometry.h" - -NS_CC_BEGIN - -/** - * @addtogroup data_structures - * @{ - */ - -/** -@brief Returns a Core Graphics rectangle structure corresponding to the data in a given string. -@param pszContent A string object whose contents are of the form "{{x,y},{w, h}}", - where x is the x coordinate, y is the y coordinate, w is the width, and h is the height. - These components can represent integer or float values. - An example of a valid string is "{{3,2},{4,5}}". - The string is not localized, so items are always separated with a comma. -@return A Core Graphics structure that represents a rectangle. - If the string is not well-formed, the function returns Rect::ZERO. -*/ -Rect CC_DLL RectFromString(const char* pszContent); - -/** -@brief Returns a Core Graphics point structure corresponding to the data in a given string. -@param pszContent A string object whose contents are of the form "{x,y}", - where x is the x coordinate and y is the y coordinate. - The x and y values can represent integer or float values. - An example of a valid string is "{3.0,2.5}". - The string is not localized, so items are always separated with a comma. -@return A Core Graphics structure that represents a point. - If the string is not well-formed, the function returns Point::ZERO. -*/ -Point CC_DLL PointFromString(const char* pszContent); - -/** -@brief Returns a Core Graphics size structure corresponding to the data in a given string. -@param pszContent A string object whose contents are of the form "{w, h}", - where w is the width and h is the height. - The w and h values can be integer or float values. - An example of a valid string is "{3.0,2.5}". - The string is not localized, so items are always separated with a comma. -@return A Core Graphics structure that represents a size. - If the string is not well-formed, the function returns Size::ZERO. -*/ -Size CC_DLL SizeFromString(const char* pszContent); - -// end of data_structure group -/// @} - -NS_CC_END - -#endif // __PLATFOMR_CCNS_H__ - - diff --git a/cocos/platform/cocoa/CCObject.cpp b/cocos/platform/cocoa/CCObject.cpp deleted file mode 100644 index 13fa0e3236..0000000000 --- a/cocos/platform/cocoa/CCObject.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - - -#include "CCObject.h" -#include "CCAutoreleasePool.h" -#include "ccMacros.h" -#include "script_support/CCScriptSupport.h" - -NS_CC_BEGIN - -Object::Object() -: _luaID(0) -, _reference(1) // when the object is created, the reference count of it is 1 -, _autoReleaseCount(0) -{ - static unsigned int uObjectCount = 0; - - _ID = ++uObjectCount; -} - -Object::~Object() -{ - // if the object is managed, we should remove it - // from pool manager - if (_autoReleaseCount > 0) - { - PoolManager::sharedPoolManager()->removeObject(this); - } - - // if the object is referenced by Lua engine, remove it - if (_luaID) - { - ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptObjectByObject(this); - } - else - { - ScriptEngineProtocol* pEngine = ScriptEngineManager::getInstance()->getScriptEngine(); - if (pEngine != NULL && pEngine->getScriptType() == kScriptTypeJavascript) - { - pEngine->removeScriptObjectByObject(this); - } - } -} - -Object* Object::autorelease() -{ - PoolManager::sharedPoolManager()->addObject(this); - return this; -} - -bool Object::isSingleReference() const -{ - return _reference == 1; -} - -unsigned int Object::retainCount() const -{ - return _reference; -} - -bool Object::isEqual(const Object *object) -{ - return this == object; -} - -void Object::acceptVisitor(DataVisitor &visitor) -{ - visitor.visitObject(this); -} - -NS_CC_END diff --git a/cocos/platform/cocoa/CCObject.h b/cocos/platform/cocoa/CCObject.h deleted file mode 100644 index 8de1ff9d8b..0000000000 --- a/cocos/platform/cocoa/CCObject.h +++ /dev/null @@ -1,216 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __CCOBJECT_H__ -#define __CCOBJECT_H__ - -#include "cocoa/CCDataVisitor.h" -#include "ccMacros.h" - -#ifdef EMSCRIPTEN -#include -#endif // EMSCRIPTEN - -NS_CC_BEGIN - -/** - * @addtogroup base_nodes - * @{ - */ - -class Object; -class Node; - -/** Interface that defines how to clone an object */ -class CC_DLL Clonable -{ -public: - /** returns a copy of the object */ - virtual Clonable* clone() const = 0; - /** - * @js NA - * @lua NA - */ - virtual ~Clonable() {}; - - /** returns a copy of the object. - @deprecated Use clone() instead - */ - CC_DEPRECATED_ATTRIBUTE Object* copy() const - { - // use "clone" instead - CC_ASSERT(false); - return nullptr; - } -}; - -class CC_DLL Object -{ -public: - /// object id, ScriptSupport need public _ID - unsigned int _ID; - /// Lua reference id - int _luaID; -protected: - /// count of references - unsigned int _reference; - /// count of autorelease - unsigned int _autoReleaseCount; -public: - /** - * Constructor - * - * The object's reference count is 1 after construction. - * @js NA - */ - Object(); - - /** - * @js NA - * @lua NA - */ - virtual ~Object(); - - /** - * Release the ownership immediately. - * - * This decrements the object's reference count. - * - * If the reference count reaches 0 after the descrement, this object is - * destructed. - * - * @see retain, autorelease - * @js NA - */ - inline void release() - { - CCASSERT(_reference > 0, "reference count should greater than 0"); - --_reference; - - if (_reference == 0) - delete this; - } - - /** - * Retains the ownership. - * - * This increases the object's reference count. - * - * @see release, autorelease - * @js NA - */ - inline void retain() - { - CCASSERT(_reference > 0, "reference count should greater than 0"); - ++_reference; - } - - /** - * Release the ownership sometime soon automatically. - * - * This descrements the object's reference count at the end of current - * autorelease pool block. - * - * If the reference count reaches 0 after the descrement, this object is - * destructed. - * - * @returns The object itself. - * - * @see AutoreleasePool, retain, release - * @js NA - * @lua NA - */ - Object* autorelease(); - - /** - * Returns a boolean value that indicates whether there is only one - * reference to the object. That is, whether the reference count is 1. - * - * @returns Whether the object's reference count is 1. - * @js NA - */ - bool isSingleReference() const; - - /** - * Returns the object's current reference count. - * - * @returns The object's reference count. - * @js NA - */ - unsigned int retainCount() const; - - /** - * Returns a boolean value that indicates whether this object and a given - * object are equal. - * - * @param object The object to be compared to this object. - * - * @returns True if this object and @p object are equal, otherwise false. - * @js NA - * @lua NA - */ - virtual bool isEqual(const Object* object); - /** - * @js NA - * @lua NA - */ - virtual void acceptVisitor(DataVisitor &visitor); - /** - * @js NA - * @lua NA - */ - virtual void update(float dt) {CC_UNUSED_PARAM(dt);}; - - friend class AutoreleasePool; -}; - - -typedef void (Object::*SEL_SCHEDULE)(float); -typedef void (Object::*SEL_CallFunc)(); -typedef void (Object::*SEL_CallFuncN)(Node*); -typedef void (Object::*SEL_CallFuncND)(Node*, void*); -typedef void (Object::*SEL_CallFuncO)(Object*); -typedef void (Object::*SEL_MenuHandler)(Object*); -typedef int (Object::*SEL_Compare)(Object*); - -#define schedule_selector(_SELECTOR) static_cast(&_SELECTOR) -#define callfunc_selector(_SELECTOR) static_cast(&_SELECTOR) -#define callfuncN_selector(_SELECTOR) static_cast(&_SELECTOR) -#define callfuncND_selector(_SELECTOR) static_cast(&_SELECTOR) -#define callfuncO_selector(_SELECTOR) static_cast(&_SELECTOR) -#define menu_selector(_SELECTOR) static_cast(&_SELECTOR) -#define event_selector(_SELECTOR) static_cast(&_SELECTOR) -#define compare_selector(_SELECTOR) static_cast(&_SELECTOR) - -// new callbacks based on C++11 -#define CC_CALLBACK_0(__selector__,__target__, ...) std::bind(&__selector__,__target__, ##__VA_ARGS__) -#define CC_CALLBACK_1(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, ##__VA_ARGS__) -#define CC_CALLBACK_2(__selector__,__target__, ...) std::bind(&__selector__,__target__, std::placeholders::_1, std::placeholders::_2, ##__VA_ARGS__) - -// end of base_nodes group -/// @} - -NS_CC_END - -#endif // __CCOBJECT_H__ diff --git a/cocos/platform/cocoa/CCSet.cpp b/cocos/platform/cocoa/CCSet.cpp deleted file mode 100644 index c3c24e0e5e..0000000000 --- a/cocos/platform/cocoa/CCSet.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "CCSet.h" - -using namespace std; - -NS_CC_BEGIN - -Set::Set(void) -{ - _set = new set; -} - -Set::Set(const Set &rSetObject) -{ - _set = new set(*rSetObject._set); - - // call retain of members - SetIterator iter; - for (iter = _set->begin(); iter != _set->end(); ++iter) - { - if (! (*iter)) - { - break; - } - - (*iter)->retain(); - } -} - -Set::~Set(void) -{ - removeAllObjects(); - CC_SAFE_DELETE(_set); -} - -void Set::acceptVisitor(DataVisitor &visitor) -{ - visitor.visit(this); -} - -Set * Set::create() -{ - Set * pRet = new Set(); - - if (pRet != NULL) - { - pRet->autorelease(); - } - - return pRet; -} - -Set* Set::copy(void) -{ - Set *pSet = new Set(*this); - - return pSet; -} - -Set* Set::mutableCopy(void) -{ - return copy(); -} - -int Set::count(void) -{ - return (int)_set->size(); -} - -void Set::addObject(Object *pObject) -{ - if (_set->count(pObject) == 0) - { - CC_SAFE_RETAIN(pObject); - _set->insert(pObject); - } -} - -void Set::removeObject(Object *pObject) -{ - if (_set->erase(pObject) > 0) - { - CC_SAFE_RELEASE(pObject); - } -} - -void Set::removeAllObjects() -{ - SetIterator it = _set->begin(); - SetIterator tmp; - - while (it != _set->end()) - { - if (!(*it)) - { - break; - } - - tmp = it; - ++tmp; - Object * obj = *it; - _set->erase(it); - CC_SAFE_RELEASE(obj); - it = tmp; - } -} - -bool Set::containsObject(Object *pObject) -{ - return _set->find(pObject) != _set->end(); -} - -SetIterator Set::begin(void) -{ - return _set->begin(); -} - -SetIterator Set::end(void) -{ - return _set->end(); -} - -Object* Set::anyObject() -{ - if (!_set || _set->empty()) - { - return 0; - } - - SetIterator it; - - for( it = _set->begin(); it != _set->end(); ++it) - { - if (*it) - { - return (*it); - } - } - - return 0; -} - -NS_CC_END diff --git a/cocos/platform/cocoa/CCSet.h b/cocos/platform/cocoa/CCSet.h deleted file mode 100644 index c748f0ada5..0000000000 --- a/cocos/platform/cocoa/CCSet.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010-2012 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __CC_SET_H__ -#define __CC_SET_H__ - -#include -#include "CCObject.h" - -NS_CC_BEGIN - -/** - * @addtogroup data_structures - * @{ - */ - -typedef std::set::iterator SetIterator; - -class CC_DLL Set : public Object -{ -public: - /** - * @js ctor - */ - Set(void); - Set(const Set &rSetObject); - /** - * @js NA - * @lua NA - */ - virtual ~Set(void); - - /** - * @brief Create and return a new empty set. - */ - static Set * create(); - - /** - *@brief Return a copy of the Set, it will copy all the elements. - */ - Set* copy(); - /** - *@brief It is the same as copy(). - */ - Set* mutableCopy(); - /** - *@brief Return the number of elements the Set contains. - */ - int count(); - /** - *@brief Add a element into Set, it will retain the element. - */ - void addObject(Object *pObject); - /** - *@brief Remove the given element, nothing todo if no element equals pObject. - */ - void removeObject(Object *pObject); - /** - *@brief Remove all elements of the set - */ - void removeAllObjects(); - /** - *@brief Check if Set contains a element equals pObject. - */ - bool containsObject(Object *pObject); - /** - *@brief Return the iterator that points to the first element. - * @js NA - * @lua NA - */ - SetIterator begin(); - /** - *@brief Return the iterator that points to the position after the last element. - * @js NA - * @lua NA - */ - SetIterator end(); - /** - *@brief Return the first element if it contains elements, or null if it doesn't contain any element. - */ - Object* anyObject(); - /** - * @js NA - * @lua NA - */ - virtual void acceptVisitor(DataVisitor &visitor); - -private: - std::set *_set; -}; - -// end of data_structure group -/// @} - -NS_CC_END - -#endif // __CC_SET_H__ - diff --git a/cocos/platform/cocoa/CCString.cpp b/cocos/platform/cocoa/CCString.cpp deleted file mode 100644 index f9962b1ba4..0000000000 --- a/cocos/platform/cocoa/CCString.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2012 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#include "CCString.h" -#include "platform/CCFileUtils.h" -#include "ccMacros.h" -#include -#include -#include "CCArray.h" - -NS_CC_BEGIN - -#define kMaxStringLen (1024*100) - -String::String() - :_string("") -{} - -String::String(const char * str) - :_string(str) -{} - -String::String(const std::string& str) - :_string(str) -{} - -String::String(const String& str) - :_string(str.getCString()) -{} - -String::~String() -{ - CCLOGINFO("deallocing String: %p", this); - - _string.clear(); -} - -String& String::operator= (const String& other) -{ - _string = other._string; - return *this; -} - -bool String::initWithFormatAndValist(const char* format, va_list ap) -{ - bool bRet = false; - char* pBuf = (char*)malloc(kMaxStringLen); - if (pBuf != NULL) - { - vsnprintf(pBuf, kMaxStringLen, format, ap); - _string = pBuf; - free(pBuf); - bRet = true; - } - return bRet; -} - -bool String::initWithFormat(const char* format, ...) -{ - bool bRet = false; - _string.clear(); - - va_list ap; - va_start(ap, format); - - bRet = initWithFormatAndValist(format, ap); - - va_end(ap); - - return bRet; -} - -int String::intValue() const -{ - if (length() == 0) - { - return 0; - } - return atoi(_string.c_str()); -} - -unsigned int String::uintValue() const -{ - if (length() == 0) - { - return 0; - } - return (unsigned int)atoi(_string.c_str()); -} - -float String::floatValue() const -{ - if (length() == 0) - { - return 0.0f; - } - return (float)atof(_string.c_str()); -} - -double String::doubleValue() const -{ - if (length() == 0) - { - return 0.0; - } - return atof(_string.c_str()); -} - -bool String::boolValue() const -{ - if (length() == 0) - { - return false; - } - - if (0 == strcmp(_string.c_str(), "0") || 0 == strcmp(_string.c_str(), "false")) - { - return false; - } - return true; -} - -const char* String::getCString() const -{ - return _string.c_str(); -} - -unsigned int String::length() const -{ - return _string.length(); -} - -int String::compare(const char * pStr) const -{ - return strcmp(getCString(), pStr); -} - -void String::append(const std::string& str) -{ - _string.append(str); -} - -void String::appendWithFormat(const char* format, ...) -{ - va_list ap; - va_start(ap, format); - - char* pBuf = (char*)malloc(kMaxStringLen); - if (pBuf != NULL) - { - vsnprintf(pBuf, kMaxStringLen, format, ap); - _string.append(pBuf); - free(pBuf); - } - - va_end(ap); - -} - -Array* String::componentsSeparatedByString(const char *delimiter) -{ - Array* result = Array::create(); - - int cutAt; - while( (cutAt = _string.find_first_of(delimiter)) != _string.npos ) - { - if(cutAt > 0) - { - result->addObject(String::create(_string.substr(0, cutAt))); - } - _string = _string.substr(cutAt + 1); - } - - if(_string.length() > 0) - { - result->addObject(String::create(_string)); - } - - return result; -} - -bool String::isEqual(const Object* pObject) -{ - bool bRet = false; - const String* pStr = dynamic_cast(pObject); - if (pStr != NULL) - { - if (0 == _string.compare(pStr->_string)) - { - bRet = true; - } - } - return bRet; -} - -String* String::create(const std::string& str) -{ - String* pRet = new String(str); - pRet->autorelease(); - return pRet; -} - -String* String::createWithData(const unsigned char* pData, unsigned long nLen) -{ - String* pRet = NULL; - if (pData != NULL) - { - char* pStr = (char*)malloc(nLen+1); - if (pStr != NULL) - { - pStr[nLen] = '\0'; - if (nLen > 0) - { - memcpy(pStr, pData, nLen); - } - - pRet = String::create(pStr); - free(pStr); - } - } - return pRet; -} - -String* String::createWithFormat(const char* format, ...) -{ - String* pRet = String::create(""); - va_list ap; - va_start(ap, format); - pRet->initWithFormatAndValist(format, ap); - va_end(ap); - - return pRet; -} - -String* String::createWithContentsOfFile(const char* filename) -{ - unsigned long size = 0; - unsigned char* pData = 0; - String* pRet = NULL; - pData = FileUtils::getInstance()->getFileData(filename, "rb", &size); - pRet = String::createWithData(pData, size); - CC_SAFE_DELETE_ARRAY(pData); - return pRet; -} - -void String::acceptVisitor(DataVisitor &visitor) -{ - visitor.visit(this); -} - -String* String::clone() const -{ - return String::create(_string); -} - -NS_CC_END diff --git a/cocos/platform/cocoa/CCString.h b/cocos/platform/cocoa/CCString.h deleted file mode 100644 index a6f237a476..0000000000 --- a/cocos/platform/cocoa/CCString.h +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -http://www.cocos2d-x.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ -#ifndef __CCSTRING_H__ -#define __CCSTRING_H__ - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY) -#include -#endif - -#include -#include -#include -#include "CCObject.h" - -NS_CC_BEGIN - -/** - * @addtogroup data_structures - * @{ - */ - -class CC_DLL String : public Object, public Clonable -{ -public: - /** - * @js NA - * @lua NA - */ - String(); - /** - * @js NA - * @lua NA - */ - String(const char* str); - /** - * @js NA - * @lua NA - */ - String(const std::string& str); - /** - * @js NA - * @lua NA - */ - String(const String& str); - /** - * @js NA - * @lua NA - */ - virtual ~String(); - - /* override assignment operator - * @js NA - * @lua NA - */ - String& operator= (const String& other); - - /** init a string with format, it's similar with the c function 'sprintf' - * @js NA - * @lua NA - */ - bool initWithFormat(const char* format, ...) CC_FORMAT_PRINTF(2, 3); - - /** convert to int value - * @js NA - */ - int intValue() const; - - /** convert to unsigned int value - * @js NA - */ - unsigned int uintValue() const; - - /** convert to float value - * @js NA - */ - float floatValue() const; - - /** convert to double value - * @js NA - */ - double doubleValue() const; - - /** convert to bool value - * @js NA - */ - bool boolValue() const; - - /** get the C string - * @js NA - */ - const char* getCString() const; - - /** get the length of string - * @js NA - */ - unsigned int length() const; - - /** compare to a c string - * @js NA - */ - int compare(const char *) const; - - /** append additional characters at the end of its current value - * @js NA - * @lua NA - */ - void append(const std::string& str); - - /** append(w/ format) additional characters at the end of its current value - * @js NA - * @lua NA - */ - void appendWithFormat(const char* format, ...); - - /** split a string - * @js NA - * @lua NA - */ - Array* componentsSeparatedByString(const char *delimiter); - - /* override functions - * @js NA - */ - virtual bool isEqual(const Object* pObject); - - /** create a string with std string, you can also pass a c string pointer because the default constructor of std::string can access a c string pointer. - * @return A String pointer which is an autorelease object pointer, - * it means that you needn't do a release operation unless you retain it. - * @js NA - */ - static String* create(const std::string& str); - - /** create a string with format, it's similar with the c function 'sprintf', the default buffer size is (1024*100) bytes, - * if you want to change it, you should modify the kMaxStringLen macro in String.cpp file. - * @return A String pointer which is an autorelease object pointer, - * it means that you needn't do a release operation unless you retain it. - * @js NA - */ - static String* createWithFormat(const char* format, ...) CC_FORMAT_PRINTF(1, 2); - - /** create a string with binary data - * @return A String pointer which is an autorelease object pointer, - * it means that you needn't do a release operation unless you retain it. - * @js NA - */ - static String* createWithData(const unsigned char* pData, unsigned long nLen); - - /** create a string with a file, - * @return A String pointer which is an autorelease object pointer, - * it means that you needn't do a release operation unless you retain it. - * @js NA - */ - static String* createWithContentsOfFile(const char* filename); - /** - * @js NA - * @lua NA - */ - virtual void acceptVisitor(DataVisitor &visitor); - /** - * @js NA - * @lua NA - */ - virtual String* clone() const; - -private: - - /** only for internal use */ - bool initWithFormatAndValist(const char* format, va_list ap); - -public: - std::string _string; -}; - -struct StringCompare : public std::binary_function { - public: - bool operator() (String * a, String * b) const { - return strcmp(a->getCString(), b->getCString()) < 0; - } -}; - -#define StringMake(str) String::create(str) -#define ccs StringMake - -// end of data_structure group -/// @} - -NS_CC_END - -#endif //__CCSTRING_H__