diff --git a/README.md b/README.md index 742c41e77..f62aa68ee 100644 --- a/README.md +++ b/README.md @@ -614,8 +614,6 @@ Probably deprecate the Maps module, since I will focus my efforts on the UI syst * Jason Perkins for [premake](https://premake.github.io/) -* Daniel Bahr for [CRC++](https://github.com/d-bahr/CRCpp) - * Martín Lucas Golini ( me ) and all the several contributors for [SOIL2](https://github.com/SpartanJ/SOIL2) and [efsw](https://github.com/SpartanJ/efsw) * The Xiph open source community for [libogg](https://xiph.org/ogg/) and [libvorbis](https://xiph.org/vorbis/) diff --git a/include/eepp/core/string.hpp b/include/eepp/core/string.hpp index 07dfd44ce..7b53110b8 100644 --- a/include/eepp/core/string.hpp +++ b/include/eepp/core/string.hpp @@ -46,7 +46,7 @@ namespace EE { /** Utility string class that automatically handles conversions between types and encodings **/ class EE_API String { public: - typedef Uint32 StringBaseType; + typedef char32_t StringBaseType; typedef std::basic_string StringType; typedef StringType::iterator Iterator; //! Iterator type typedef StringType::const_iterator ConstIterator; //! Constant iterator type @@ -57,10 +57,10 @@ class EE_API String { static const std::size_t InvalidPos; ///< Represents an invalid position in the string /** @return string hash */ - static constexpr Uint32 hash( const Uint8* str ); + static constexpr HashType hash( const Uint8* str ); /** @return string hash */ - static constexpr Uint32 hash( const char* str ) { + static constexpr HashType hash( const char* str ) { //! djb2 if ( NULL != str ) { Uint32 hash = 5381; @@ -76,11 +76,11 @@ class EE_API String { } /** @return string hash */ - static Uint32 hash( const std::string& str ); + static String::HashType hash( const std::string& str ); /** @return string hash. Note: String::hash( std::string( "text" ) ) is != to String::hash( * String( "text" ) ) */ - static Uint32 hash( const String& str ); + static String::HashType hash( const String& str ); /** @return If the value passed is a character */ static bool isCharacter( const int& value ); @@ -306,6 +306,11 @@ class EE_API String { **/ String( const char* utf8String ); + /** @brief Construct from an from a sub-string C-style UTF-8 string to UTF-32 + ** @param uf8String UTF-8 string to convert + **/ + String( const char* utf8String, const size_t& utf8StringSize ); + /** @brief Construct from an UTF-8 string to UTF-32 according ** @param utf8String UTF-8 string to convert **/ @@ -431,7 +436,7 @@ class EE_API String { std::basic_string toUtf16() const; /** @return The hash code of the String */ - Uint32 getHash() const; + HashType getHash() const; /** @brief Overload of assignment operator ** @param right Instance to assign diff --git a/include/eepp/graphics/drawableresource.hpp b/include/eepp/graphics/drawableresource.hpp index 70deec03f..ed4c690fa 100644 --- a/include/eepp/graphics/drawableresource.hpp +++ b/include/eepp/graphics/drawableresource.hpp @@ -15,7 +15,7 @@ class EE_API DrawableResource : public Drawable { typedef std::function OnResourceChangeCallback; /** @return The DrawableResource Id. The Id is the String::hash of the name. */ - const Uint32& getId() const; + const String::HashType& getId() const; /** @return The DrawableResource Name. */ const std::string getName() const; @@ -36,7 +36,7 @@ class EE_API DrawableResource : public Drawable { protected: std::string mName; - Uint32 mId; + String::HashType mId; Uint32 mNumCallBacks; std::map mCallbacks; diff --git a/include/eepp/graphics/font.hpp b/include/eepp/graphics/font.hpp index d3d44b490..4c6df1d8c 100644 --- a/include/eepp/graphics/font.hpp +++ b/include/eepp/graphics/font.hpp @@ -65,7 +65,7 @@ class EE_API Font { void setName( const std::string& setName ); /** @return The font id */ - const Uint32& getId(); + const String::HashType& getId(); virtual const Info& getInfo() const = 0; @@ -95,7 +95,7 @@ class EE_API Font { protected: FontType mType; std::string mFontName; - Uint32 mFontHash; + String::HashType mFontHash; Uint32 mNumCallBacks; std::map mCallbacks; diff --git a/include/eepp/graphics/framebuffer.hpp b/include/eepp/graphics/framebuffer.hpp index 73d267de1..b3eda89e5 100644 --- a/include/eepp/graphics/framebuffer.hpp +++ b/include/eepp/graphics/framebuffer.hpp @@ -102,7 +102,7 @@ class EE_API FrameBuffer { void setName( const std::string& name ); /** @return The hash id from its name */ - const Uint32& getId() const; + const String::HashType& getId() const; /** @return If the frame buffer was created */ virtual bool created() const = 0; @@ -112,7 +112,7 @@ class EE_API FrameBuffer { Sizei mSize; Uint32 mChannels; std::string mName; - Uint32 mId; + String::HashType mId; bool mHasColorBuffer; bool mHasDepthBuffer; bool mHasStencilBuffer; diff --git a/include/eepp/graphics/framebuffermanager.hpp b/include/eepp/graphics/framebuffermanager.hpp index cd87dfbb4..e57b7eb8b 100644 --- a/include/eepp/graphics/framebuffermanager.hpp +++ b/include/eepp/graphics/framebuffermanager.hpp @@ -22,7 +22,7 @@ class EE_API FrameBufferManager : public Container { FrameBuffer* getFromName( const std::string& name ); - FrameBuffer* getFromId( const Uint32& id ); + FrameBuffer* getFromId( const String::HashType& id ); protected: FrameBufferManager(); diff --git a/include/eepp/graphics/shaderprogram.hpp b/include/eepp/graphics/shaderprogram.hpp index ee4ef7360..3e0127752 100644 --- a/include/eepp/graphics/shaderprogram.hpp +++ b/include/eepp/graphics/shaderprogram.hpp @@ -117,7 +117,7 @@ class EE_API ShaderProgram { const Uint32& getHandler() const { return mHandler; } /** @return The Id of the program ( hash of the program name ) */ - const Uint32& getId() const { return mId; } + const String::HashType& getId() const { return mId; } /** Reloads the shaders */ void reload(); @@ -146,7 +146,7 @@ class EE_API ShaderProgram { protected: std::string mName; Uint32 mHandler; - Uint32 mId; + String::HashType mId; bool mValid; std::string mLinkLog; diff --git a/include/eepp/graphics/texture.hpp b/include/eepp/graphics/texture.hpp index 8be1b45ff..eb3853d8b 100644 --- a/include/eepp/graphics/texture.hpp +++ b/include/eepp/graphics/texture.hpp @@ -35,7 +35,7 @@ class EE_API Texture : public DrawableResource, public Image, private NonCopyabl int getHandle() const { return mTexture; } /** @return The hash of the filename */ - const Uint32& getHashName() const; + const String::HashType& getHashName() const; /** Set the Texture File Path */ void setFilepath( const std::string& filepath ) { mFilepath = filepath; } diff --git a/include/eepp/graphics/textureatlas.hpp b/include/eepp/graphics/textureatlas.hpp index 5384f9898..6565b0cd7 100644 --- a/include/eepp/graphics/textureatlas.hpp +++ b/include/eepp/graphics/textureatlas.hpp @@ -71,7 +71,7 @@ class EE_API TextureAtlas : public ResourceManager { void setPath( const std::string& path ); /** @return The texture atlas Id. The Id is the String::hash of the texture atlas name. */ - const Uint32& getId() const; + const String::HashType& getId() const; /** @return The number of TextureRegions inside the texture atlas. */ Uint32 getCount(); @@ -94,7 +94,7 @@ class EE_API TextureAtlas : public ResourceManager { friend class TextureAtlasLoader; std::string mName; - Uint32 mId; + String::HashType mId; std::string mPath; std::vector mTextures; diff --git a/include/eepp/graphics/textureatlasmanager.hpp b/include/eepp/graphics/textureatlasmanager.hpp index 854ba7fde..5bde3f938 100644 --- a/include/eepp/graphics/textureatlasmanager.hpp +++ b/include/eepp/graphics/textureatlasmanager.hpp @@ -40,7 +40,7 @@ class EE_API TextureAtlasManager : public ResourceManagerMulti { /** It will search for a TextureRegion Id in the texture atlases loaded. * @return The first TextureRegion found with the given id in any atlas. */ - TextureRegion* getTextureRegionById( const Uint32& Id ); + TextureRegion* getTextureRegionById( const String::HashType& Id ); /** Search for a pattern name * For example search for name "car" with extensions "png", i will try to find car00.png diff --git a/include/eepp/graphics/texturefactory.hpp b/include/eepp/graphics/texturefactory.hpp index 0dfc3a43a..0067f4ab9 100644 --- a/include/eepp/graphics/texturefactory.hpp +++ b/include/eepp/graphics/texturefactory.hpp @@ -243,7 +243,7 @@ class EE_API TextureFactory : protected Mutex { * @param Hash The file path hash * @return The texture, NULL if not exists */ - Texture* getByHash( const Uint32& Hash ); + Texture* getByHash( const String::HashType& hash ); ~TextureFactory(); diff --git a/include/eepp/maps/mapeditor/mapeditor.hpp b/include/eepp/maps/mapeditor/mapeditor.hpp index 3d691ca48..24903b7fe 100644 --- a/include/eepp/maps/mapeditor/mapeditor.hpp +++ b/include/eepp/maps/mapeditor/mapeditor.hpp @@ -199,7 +199,7 @@ class EE_API MapEditor { void onObjectModeSel( const Event* Event ); - void onNewGOTypeAdded( std::string name, Uint32 hash ); + void onNewGOTypeAdded( std::string name, String::HashType hash ); void onAddObject( Uint32 Type, Polygon2f poly ); @@ -251,7 +251,7 @@ class EE_API MapEditor { void updateScroll(); - bool addShortcut( const Uint32& KeyCode, const Uint32& Mod, UIWidget* Widget ); + bool addShortcut( const Keycode& KeyCode, const Uint32& Mod, UIWidget* Widget ); }; }} // namespace EE::Maps diff --git a/include/eepp/maps/maplayer.hpp b/include/eepp/maps/maplayer.hpp index 1a5597835..2b7c06bb1 100644 --- a/include/eepp/maps/maplayer.hpp +++ b/include/eepp/maps/maplayer.hpp @@ -37,7 +37,7 @@ class EE_API MapLayer { const std::string& getName() const; - const Uint32& getId() const; + const String::HashType& getId() const; void addProperty( std::string Text, std::string Value ); @@ -64,7 +64,7 @@ class EE_API MapLayer { Uint32 mType; Uint32 mFlags; Vector2f mOffset; - Uint32 mNameHash; + String::HashType mNameHash; std::string mName; PropertiesMap mProperties; diff --git a/include/eepp/maps/tilemap.hpp b/include/eepp/maps/tilemap.hpp index 3e3fbaffd..e2dbf9755 100644 --- a/include/eepp/maps/tilemap.hpp +++ b/include/eepp/maps/tilemap.hpp @@ -48,7 +48,7 @@ class EE_API TileMap { virtual Uint32 getLayerIndex( MapLayer* Layer ); - virtual MapLayer* getLayerByHash( Uint32 hash ); + virtual MapLayer* getLayerByHash( String::HashType hash ); virtual MapLayer* getLayer( const std::string& name ); diff --git a/include/eepp/network/http.hpp b/include/eepp/network/http.hpp index 8634592a1..382f00ce6 100644 --- a/include/eepp/network/http.hpp +++ b/include/eepp/network/http.hpp @@ -584,7 +584,7 @@ class EE_API Http : NonCopyable { static std::string getHostKey( const URI& host, const URI& proxy ); - static Uint32 getHostHash( const URI& host, const URI& proxy ); + static String::HashType getHostHash( const URI& host, const URI& proxy ); }; /** Creates an HTTP Request using the global HTTP Client Pool */ diff --git a/include/eepp/scene/eventdispatcher.hpp b/include/eepp/scene/eventdispatcher.hpp index fb7492e29..ec82704d2 100644 --- a/include/eepp/scene/eventdispatcher.hpp +++ b/include/eepp/scene/eventdispatcher.hpp @@ -2,12 +2,14 @@ #define EE_EVENTDISPATCHER_HPP #include -#include -using namespace EE::System; #include -using namespace EE::Math; +#include +#include #include +using namespace EE::System; +using namespace EE::Math; + namespace EE { namespace Window { class Input; class InputEvent; @@ -48,9 +50,9 @@ class EE_API EventDispatcher { void sendTextInput( const Uint32& textChar, const Uint32& timestamp ); - void sendKeyUp( const Uint32& KeyCode, const Uint32& Char, const Uint32& Mod ); + void sendKeyUp( const Keycode& KeyCode, const Uint32& Char, const Uint32& Mod ); - void sendKeyDown( const Uint32& KeyCode, const Uint32& Char, const Uint32& Mod ); + void sendKeyDown( const Keycode& KeyCode, const Uint32& Char, const Uint32& Mod ); void sendMouseClick( Node* ToCtrl, const Vector2i& Pos, const Uint32 Flags ); diff --git a/include/eepp/scene/keyevent.hpp b/include/eepp/scene/keyevent.hpp index a7bbd0b21..a84f8b168 100644 --- a/include/eepp/scene/keyevent.hpp +++ b/include/eepp/scene/keyevent.hpp @@ -3,25 +3,28 @@ #include #include +#include + +using namespace EE::Window; namespace EE { namespace Scene { class EE_API KeyEvent : public Event { public: - KeyEvent( Node* node, const Uint32& eventNum, const Uint32& keyCode, const Uint32& chr, + KeyEvent( Node* node, const Uint32& eventNum, const Keycode& keyCode, const Uint32& chr, const Uint32& mod ); ~KeyEvent(); - const Uint32& getKeyCode() const; + const Keycode& getKeyCode() const; - const Uint32& getChar() const; + const String::StringBaseType& getChar() const; const Uint32& getMod() const; protected: - Uint32 mKeyCode; - Uint32 mChar; + Keycode mKeyCode; + String::StringBaseType mChar; Uint32 mMod; }; @@ -30,14 +33,14 @@ class EE_API TextInputEvent : public Event { TextInputEvent( Node* node, const Uint32& eventNum, const Uint32& chr, const Uint32& timestamp ); - const Uint32& getChar() const; + const String::StringBaseType& getChar() const; const Uint32& getTimestamp() const; String getText() const; protected: - Uint32 mChar; + String::StringBaseType mChar; Uint32 mTimestamp; }; diff --git a/include/eepp/scene/node.hpp b/include/eepp/scene/node.hpp index cad025ff1..2d987ae1a 100644 --- a/include/eepp/scene/node.hpp +++ b/include/eepp/scene/node.hpp @@ -214,7 +214,7 @@ class EE_API Node : public Transformable { virtual Node* setId( const std::string& id ); - Uint32 getIdHash() const; + const String::HashType& getIdHash() const; Node* find( const std::string& id ) const; @@ -369,12 +369,13 @@ class EE_API Node : public Transformable { virtual void onIdChange(); bool isClosing() const; + protected: typedef std::map> EventsMap; friend class EventDispatcher; std::string mId; - Uint32 mIdHash; + String::HashType mIdHash; Vector2f mScreenPos; Vector2i mScreenPosi; Sizef mSize; @@ -499,7 +500,7 @@ class EE_API Node : public Transformable { Color getColor( const Color& Col ); - Node* findIdHash( const Uint32& idHash ) const; + Node* findIdHash( const String::HashType& idHash ) const; virtual void updateOriginPoint(); diff --git a/include/eepp/ui/css/animationdefinition.hpp b/include/eepp/ui/css/animationdefinition.hpp index d60d55aab..a1f867320 100644 --- a/include/eepp/ui/css/animationdefinition.hpp +++ b/include/eepp/ui/css/animationdefinition.hpp @@ -75,10 +75,10 @@ class EE_API AnimationDefinition { void setPaused( bool value ); - const Uint32& getId() const; + const String::HashType& getId() const; protected: - Uint32 mId; + String::HashType mId; std::string mName; Time mDelay = Time::Zero; Time mDuration = Time::Zero; diff --git a/include/eepp/ui/css/propertydefinition.hpp b/include/eepp/ui/css/propertydefinition.hpp index eab30e0cf..6a4c9bd7f 100644 --- a/include/eepp/ui/css/propertydefinition.hpp +++ b/include/eepp/ui/css/propertydefinition.hpp @@ -235,7 +235,7 @@ class EE_API PropertyDefinition { const std::string& getName() const; - const Uint32& getId() const; + const String::HashType& getId() const; PropertyId getPropertyId() const; @@ -267,7 +267,7 @@ class EE_API PropertyDefinition { protected: std::string mName; - Uint32 mId; + String::HashType mId; std::vector mAliases; std::vector mAliasesHash; std::string mDefaultValue; diff --git a/include/eepp/ui/css/propertyspecification.hpp b/include/eepp/ui/css/propertyspecification.hpp index e371ef603..1e14ac5ca 100644 --- a/include/eepp/ui/css/propertyspecification.hpp +++ b/include/eepp/ui/css/propertyspecification.hpp @@ -25,7 +25,7 @@ class EE_API PropertySpecification { const std::vector& properties, const std::string& shorthandParserName ); - const ShorthandDefinition* getShorthand( const Uint32& id ) const; + const ShorthandDefinition* getShorthand( const String::HashType& id ) const; const ShorthandDefinition* getShorthand( const std::string& name ) const; diff --git a/include/eepp/ui/css/shorthanddefinition.hpp b/include/eepp/ui/css/shorthanddefinition.hpp index 7bd0ece48..2246b02ea 100644 --- a/include/eepp/ui/css/shorthanddefinition.hpp +++ b/include/eepp/ui/css/shorthanddefinition.hpp @@ -42,17 +42,17 @@ class EE_API ShorthandDefinition { const std::string& getName() const; - const Uint32& getId() const; + const String::HashType& getId() const; ShorthandDefinition& addAlias( const std::string& alias ); bool isAlias( const std::string& alias ) const; - bool isAlias( const Uint32& id ) const; + bool isAlias( const String::HashType& id ) const; bool isDefinition( const std::string& name ) const; - bool isDefinition( const Uint32& id ) const; + bool isDefinition( const String::HashType& id ) const; ShorthandId getShorthandId() const; @@ -61,9 +61,9 @@ class EE_API ShorthandDefinition { protected: std::string mName; std::string mFuncName; - Uint32 mId; + String::HashType mId; std::vector mAliases; - std::vector mAliasesHash; + std::vector mAliasesHash; std::vector mProperties; }; diff --git a/include/eepp/ui/css/stylesheet.hpp b/include/eepp/ui/css/stylesheet.hpp index 5b98d4376..fb7946f16 100644 --- a/include/eepp/ui/css/stylesheet.hpp +++ b/include/eepp/ui/css/stylesheet.hpp @@ -43,7 +43,7 @@ class EE_API StyleSheet { const KeyframesDefinitionMap& getKeyframes() const; - static size_t NodeHash( const std::string& tag, const std::string& id ); + static size_t nodeHash( const std::string& tag, const std::string& id ); protected: std::vector> mNodes; diff --git a/include/eepp/ui/css/stylesheetproperty.hpp b/include/eepp/ui/css/stylesheetproperty.hpp index d7ac05a53..825599b37 100644 --- a/include/eepp/ui/css/stylesheetproperty.hpp +++ b/include/eepp/ui/css/stylesheetproperty.hpp @@ -49,7 +49,7 @@ class EE_API StyleSheetProperty { const std::string& getName() const; - const Uint32& getNameHash() const; + const String::HashType& getNameHash() const; const std::string& getValue() const; @@ -171,15 +171,15 @@ class EE_API StyleSheetProperty { Sizei asSizei( UINode* node, const Sizei& defaultValue = Sizei::Zero ) const; - const Uint32& getValueHash() const; + const String::HashType& getValueHash() const; const std::vector& getVarCache() const; protected: std::string mName; - Uint32 mNameHash; + String::HashType mNameHash; std::string mValue; - Uint32 mValueHash; + String::HashType mValueHash; Uint32 mSpecificity; Uint32 mIndex; bool mVolatile; diff --git a/include/eepp/ui/css/stylesheetpropertyanimation.hpp b/include/eepp/ui/css/stylesheetpropertyanimation.hpp index 148ca245c..caef4a928 100644 --- a/include/eepp/ui/css/stylesheetpropertyanimation.hpp +++ b/include/eepp/ui/css/stylesheetpropertyanimation.hpp @@ -20,7 +20,7 @@ enum class AnimationOrigin : uint8_t { User, Animation, Transition }; class EE_API StyleSheetPropertyAnimation : public Action { public: - static constexpr Uint32 ID = String::hash( "StyleSheetPropertyAnimation" ); + static constexpr String::HashType ID = String::hash( "StyleSheetPropertyAnimation" ); static void tweenProperty( UIWidget* widget, const Float& normalizedProgress, const PropertyDefinition* property, const std::string& startValue, diff --git a/include/eepp/ui/css/stylesheetvariable.hpp b/include/eepp/ui/css/stylesheetvariable.hpp index e5a85d720..9e16ee218 100644 --- a/include/eepp/ui/css/stylesheetvariable.hpp +++ b/include/eepp/ui/css/stylesheetvariable.hpp @@ -2,8 +2,8 @@ #define EE_UI_CSS_STYLESHEETVARIABLE_HPP #include +#include #include -#include namespace EE { namespace UI { namespace CSS { @@ -18,7 +18,7 @@ class EE_API StyleSheetVariable { const std::string& getName() const; - const Uint32& getNameHash() const; + const String::HashType& getNameHash() const; const std::string& getValue() const; @@ -38,7 +38,7 @@ class EE_API StyleSheetVariable { protected: std::string mName; - Uint32 mNameHash; + String::HashType mNameHash; std::string mValue; Uint32 mSpecificity; }; diff --git a/include/eepp/ui/doc/syntaxhighlighter.hpp b/include/eepp/ui/doc/syntaxhighlighter.hpp index 5472ba0dd..daea84a38 100644 --- a/include/eepp/ui/doc/syntaxhighlighter.hpp +++ b/include/eepp/ui/doc/syntaxhighlighter.hpp @@ -9,7 +9,7 @@ namespace EE { namespace UI { namespace Doc { struct TokenizedLine { int initState; - Uint32 hash; + String::HashType hash; std::vector tokens; int state; }; diff --git a/include/eepp/ui/doc/textdocument.hpp b/include/eepp/ui/doc/textdocument.hpp index 8bdca7c14..8a313e30b 100644 --- a/include/eepp/ui/doc/textdocument.hpp +++ b/include/eepp/ui/doc/textdocument.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -18,63 +19,6 @@ using namespace EE::System; namespace EE { namespace UI { namespace Doc { -class EE_API TextDocumentLine { - public: - TextDocumentLine( const String& text ) : mText( text ) { updateHash(); } - - void setText( const String& text ) { - mText = text; - updateHash(); - } - - const String& getText() const { return mText; } - - void operator=( const std::string& right ) { setText( right ); } - - String::StringBaseType operator[]( std::size_t index ) const { return mText[index]; } - - void insertChar( const unsigned int& pos, const String::StringBaseType& tchar ) { - mText.insert( mText.begin() + pos, tchar ); - updateHash(); - } - - void append( const String& text ) { - mText.append( text ); - updateHash(); - } - - void append( const String::StringBaseType& code ) { - mText.append( code ); - updateHash(); - } - - String substr( std::size_t pos = 0, std::size_t n = String::StringType::npos ) const { - return mText.substr( pos, n ); - } - - String::Iterator insert( String::Iterator p, const String::StringBaseType& c ) { - auto it = mText.insert( p, c ); - updateHash(); - return it; - } - - bool empty() const { return mText.empty(); } - - size_t size() const { return mText.size(); } - - size_t length() const { return mText.length(); } - - const Uint32& getHash() const { return mHash; } - - std::string toUtf8() const { return mText.toUtf8(); } - - protected: - String mText; - Uint32 mHash; - - void updateHash() { mHash = mText.getHash(); } -}; - class EE_API TextDocument { public: typedef std::function DocumentCommand; @@ -98,13 +42,15 @@ class EE_API TextDocument { void reset(); - void loadFromPath( const std::string& path ); + void loadFromStream( IOStream& path ); + + void loadFromFile( const std::string& path ); bool save(); bool save( const std::string& path, const bool& utf8bom = false ); - bool save( IOStreamFile& stream, const bool& utf8bom = false ); + bool save( IOStream& stream, const bool& utf8bom = false ); const std::string getFilename() const; diff --git a/include/eepp/ui/doc/textdocumentline.hpp b/include/eepp/ui/doc/textdocumentline.hpp new file mode 100644 index 000000000..d48bd44fa --- /dev/null +++ b/include/eepp/ui/doc/textdocumentline.hpp @@ -0,0 +1,67 @@ +#ifndef EE_UI_DOC_TEXTDOCUMENTLINE_HPP +#define EE_UI_DOC_TEXTDOCUMENTLINE_HPP + +#include + +namespace EE { namespace UI { namespace Doc { + +class EE_API TextDocumentLine { + public: + TextDocumentLine( const String& text ) : mText( text ) { updateHash(); } + + void setText( const String& text ) { + mText = text; + updateHash(); + } + + const String& getText() const { return mText; } + + void operator=( const std::string& right ) { setText( right ); } + + String::StringBaseType operator[]( std::size_t index ) const { return mText[index]; } + + void insertChar( const unsigned int& pos, const String::StringBaseType& tchar ) { + mText.insert( mText.begin() + pos, tchar ); + updateHash(); + } + + void append( const String& text ) { + mText.append( text ); + updateHash(); + } + + void append( const String::StringBaseType& code ) { + mText.append( code ); + updateHash(); + } + + String substr( std::size_t pos = 0, std::size_t n = String::StringType::npos ) const { + return mText.substr( pos, n ); + } + + String::Iterator insert( String::Iterator p, const String::StringBaseType& c ) { + auto it = mText.insert( p, c ); + updateHash(); + return it; + } + + bool empty() const { return mText.empty(); } + + size_t size() const { return mText.size(); } + + size_t length() const { return mText.length(); } + + const String::HashType& getHash() const { return mHash; } + + std::string toUtf8() const { return mText.toUtf8(); } + + protected: + String mText; + String::HashType mHash; + + void updateHash() { mHash = mText.getHash(); } +}; + +}}} + +#endif // EE_UI_DOC_TEXTDOCUMENTLINE_HPP diff --git a/include/eepp/ui/keyboardshortcut.hpp b/include/eepp/ui/keyboardshortcut.hpp index 6aef76fdc..987a58f30 100644 --- a/include/eepp/ui/keyboardshortcut.hpp +++ b/include/eepp/ui/keyboardshortcut.hpp @@ -2,10 +2,12 @@ #define EE_UI_KEYBOARDSHORTCUT_HPP #include +#include #include #include #include +using namespace EE::Window; namespace EE { namespace Window { class Input; }} // namespace EE::Window @@ -16,12 +18,12 @@ class UIWidget; class EE_API UIKeyShortcut { public: - UIKeyShortcut() : KeyCode( 0 ), Mod( 0 ), Widget( NULL ) {} + UIKeyShortcut() : KeyCode( KEY_UNKNOWN ), Mod( 0 ), Widget( NULL ) {} - UIKeyShortcut( const Uint32& KeyCode, const Uint32& Mod, UIWidget* Widget ) : + UIKeyShortcut( const Keycode& KeyCode, const Uint32& Mod, UIWidget* Widget ) : KeyCode( KeyCode ), Mod( Mod ), Widget( Widget ) {} - Uint32 KeyCode; + Keycode KeyCode; Uint32 Mod; UIWidget* Widget; }; @@ -32,10 +34,10 @@ class EE_API KeyBindings { public: struct Shortcut { Shortcut() {} - Shortcut( Uint32 key, Uint32 mod ) : key( key ), mod( mod ) {} + Shortcut( Keycode key, Uint32 mod ) : key( key ), mod( mod ) {} Shortcut( const Uint64& code ) : - key( code & 0xFFFFFFFF ), mod( ( code >> 32 ) & 0xFFFFFFFF ) {} - Uint32 key{0}; + key( ( Keycode )( code & 0xFFFFFFFF ) ), mod( ( code >> 32 ) & 0xFFFFFFFF ) {} + Keycode key{KEY_UNKNOWN}; Uint32 mod{0}; Uint64 toUint64() const { return (Uint64)mod << 32 | (Uint64)key; } operator Uint64() const { return toUint64(); } diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index c5e19506d..b0de7bf97 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -129,22 +129,35 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { void setKeyBindings( const KeyBindings& keyBindings ); - void addKeyBindingString( const std::string& shortcut, const std::string& command ); + void addKeyBindingString( const std::string& shortcut, const std::string& command, + const bool& allowLocked = false ); - void addKeyBinding( const KeyBindings::Shortcut& shortcut, const std::string& command ); + void addKeyBinding( const KeyBindings::Shortcut& shortcut, const std::string& command, + const bool& allowLocked = false ); - void replaceKeyBindingString( const std::string& shortcut, const std::string& command ); + void replaceKeyBindingString( const std::string& shortcut, const std::string& command, + const bool& allowLocked = false ); - void replaceKeyBinding( const KeyBindings::Shortcut& shortcut, const std::string& command ); + void replaceKeyBinding( const KeyBindings::Shortcut& shortcut, const std::string& command, + const bool& allowLocked = false ); - void addKeybindsString( const std::map& binds ); + void addKeybindsString( const std::map& binds, + const bool& allowLocked = false ); - void addKeybinds( const std::map& binds ); + void addKeybinds( const std::map& binds, + const bool& allowLocked = false ); const bool& getHighlightCurrentLine() const; void setHighlightCurrentLine( const bool& highlightCurrentLine ); + const Uint32& getLineBreakingColumn() const; + + /** Set to 0 to hide. */ + void setLineBreakingColumn( const Uint32& lineBreakingColumn ); + + void addUnlockedCommand( const std::string& command ); + protected: struct LastXOffset { TextPosition position; @@ -175,12 +188,15 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { Color mCurrentLineBackgroundColor; Color mCaretColor; Color mIndentationGuideColor; + Color mLineBreakColumnColor; SyntaxColorScheme mColorScheme; SyntaxHighlighter mHighlighter; UIScrollBar* mVScrollBar; LastXOffset mLastXOffset{{0, 0}, 0.f}; KeyBindings mKeyBindings; + std::unordered_set mUnlockedCmd; Clock mLastDoubleClick; + Uint32 mLineBreakingColumn{100}; void updateColorScheme(); diff --git a/include/eepp/ui/uiscenenode.hpp b/include/eepp/ui/uiscenenode.hpp index e819d5ad6..85ec0d2b0 100644 --- a/include/eepp/ui/uiscenenode.hpp +++ b/include/eepp/ui/uiscenenode.hpp @@ -80,9 +80,9 @@ class EE_API UISceneNode : public SceneNode { UIWidget* getRoot() const; - bool addShortcut( const Uint32& KeyCode, const Uint32& Mod, UIWidget* Widget ); + bool addShortcut( const Keycode& KeyCode, const Uint32& Mod, UIWidget* Widget ); - bool removeShortcut( const Uint32& KeyCode, const Uint32& Mod ); + bool removeShortcut( const Keycode& KeyCode, const Uint32& Mod ); bool getVerbose() const; diff --git a/include/eepp/ui/uitheme.hpp b/include/eepp/ui/uitheme.hpp index 400a0ccdc..17e93f8a2 100644 --- a/include/eepp/ui/uitheme.hpp +++ b/include/eepp/ui/uitheme.hpp @@ -51,7 +51,7 @@ class EE_API UITheme : protected ResourceManagerMulti { void setName( const std::string& name ); - const Uint32& getId() const; + const String::HashType& getId() const; const std::string& getAbbr() const; @@ -77,7 +77,7 @@ class EE_API UITheme : protected ResourceManagerMulti { protected: std::string mName; - Uint32 mNameHash; + String::HashType mNameHash; std::string mAbbr; Graphics::TextureAtlas* mTextureAtlas; Font* mDefaultFont; diff --git a/include/eepp/ui/uiwindow.hpp b/include/eepp/ui/uiwindow.hpp index 144f85b1d..ddba19f8b 100644 --- a/include/eepp/ui/uiwindow.hpp +++ b/include/eepp/ui/uiwindow.hpp @@ -111,9 +111,9 @@ class EE_API UIWindow : public UIWidget { UITextView* getTitleTextBox() const; - bool addShortcut( const Uint32& KeyCode, const Uint32& Mod, UIWidget* Widget ); + bool addShortcut( const Keycode& KeyCode, const Uint32& Mod, UIWidget* Widget ); - bool removeShortcut( const Uint32& KeyCode, const Uint32& Mod ); + bool removeShortcut( const Keycode& KeyCode, const Uint32& Mod ); bool isModal(); @@ -238,7 +238,7 @@ class EE_API UIWindow : public UIWidget { void checkShortcuts( const Uint32& KeyCode, const Uint32& Mod ); - UIKeyboardShortcuts::iterator existsShortcut( const Uint32& KeyCode, const Uint32& Mod ); + UIKeyboardShortcuts::iterator existsShortcut( const Keycode& KeyCode, const Uint32& Mod ); void createModalControl(); diff --git a/include/eepp/window/cursor.hpp b/include/eepp/window/cursor.hpp index a8c1ae64c..dac650a5a 100644 --- a/include/eepp/window/cursor.hpp +++ b/include/eepp/window/cursor.hpp @@ -55,7 +55,7 @@ class EE_API Cursor { }; /** @return The cursor id */ - const Uint32& getId() const; + const String::HashType& getId() const; /** @return The cursor name */ const std::string& getName() const; @@ -72,7 +72,7 @@ class EE_API Cursor { protected: friend class CursorManager; - Uint32 mId; + String::HashType mId; std::string mName; Graphics::Image* mImage; Vector2i mHotSpot; diff --git a/include/eepp/window/cursormanager.hpp b/include/eepp/window/cursormanager.hpp index 04c0dcbd9..cd8f9b553 100644 --- a/include/eepp/window/cursormanager.hpp +++ b/include/eepp/window/cursormanager.hpp @@ -64,19 +64,19 @@ class EE_API CursorManager { * @param Delete Indicates if the cursor must be delete after being removed from the cursor * manager */ - virtual void remove( const Uint32& id, bool Delete = false ); + virtual void remove( const String::HashType& id, bool Delete = false ); /** @return The cursor pointer by its name */ virtual Cursor* get( const std::string& name ); /** @return The cursor pointer by its id */ - virtual Cursor* getById( const Uint32& id ); + virtual Cursor* getById( const String::HashType& id ); /** Set the the current cursor by its name */ virtual void set( const std::string& name ); /** Set the the current cursor by its id */ - virtual void setById( const Uint32& id ); + virtual void setById( const String::HashType& id ); /** Set the the current cursor by its cursor pointer */ virtual void set( Cursor* cursor ) = 0; diff --git a/include/eepp/window/input.hpp b/include/eepp/window/input.hpp index 7f610e7a4..d2cd7c6ce 100644 --- a/include/eepp/window/input.hpp +++ b/include/eepp/window/input.hpp @@ -98,9 +98,15 @@ class EE_API Input { /** @return If the Shift Key is pressed */ bool isShiftPressed() const; - /** @return If the Alt Key is pressed */ + /** @return If any Alt Key is pressed */ bool isAltPressed() const; + /** @return If the left Alt Key is pressed */ + bool isLeftAltPressed() const; + + /** @return If the left Alt Key is pressed */ + bool isAltGrPressed() const; + /** @return If the Meta Key is pressed */ bool isMetaPressed() const; diff --git a/include/eepp/window/inputevent.hpp b/include/eepp/window/inputevent.hpp index 567ef21b1..e4cfce963 100644 --- a/include/eepp/window/inputevent.hpp +++ b/include/eepp/window/inputevent.hpp @@ -93,9 +93,9 @@ class InputEvent { /** Keyboard text editing event */ struct TextInputEvent { Uint32 timestamp; - Uint32 text; + String::StringBaseType text; - String getText() { return String( text ); } + String getText() { return String( (String::StringBaseType)text ); } }; /** Joystick axis motion event structure */ diff --git a/include/eepp/window/inputtextbuffer.hpp b/include/eepp/window/inputtextbuffer.hpp index 55d080be3..949427965 100644 --- a/include/eepp/window/inputtextbuffer.hpp +++ b/include/eepp/window/inputtextbuffer.hpp @@ -185,11 +185,11 @@ class EE_API InputTextBuffer { void eraseToNextNoChar(); - bool isIgnoredChar( const Uint32& c ); + bool isIgnoredChar( const String::StringBaseType& c ); - bool validChar( const Uint32& c ); + bool validChar(const String::StringBaseType& c ); - void tryAddChar( const Uint32& c ); + void tryAddChar( const String::StringBaseType& c ); void shiftSelection( const int& lastPromtpPos ); diff --git a/projects/linux/ee.files b/projects/linux/ee.files index fe8e0b7b7..516074c7e 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -322,6 +322,7 @@ ../../include/eepp/ui/doc/syntaxhighlighter.hpp ../../include/eepp/ui/doc/syntaxtokenizer.hpp ../../include/eepp/ui/doc/textdocument.hpp +../../include/eepp/ui/doc/textdocumentline.hpp ../../include/eepp/ui/doc/textposition.hpp ../../include/eepp/ui/doc/textrange.hpp ../../include/eepp/ui/doc/undostack.hpp diff --git a/src/eepp/core/string.cpp b/src/eepp/core/string.cpp index a0051ab14..a6de8e376 100644 --- a/src/eepp/core/string.cpp +++ b/src/eepp/core/string.cpp @@ -1,18 +1,16 @@ #include #include -#include #include #include #include +#include #include -static CRC::Table CRC_TABLE( CRC::CRC_32() ); - namespace EE { const std::size_t String::InvalidPos = StringType::npos; -constexpr Uint32 String::hash( const Uint8* str ) { +constexpr String::HashType String::hash( const Uint8* str ) { //! djb2 if ( NULL != str ) { Uint32 hash = 5381; @@ -27,12 +25,12 @@ constexpr Uint32 String::hash( const Uint8* str ) { return 0; } -Uint32 String::hash( const std::string& str ) { +String::HashType String::hash( const std::string& str ) { return String::hash( str.c_str() ); } -Uint32 String::hash( const String& str ) { - return CRC::Calculate( (void*)str.c_str(), sizeof( StringBaseType ) * str.size(), CRC_TABLE ); +String::HashType String::hash( const String& str ) { + return std::hash{}( str.mString ); } bool String::isCharacter( const int& value ) { @@ -489,6 +487,16 @@ String::String( const char* utf8String ) { } } +String::String( const char* utf8String, const size_t& utf8StringSize ) { + if ( utf8String ) { + if ( utf8StringSize > 0 ) { + mString.reserve( utf8StringSize + 1 ); + + Utf8::toUtf32( utf8String, utf8String + utf8StringSize, std::back_inserter( mString ) ); + } + } +} + String::String( const std::string& utf8String ) { mString.reserve( utf8String.length() + 1 ); @@ -597,7 +605,7 @@ std::basic_string String::toUtf16() const { return output; } -Uint32 String::getHash() const { +String::HashType String::getHash() const { return String::hash( *this ); } diff --git a/src/eepp/graphics/drawableresource.cpp b/src/eepp/graphics/drawableresource.cpp index 1876fed8a..295130d29 100644 --- a/src/eepp/graphics/drawableresource.cpp +++ b/src/eepp/graphics/drawableresource.cpp @@ -16,7 +16,7 @@ DrawableResource::~DrawableResource() { sendEvent( Event::Unload ); } -const Uint32& DrawableResource::getId() const { +const String::HashType& DrawableResource::getId() const { return mId; } diff --git a/src/eepp/graphics/drawablesearcher.cpp b/src/eepp/graphics/drawablesearcher.cpp index e560928e9..79f41f673 100644 --- a/src/eepp/graphics/drawablesearcher.cpp +++ b/src/eepp/graphics/drawablesearcher.cpp @@ -31,7 +31,7 @@ static Drawable* getSprite( const std::string& sprite ) { } static Drawable* searchByNameInternal( const std::string& name ) { - Uint32 id = String::hash( name ); + String::HashType id = String::hash( name ); Drawable* drawable = TextureAtlasManager::instance()->getTextureRegionById( id ); if ( NULL == drawable ) { diff --git a/src/eepp/graphics/font.cpp b/src/eepp/graphics/font.cpp index d521d9cd4..986872c36 100644 --- a/src/eepp/graphics/font.cpp +++ b/src/eepp/graphics/font.cpp @@ -29,7 +29,7 @@ void Font::setName( const std::string& name ) { mFontHash = String::hash( mFontName ); } -const Uint32& Font::getId() { +const String::HashType& Font::getId() { return mFontHash; } diff --git a/src/eepp/graphics/framebuffer.cpp b/src/eepp/graphics/framebuffer.cpp index ffbd9d49c..18f415b85 100644 --- a/src/eepp/graphics/framebuffer.cpp +++ b/src/eepp/graphics/framebuffer.cpp @@ -137,7 +137,7 @@ void FrameBuffer::setName( const std::string& name ) { mId = String::hash( mName ); } -const Uint32& FrameBuffer::getId() const { +const String::HashType& FrameBuffer::getId() const { return mId; } diff --git a/src/eepp/graphics/framebuffermanager.cpp b/src/eepp/graphics/framebuffermanager.cpp index 64391cc67..943c7d657 100644 --- a/src/eepp/graphics/framebuffermanager.cpp +++ b/src/eepp/graphics/framebuffermanager.cpp @@ -34,7 +34,7 @@ FrameBuffer* FrameBufferManager::getFromName( const std::string& name ) { return getFromId( String::hash( name ) ); } -FrameBuffer* FrameBufferManager::getFromId( const Uint32& id ) { +FrameBuffer* FrameBufferManager::getFromId( const String::HashType& id ) { for ( auto& fb : mResources ) { if ( fb->getId() == id ) { return fb; diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index 306986247..302a8264f 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -1185,7 +1185,7 @@ Uint32 Text::getTotalVertices() { size_t sl = mString.size(); size_t sv = sl * GLi->quadVertexs(); - Uint32* c = &mString[0]; + String::StringBaseType* c = &mString[0]; Uint32 skiped = 0; bool lineHasChars = false; diff --git a/src/eepp/graphics/texture.cpp b/src/eepp/graphics/texture.cpp index e599cc1a5..940ed1d5c 100644 --- a/src/eepp/graphics/texture.cpp +++ b/src/eepp/graphics/texture.cpp @@ -598,7 +598,7 @@ void Texture::replace( Image* image ) { onResourceChange(); } -const Uint32& Texture::getHashName() const { +const String::HashType& Texture::getHashName() const { return mId; } diff --git a/src/eepp/graphics/textureatlas.cpp b/src/eepp/graphics/textureatlas.cpp index 4022a63e4..08fbf82ad 100644 --- a/src/eepp/graphics/textureatlas.cpp +++ b/src/eepp/graphics/textureatlas.cpp @@ -29,7 +29,7 @@ void TextureAtlas::setPath( const std::string& path ) { mPath = path; } -const Uint32& TextureAtlas::getId() const { +const String::HashType& TextureAtlas::getId() const { return mId; } diff --git a/src/eepp/graphics/textureatlasmanager.cpp b/src/eepp/graphics/textureatlasmanager.cpp index 2d43d338f..1ee521703 100644 --- a/src/eepp/graphics/textureatlasmanager.cpp +++ b/src/eepp/graphics/textureatlasmanager.cpp @@ -51,7 +51,7 @@ TextureRegion* TextureAtlasManager::getTextureRegionByName( const std::string& N return tTextureRegion; } -TextureRegion* TextureAtlasManager::getTextureRegionById( const Uint32& Id ) { +TextureRegion* TextureAtlasManager::getTextureRegionById( const String::HashType& Id ) { std::list::iterator it; TextureAtlas* tSG = NULL; diff --git a/src/eepp/graphics/texturefactory.cpp b/src/eepp/graphics/texturefactory.cpp index 8e0dc30c7..a017fe9f2 100644 --- a/src/eepp/graphics/texturefactory.cpp +++ b/src/eepp/graphics/texturefactory.cpp @@ -326,13 +326,13 @@ Texture* TextureFactory::getByName( const std::string& Name ) { return getByHash( String::hash( Name ) ); } -Texture* TextureFactory::getByHash( const Uint32& Hash ) { +Texture* TextureFactory::getByHash( const String::HashType& hash ) { Texture* tTex = NULL; for ( Uint32 i = (Uint32)mTextures.size() - 1; i > 0; i-- ) { tTex = mTextures[i]; - if ( NULL != tTex && tTex->getHashName() == Hash ) + if ( NULL != tTex && tTex->getHashName() == hash ) return mTextures[i]; } diff --git a/src/eepp/maps/mapeditor/mapeditor.cpp b/src/eepp/maps/mapeditor/mapeditor.cpp index cd7f60069..e09e351d7 100644 --- a/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/eepp/maps/mapeditor/mapeditor.cpp @@ -93,7 +93,7 @@ void MapEditor::createME() { createUIMap(); } -bool MapEditor::addShortcut( const Uint32& KeyCode, const Uint32& Mod, UIWidget* Widget ) { +bool MapEditor::addShortcut( const Keycode& KeyCode, const Uint32& Mod, UIWidget* Widget ) { if ( NULL != mUIWindow ) { return mUIWindow->addShortcut( KeyCode, Mod, Widget ); } else { @@ -264,7 +264,7 @@ void MapEditor::createTabs() { mTabWidget->add( "Objects", mObjectCont ); } -void MapEditor::onTabSelected( const Event* Event ) { +void MapEditor::onTabSelected( const Event* ) { if ( NULL != mUIMap ) { switch ( mTabWidget->getSelectedTabIndex() ) { case 0: @@ -736,14 +736,14 @@ void MapEditor::onAddObject( Uint32 Type, Polygon2f poly ) { } } -void MapEditor::onLightTypeChange( const Event* Event ) { +void MapEditor::onLightTypeChange( const Event* ) { if ( NULL != mUIMap->getSelectedLight() ) { mUIMap->getSelectedLight()->setType( mLightTypeChk->isChecked() ? MapLightType::Isometric : MapLightType::Normal ); } } -void MapEditor::onLightRadiusChangeVal( const Event* Event ) { +void MapEditor::onLightRadiusChangeVal( const Event* ) { if ( NULL != mUIMap->getSelectedLight() ) { mUIMap->getSelectedLight()->setRadius( mLightRadius->getValue() ); } @@ -775,7 +775,7 @@ void MapEditor::onNewLight( const Event* Event ) { } } -void MapEditor::onRedChange( const Event* Event ) { +void MapEditor::onRedChange( const Event* ) { Color Col = mUIBaseColor->getBackgroundColor(); Col.r = (Uint8)mUIRedSlider->getValue(); mUIBaseColor->setBackgroundColor( Col ); @@ -788,7 +788,7 @@ void MapEditor::onRedChange( const Event* Event ) { } } -void MapEditor::onGreenChange( const Event* Event ) { +void MapEditor::onGreenChange( const Event* ) { Color Col = mUIBaseColor->getBackgroundColor(); Col.g = (Uint8)mUIGreenSlider->getValue(); mUIBaseColor->setBackgroundColor( Col ); @@ -801,7 +801,7 @@ void MapEditor::onGreenChange( const Event* Event ) { } } -void MapEditor::onBlueChange( const Event* Event ) { +void MapEditor::onBlueChange( const Event* ) { Color Col = mUIBaseColor->getBackgroundColor(); Col.b = (Uint8)mUIBlueSlider->getValue(); mUIBaseColor->setBackgroundColor( Col ); @@ -814,7 +814,7 @@ void MapEditor::onBlueChange( const Event* Event ) { } } -void MapEditor::chkClickDI( const Event* Event ) { +void MapEditor::chkClickDI( const Event* ) { if ( mChkDI->isChecked() ) { mSGCont->setEnabled( false ); mSGCont->setVisible( false ); @@ -828,7 +828,7 @@ void MapEditor::chkClickDI( const Event* Event ) { } } -void MapEditor::chkClickClampToTile( const Event* Event ) { +void MapEditor::chkClickClampToTile( const Event* ) { if ( NULL != mUIMap ) mUIMap->setClampToTile( mChkClampToTile->isChecked() ); } @@ -874,7 +874,7 @@ void MapEditor::updateFlags() { mCurGOFlags |= GObjFlags::GAMEOBJECT_BLEND_ADD; } -void MapEditor::onTypeChange( const Event* Event ) { +void MapEditor::onTypeChange( const Event* ) { if ( mGOTypeList->getText() == "TextureRegion" ) mCurGOType = GAMEOBJECT_TYPE_TEXTUREREGION; else if ( mGOTypeList->getText() == "TextureRegionEx" ) @@ -893,30 +893,30 @@ void MapEditor::onTypeChange( const Event* Event ) { } } -void MapEditor::chkClickMirrored( const Event* Event ) { +void MapEditor::chkClickMirrored( const Event* ) { updateGfx(); updateFlags(); } -void MapEditor::chkClickFlipped( const Event* Event ) { +void MapEditor::chkClickFlipped( const Event* ) { updateGfx(); updateFlags(); } -void MapEditor::chkClickRot90( const Event* Event ) { +void MapEditor::chkClickRot90( const Event* ) { updateGfx(); updateFlags(); } -void MapEditor::chkClickBlocked( const Event* Event ) { +void MapEditor::chkClickBlocked( const Event* ) { updateFlags(); } -void MapEditor::chkClickAutoFix( const Event* Event ) { +void MapEditor::chkClickAutoFix( const Event* ) { updateFlags(); } -void MapEditor::chkClickAnimated( const Event* Event ) { +void MapEditor::chkClickAnimated( const Event* ) { updateFlags(); if ( mChkAnim->isChecked() && ( mGOTypeList->getText() == "TextureRegion" || @@ -925,11 +925,11 @@ void MapEditor::chkClickAnimated( const Event* Event ) { } } -void MapEditor::addNewGOType( const Event* Event ) { +void MapEditor::addNewGOType( const Event* ) { eeNew( UIGOTypeNew, ( cb::Make2( this, &MapEditor::onNewGOTypeAdded ) ) ); } -void MapEditor::onNewGOTypeAdded( std::string name, Uint32 hash ) { +void MapEditor::onNewGOTypeAdded( std::string name, String::HashType ) { if ( "" != name ) { for ( Uint32 i = 0; i < mGOTypeList->getListBox()->getCount(); i++ ) { UIListBoxItem* Item = mGOTypeList->getListBox()->getItem( i ); @@ -997,7 +997,7 @@ void MapEditor::fillTextureRegionList() { 8.f / (Float)mTextureRegionList->getCount() ); } -void MapEditor::onTextureRegionChange( const Event* Event ) { +void MapEditor::onTextureRegionChange( const Event* ) { if ( NULL != mCurSG ) { TextureRegion* tTextureRegion = mCurSG->getByName( mTextureRegionList->getItemSelectedText() ); @@ -1008,7 +1008,7 @@ void MapEditor::onTextureRegionChange( const Event* Event ) { } } -void MapEditor::onTextureAtlasChange( const Event* Event ) { +void MapEditor::onTextureAtlasChange( const Event* ) { fillTextureRegionList(); } @@ -1039,7 +1039,7 @@ void MapEditor::mapCreated() { createTabs(); } -void MapEditor::onMapSizeChange( const Event* Event ) { +void MapEditor::onMapSizeChange( const Event* ) { if ( mMouseScrolling ) return; @@ -1064,14 +1064,14 @@ void MapEditor::onMapSizeChange( const Event* Event ) { mMapVScroll->setPageStep( v.y / s.y * m.y ); } -void MapEditor::onScrollMapH( const Event* Event ) { +void MapEditor::onScrollMapH( const Event* ) { if ( mMouseScrolling ) return; mUIMap->Map()->setOffset( Vector2f( -mMapHScroll->getValue(), -mMapVScroll->getValue() ) ); } -void MapEditor::onScrollMapV( const Event* Event ) { +void MapEditor::onScrollMapV( const Event* ) { mUIMap->Map()->setOffset( Vector2f( -mMapHScroll->getValue(), -mMapVScroll->getValue() ) ); } @@ -1159,7 +1159,7 @@ void MapEditor::fileMenuClick( const Event* Event ) { } } -void MapEditor::onMapClose( const Event* Event ) { +void MapEditor::onMapClose( const Event* ) { createNewEmptyMap(); mapCreated(); @@ -1414,7 +1414,7 @@ void MapEditor::onLayerAdd( UIMapLayerNew* UILayer ) { } } -void MapEditor::onLayerSelect( const Event* Event ) { +void MapEditor::onLayerSelect( const Event* ) { MapLayer* tLayer = mUIMap->Map()->getLayer( mLayerList->getText() ); if ( NULL != tLayer ) { @@ -1428,7 +1428,7 @@ void MapEditor::onLayerSelect( const Event* Event ) { } } -void MapEditor::windowClose( const Event* Event ) { +void MapEditor::windowClose( const Event* ) { if ( mCloseCb ) mCloseCb(); diff --git a/src/eepp/maps/maplayer.cpp b/src/eepp/maps/maplayer.cpp index 9364a3af0..a06d0430e 100644 --- a/src/eepp/maps/maplayer.cpp +++ b/src/eepp/maps/maplayer.cpp @@ -58,7 +58,7 @@ const std::string& MapLayer::getName() const { return mName; } -const Uint32& MapLayer::getId() const { +const String::HashType& MapLayer::getId() const { return mNameHash; } diff --git a/src/eepp/maps/tilemap.cpp b/src/eepp/maps/tilemap.cpp index 4336c5a05..b8230ad01 100644 --- a/src/eepp/maps/tilemap.cpp +++ b/src/eepp/maps/tilemap.cpp @@ -184,7 +184,7 @@ MapLayer* TileMap::getLayer( Uint32 index ) { return mLayers[index]; } -MapLayer* TileMap::getLayerByHash( Uint32 hash ) { +MapLayer* TileMap::getLayerByHash( String::HashType hash ) { for ( Uint32 i = 0; i < mLayerCount; i++ ) { if ( mLayers[i]->getId() == hash ) return mLayers[i]; diff --git a/src/eepp/network/http.cpp b/src/eepp/network/http.cpp index 3dd64757f..6266cd5cd 100644 --- a/src/eepp/network/http.cpp +++ b/src/eepp/network/http.cpp @@ -1378,7 +1378,7 @@ std::string Http::Pool::getHostKey( const URI& host, const URI& proxy ) { proxy.getSchemeAndAuthority().c_str() ); } -Uint32 Http::Pool::getHostHash( const URI& host, const URI& proxy ) { +String::HashType Http::Pool::getHostHash( const URI& host, const URI& proxy ) { return String::hash( Http::Pool::getHostKey( host, proxy ) ); } diff --git a/src/eepp/scene/eventdispatcher.cpp b/src/eepp/scene/eventdispatcher.cpp index 75f28c0f7..0ee1b2c94 100644 --- a/src/eepp/scene/eventdispatcher.cpp +++ b/src/eepp/scene/eventdispatcher.cpp @@ -176,7 +176,7 @@ void EventDispatcher::sendTextInput( const Uint32& textChar, const Uint32& times } } -void EventDispatcher::sendKeyUp( const Uint32& KeyCode, const Uint32& Char, const Uint32& Mod ) { +void EventDispatcher::sendKeyUp( const Keycode& KeyCode, const Uint32& Char, const Uint32& Mod ) { KeyEvent keyEvent = KeyEvent( mFocusNode, Event::KeyUp, KeyCode, Char, Mod ); Node* CtrlLoop = mFocusNode; @@ -188,7 +188,7 @@ void EventDispatcher::sendKeyUp( const Uint32& KeyCode, const Uint32& Char, cons } } -void EventDispatcher::sendKeyDown( const Uint32& KeyCode, const Uint32& Char, const Uint32& Mod ) { +void EventDispatcher::sendKeyDown( const Keycode& KeyCode, const Uint32& Char, const Uint32& Mod ) { KeyEvent keyEvent = KeyEvent( mFocusNode, Event::KeyDown, KeyCode, Char, Mod ); Node* CtrlLoop = mFocusNode; diff --git a/src/eepp/scene/keyevent.cpp b/src/eepp/scene/keyevent.cpp index 93faf0c22..a82e0d9b7 100644 --- a/src/eepp/scene/keyevent.cpp +++ b/src/eepp/scene/keyevent.cpp @@ -3,17 +3,17 @@ namespace EE { namespace Scene { -KeyEvent::KeyEvent( Node* node, const Uint32& eventNum, const Uint32& keyCode, const Uint32& chr, +KeyEvent::KeyEvent( Node* node, const Uint32& eventNum, const Keycode& keyCode, const Uint32& chr, const Uint32& mod ) : Event( node, eventNum ), mKeyCode( keyCode ), mChar( chr ), mMod( mod ) {} KeyEvent::~KeyEvent() {} -const Uint32& KeyEvent::getKeyCode() const { +const Keycode& KeyEvent::getKeyCode() const { return mKeyCode; } -const Uint32& KeyEvent::getChar() const { +const String::StringBaseType& KeyEvent::getChar() const { return mChar; } @@ -25,7 +25,7 @@ TextInputEvent::TextInputEvent( Node* node, const Uint32& eventNum, const Uint32 const Uint32& timestamp ) : Event( node, eventNum ), mChar( chr ), mTimestamp( timestamp ) {} -const Uint32& TextInputEvent::getChar() const { +const String::StringBaseType& TextInputEvent::getChar() const { return mChar; } @@ -34,7 +34,7 @@ const Uint32& TextInputEvent::getTimestamp() const { } String TextInputEvent::getText() const { - return String( mChar ); + return String( (String::StringBaseType)mChar ); } }} // namespace EE::Scene diff --git a/src/eepp/scene/node.cpp b/src/eepp/scene/node.cpp index fb8b8f8b0..3046cda90 100644 --- a/src/eepp/scene/node.cpp +++ b/src/eepp/scene/node.cpp @@ -699,11 +699,11 @@ bool Node::isClosing() const { return 0 != ( mNodeFlags & NODE_FLAG_CLOSE ); } -Uint32 Node::getIdHash() const { +const String::HashType& Node::getIdHash() const { return mIdHash; } -Node* Node::findIdHash( const Uint32& idHash ) const { +Node* Node::findIdHash( const String::HashType& idHash ) const { if ( mIdHash == idHash ) { return const_cast( this ); } else { diff --git a/src/eepp/ui/css/animationdefinition.cpp b/src/eepp/ui/css/animationdefinition.cpp index 62edc54c4..b111f9c16 100644 --- a/src/eepp/ui/css/animationdefinition.cpp +++ b/src/eepp/ui/css/animationdefinition.cpp @@ -159,7 +159,7 @@ std::unordered_map AnimationDefinition::parseA } bool AnimationDefinition::isDirectionString( const std::string str ) { - Uint32 id = String::hash( str ); + String::HashType id = String::hash( str ); return id == AlternateReverse || id == Alternate || id == Reverse || id == Normal; } @@ -244,7 +244,7 @@ void AnimationDefinition::setPaused( bool value ) { mPaused = value; } -const Uint32& AnimationDefinition::getId() const { +const String::HashType& AnimationDefinition::getId() const { return mId; } diff --git a/src/eepp/ui/css/propertydefinition.cpp b/src/eepp/ui/css/propertydefinition.cpp index c261fb220..6072bd53c 100644 --- a/src/eepp/ui/css/propertydefinition.cpp +++ b/src/eepp/ui/css/propertydefinition.cpp @@ -25,7 +25,7 @@ const std::string& PropertyDefinition::getName() const { return mName; } -const Uint32& PropertyDefinition::getId() const { +const String::HashType& PropertyDefinition::getId() const { return mId; } @@ -61,7 +61,7 @@ const PropertyType& PropertyDefinition::getType() const { } PropertyDefinition& PropertyDefinition::addAlias( const std::string& alias ) { - Uint32 aliasId = String::hash( alias ); + String::HashType aliasId = String::hash( alias ); mAliases.push_back( alias ); mAliasesHash.push_back( aliasId ); PropertySpecification::instance()->addPropertyAlias( aliasId, this ); diff --git a/src/eepp/ui/css/propertyspecification.cpp b/src/eepp/ui/css/propertyspecification.cpp index ce73c7469..0970958a5 100644 --- a/src/eepp/ui/css/propertyspecification.cpp +++ b/src/eepp/ui/css/propertyspecification.cpp @@ -64,7 +64,7 @@ PropertySpecification::registerShorthand( const std::string& name, return *shorthandDef; } -const ShorthandDefinition* PropertySpecification::getShorthand( const Uint32& id ) const { +const ShorthandDefinition* PropertySpecification::getShorthand( const String::HashType& id ) const { auto it = mShorthands.find( id ); if ( it != mShorthands.end() ) diff --git a/src/eepp/ui/css/shorthanddefinition.cpp b/src/eepp/ui/css/shorthanddefinition.cpp index a75a00370..3331756db 100644 --- a/src/eepp/ui/css/shorthanddefinition.cpp +++ b/src/eepp/ui/css/shorthanddefinition.cpp @@ -38,7 +38,7 @@ const std::string& ShorthandDefinition::getName() const { return mName; } -const Uint32& ShorthandDefinition::getId() const { +const String::HashType& ShorthandDefinition::getId() const { return mId; } @@ -60,7 +60,7 @@ bool ShorthandDefinition::isAlias( const std::string& alias ) const { return isAlias( String::hash( alias ) ); } -bool ShorthandDefinition::isAlias( const Uint32& id ) const { +bool ShorthandDefinition::isAlias( const String::HashType& id ) const { return std::find( mAliasesHash.begin(), mAliasesHash.end(), id ) != mAliasesHash.end(); } @@ -68,7 +68,7 @@ bool ShorthandDefinition::isDefinition( const std::string& name ) const { return isDefinition( String::hash( name ) ); } -bool ShorthandDefinition::isDefinition( const Uint32& id ) const { +bool ShorthandDefinition::isDefinition( const String::HashType& id ) const { return mId == id || isAlias( id ); } diff --git a/src/eepp/ui/css/stylesheet.cpp b/src/eepp/ui/css/stylesheet.cpp index ed1e848d7..35576984e 100644 --- a/src/eepp/ui/css/stylesheet.cpp +++ b/src/eepp/ui/css/stylesheet.cpp @@ -15,7 +15,7 @@ template inline void HashCombine( std::size_t& seed, const T& v ) { seed ^= hasher( v ) + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 ); } -size_t StyleSheet::NodeHash( const std::string& tag, const std::string& id ) { +size_t StyleSheet::nodeHash( const std::string& tag, const std::string& id ) { size_t seed = 0; if ( !tag.empty() ) seed = std::hash()( tag ); @@ -28,7 +28,7 @@ bool StyleSheet::addStyleToNodeIndex( StyleSheetStyle* style ) { const std::string& id = style->getSelector().getSelectorId(); const std::string& tag = style->getSelector().getSelectorTagName(); if ( style->hasProperties() || style->hasVariables() ) { - size_t nodeHash = NodeHash( "*" == tag ? "" : tag, id ); + size_t nodeHash = this->nodeHash( "*" == tag ? "" : tag, id ); StyleSheetStyleVector& nodes = mNodeIndex[nodeHash]; auto it = std::find( nodes.begin(), nodes.end(), style ); if ( it == nodes.end() ) { @@ -83,12 +83,12 @@ std::shared_ptr StyleSheet::getElementStyles( UIWidget* eleme int numHashes = 2; nodeHash[0] = 0; - nodeHash[1] = NodeHash( tag, "" ); + nodeHash[1] = this->nodeHash( tag, "" ); if ( !id.empty() ) { numHashes = 4; - nodeHash[2] = NodeHash( "", id ); - nodeHash[3] = NodeHash( tag, id ); + nodeHash[2] = this->nodeHash( "", id ); + nodeHash[3] = this->nodeHash( tag, id ); } for ( int i = 0; i < numHashes; i++ ) { diff --git a/src/eepp/ui/css/stylesheetproperty.cpp b/src/eepp/ui/css/stylesheetproperty.cpp index 161b6791d..1d8538041 100644 --- a/src/eepp/ui/css/stylesheetproperty.cpp +++ b/src/eepp/ui/css/stylesheetproperty.cpp @@ -177,7 +177,7 @@ bool StyleSheetProperty::operator!=( const StyleSheetProperty& property ) const return mNameHash != property.mNameHash || mValueHash != property.mValueHash; } -const Uint32& StyleSheetProperty::getNameHash() const { +const String::HashType& StyleSheetProperty::getNameHash() const { return mNameHash; } @@ -654,7 +654,7 @@ Sizei StyleSheetProperty::asSizei( UINode* node, const Sizei& defaultValue ) con return Sizei( asVector2i( node, defaultValue ) ); } -const Uint32& StyleSheetProperty::getValueHash() const { +const String::HashType& StyleSheetProperty::getValueHash() const { return mValueHash; } diff --git a/src/eepp/ui/css/stylesheetvariable.cpp b/src/eepp/ui/css/stylesheetvariable.cpp index 6de2a7e0a..35f807399 100644 --- a/src/eepp/ui/css/stylesheetvariable.cpp +++ b/src/eepp/ui/css/stylesheetvariable.cpp @@ -56,7 +56,7 @@ bool StyleSheetVariable::operator==( const StyleSheetVariable& variable ) { return mNameHash == variable.mNameHash && mValue == variable.mValue; } -const Uint32& StyleSheetVariable::getNameHash() const { +const String::HashType& StyleSheetVariable::getNameHash() const { return mNameHash; } diff --git a/src/eepp/ui/doc/syntaxcolorscheme.cpp b/src/eepp/ui/doc/syntaxcolorscheme.cpp index b91fa2971..d4583fc65 100644 --- a/src/eepp/ui/doc/syntaxcolorscheme.cpp +++ b/src/eepp/ui/doc/syntaxcolorscheme.cpp @@ -3,6 +3,10 @@ namespace EE { namespace UI { namespace Doc { // Color schemes are compatible with the lite (https://github.com/rxi/lite) color schemes. +// But I also added: +// "line_number_background" (the gutter background color) +// "indentation" (the indentation line color) +// "line_break_column" (the right margin line column color) SyntaxColorScheme SyntaxColorScheme::getDefault() { return {"lite-theme", @@ -28,6 +32,7 @@ SyntaxColorScheme SyntaxColorScheme::getDefault() { {"line_number2", Color( "#83838f" )}, {"line_number_background", Color( "#2e2e32" )}, {"indentation", Color( "#54575b" )}, + {"line_break_column", Color( "#54575b99" )}, }}; } diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index 1adab4d27..ba42bc39a 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -41,44 +42,108 @@ void TextDocument::reset() { notifySelectionChanged(); } -void TextDocument::loadFromPath( const std::string& path ) { - if ( !FileSystem::fileExists( path ) ) { - eePRINTL( "File \"%s\" does not exists. Creating a new file.", path.c_str() ); - } +static String ptrGetLine( char* data, const size_t& size, size_t& position ) { + position = 0; + while ( position < size && data[position] != '\n' ) + position++; + if ( position < size ) + position++; + return String( data, position ); +} + +void TextDocument::loadFromStream( IOStream& file ) { Clock clock; reset(); mLines.clear(); - mFilePath = path; - mSyntaxDefinition = SyntaxDefinitionManager::instance()->getStyleByExtension( path ); - // TODO: Reimplement load without using getline, since the standard ignores the last \n and - // is inconsistent. - std::string line; - std::ifstream file( path ); - while ( std::getline( file, line ) ) { - if ( mLines.empty() && line.size() >= 3 ) { - // Check UTF-8 BOM header - if ( (char)0xef == line[0] && (char)0xbb == line[1] && (char)0xbf == line[2] ) { - line = line.substr( 3 ); - mIsBOM = true; + if ( file.isOpen() ) { + const size_t BLOCK_SIZE = EE_1MB; + size_t total = file.getSize(); + size_t pending = total; + size_t blockSize = eemin( total, BLOCK_SIZE ); + size_t read = 0; + String lineBuffer; + size_t position; + int consume; + char* bufferPtr; + TScopedBuffer data( blockSize ); + while ( pending ) { + read = file.read( data.get(), blockSize ); + bufferPtr = data.get(); + consume = read; + + if ( pending == total ) { + // Check UTF-8 BOM header + if ( (char)0xef == data.get()[0] && (char)0xbb == data.get()[1] && + (char)0xbf == data.get()[2] ) { + bufferPtr += 3; + consume -= 3; + mIsBOM = true; + } } - } - // Check CLRF - if ( !line.empty() && line[line.size() - 1] == '\r' ) { - line = line.substr( 0, line.size() - 1 ); - mIsCLRF = true; - } - mLines.emplace_back( TextDocumentLine( line + "\n" ) ); + + while ( consume ) { + lineBuffer += ptrGetLine( bufferPtr, consume, position ); + bufferPtr += position; + consume -= position; + + if ( lineBuffer[lineBuffer.size() - 1] == '\n' || !consume ) { + if ( mLines.empty() && lineBuffer.size() > 1 && + lineBuffer[lineBuffer.size() - 2] == '\r' ) { + mIsCLRF = true; + } + + if ( mIsCLRF && lineBuffer.size() > 1 ) { + lineBuffer[lineBuffer.size() - 2] = '\n'; + lineBuffer.resize( lineBuffer.size() - 1 ); + } + + mLines.push_back( lineBuffer ); + lineBuffer.resize( 0 ); + } + + if ( consume < 0 ) { + eeASSERT( !consume ); + break; + } + } + + if ( !mLines.empty() ) { + const String& lastLine = mLines[mLines.size() - 1].getText(); + if ( lastLine[lastLine.size() - 1] == '\n' ) { + mLines.push_back( String( "\n" ) ); + } else { + mLines[mLines.size() - 1].append( "\n" ); + } + } + + if ( !read ) + break; + pending -= read; + blockSize = eemin( pending, BLOCK_SIZE ); + }; } - if ( mLines.empty() ) { - mLines.emplace_back( TextDocumentLine( "\n" ) ); - } else if ( mLines[mLines.size() - 1][mLines[mLines.size() - 1].size() - 1] != '\n' ) { - mLines[mLines.size() - 1].append( '\n' ); - } - eePRINTL( "Document \"%s\" loaded in %.2fms.", path.c_str(), + eePRINTL( "Document \"%s\" loaded in %.2fms.", + mFilePath.empty() ? "untitled" : mFilePath.c_str(), clock.getElapsedTime().asMilliseconds() ); } +void TextDocument::loadFromFile( const std::string& path ) { + if ( !FileSystem::fileExists( path ) ) { + eePRINTL( "File \"%s\" does not exists. Creating a new file.", path.c_str() ); + } + + if ( !FileSystem::fileExists( path ) ) { + mSyntaxDefinition = SyntaxDefinitionManager::instance()->getStyleByExtension( path ); + return; + } + + IOStreamFile file( path, "rb" ); + loadFromStream( file ); + mFilePath = path; + mSyntaxDefinition = SyntaxDefinitionManager::instance()->getStyleByExtension( path ); +} + bool TextDocument::save( const std::string& path, const bool& utf8bom ) { if ( path.empty() || mDefaultFileName == path ) return false; @@ -90,7 +155,7 @@ bool TextDocument::save( const std::string& path, const bool& utf8bom ) { return false; } -bool TextDocument::save( IOStreamFile& stream, const bool& utf8bom ) { +bool TextDocument::save( IOStream& stream, const bool& utf8bom ) { if ( !stream.isOpen() || mLines.empty() ) return false; char nl = '\n'; @@ -100,17 +165,19 @@ bool TextDocument::save( IOStreamFile& stream, const bool& utf8bom ) { } size_t lastLine = mLines.size() - 1; for ( size_t i = 0; i <= lastLine; i++ ) { - std::string utf8( mLines[i].toUtf8() ); - if ( i == lastLine && utf8.size() > 1 && utf8[utf8.size() - 1] == '\n' ) { + std::string text( mLines[i].toUtf8() ); + if ( i == lastLine && !text.empty() && text[text.size() - 1] == '\n' ) { // Last \n is added by the document but it's not part of the document. - utf8.pop_back(); + text.pop_back(); + if ( text.empty() ) + continue; } if ( mIsCLRF ) { - utf8[utf8.size() - 1] = '\r'; - stream.write( utf8.c_str(), utf8.size() ); + text[text.size() - 1] = '\r'; + stream.write( text.c_str(), text.size() ); stream.write( &nl, 1 ); } else { - stream.write( utf8.c_str(), utf8.size() ); + stream.write( text.c_str(), text.size() ); } } cleanChangeId(); diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index adc3d9a0f..f636a1738 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -102,6 +102,13 @@ void UICodeEditor::draw() { Sizef( mSize.getWidth(), lineHeight ) ) ); } + if ( mLineBreakingColumn ) { + Float lineBreakingOffset = start.x + getGlyphWidth() * mLineBreakingColumn; + primitives.setColor( mLineBreakColumnColor ); + primitives.drawLine( + {{lineBreakingOffset, start.y}, {lineBreakingOffset, start.y + mSize.getHeight()}} ); + } + if ( mDoc.hasSelection() ) { drawSelection( lineRange, startScroll, lineHeight ); } @@ -156,7 +163,7 @@ void UICodeEditor::reset() { } void UICodeEditor::loadFromFile( const std::string& path ) { - mDoc.loadFromPath( path ); + mDoc.loadFromFile( path ); invalidateEditor(); } @@ -344,6 +351,7 @@ void UICodeEditor::updateColorScheme() { mCurrentLineBackgroundColor = mColorScheme.getEditorColor( "line_highlight" ); mCaretColor = mColorScheme.getEditorColor( "caret" ); mIndentationGuideColor = mColorScheme.getEditorColor( "indentation" ); + mLineBreakColumnColor = mColorScheme.getEditorColor( "line_break_column" ); } void UICodeEditor::setColorScheme( const SyntaxColorScheme& colorScheme ) { @@ -405,11 +413,11 @@ Uint32 UICodeEditor::onKeyDown( const KeyEvent& event ) { if ( !cmd.empty() ) { // Allow copy selection on locked mode - if ( !( mLocked && cmd != "copy" ) ) + if ( !mLocked || mUnlockedCmd.find( cmd ) != mUnlockedCmd.end() ) mDoc.execute( cmd ); } - return 1; + return 0; } TextPosition UICodeEditor::resolveScreenPosition( const Vector2f& position ) const { @@ -519,7 +527,6 @@ Uint32 UICodeEditor::onMouseLeave( const Vector2i& position, const Uint32& flags void UICodeEditor::onSizeChange() { UIWidget::onSizeChange(); - mScroll = {0, 0}; invalidateEditor(); } @@ -583,6 +590,11 @@ int UICodeEditor::getVisibleLinesCount() { } void UICodeEditor::scrollToMakeVisible( const TextPosition& position ) { + auto lineRange = getVisibleLineRange(); + + if ( position.line() >= lineRange.first && position.line() <= lineRange.second ) + return; + // Vertical Scroll Float lineHeight = getLineHeight(); Float min = eefloor( lineHeight * ( eemax( 0, position.line() - 1 ) ) ); @@ -687,31 +699,52 @@ void UICodeEditor::setKeyBindings( const KeyBindings& keyBindings ) { mKeyBindings = keyBindings; } -void UICodeEditor::addKeyBindingString( const std::string& shortcut, const std::string& command ) { +void UICodeEditor::addKeyBindingString( const std::string& shortcut, const std::string& command, + const bool& allowLocked ) { mKeyBindings.addKeybindString( shortcut, command ); + if ( allowLocked ) + mUnlockedCmd.insert( command ); } -void UICodeEditor::addKeyBinding( const KeyBindings::Shortcut& shortcut, - const std::string& command ) { +void UICodeEditor::addKeyBinding( const KeyBindings::Shortcut& shortcut, const std::string& command, + const bool& allowLocked ) { mKeyBindings.addKeybind( shortcut, command ); + if ( allowLocked ) + mUnlockedCmd.insert( command ); } -void UICodeEditor::replaceKeyBindingString( const std::string& shortcut, - const std::string& command ) { +void UICodeEditor::replaceKeyBindingString( const std::string& shortcut, const std::string& command, + const bool& allowLocked ) { mKeyBindings.replaceKeybindString( shortcut, command ); + if ( allowLocked ) + mUnlockedCmd.insert( command ); } void UICodeEditor::replaceKeyBinding( const KeyBindings::Shortcut& shortcut, - const std::string& command ) { + const std::string& command, const bool& allowLocked ) { mKeyBindings.replaceKeybind( shortcut, command ); + if ( allowLocked ) + mUnlockedCmd.insert( command ); } -void UICodeEditor::addKeybindsString( const std::map& binds ) { +void UICodeEditor::addKeybindsString( const std::map& binds, + const bool& allowLocked ) { mKeyBindings.addKeybindsString( binds ); + for ( auto bind : binds ) { + if ( allowLocked ) { + mUnlockedCmd.insert( bind.second ); + } + } } -void UICodeEditor::addKeybinds( const std::map& binds ) { +void UICodeEditor::addKeybinds( const std::map& binds, + const bool& allowLocked ) { mKeyBindings.addKeybinds( binds ); + for ( auto bind : binds ) { + if ( allowLocked ) { + mUnlockedCmd.insert( bind.second ); + } + } } const bool& UICodeEditor::getHighlightCurrentLine() const { @@ -725,6 +758,21 @@ void UICodeEditor::setHighlightCurrentLine( const bool& highlightCurrentLine ) { } } +const Uint32& UICodeEditor::getLineBreakingColumn() const { + return mLineBreakingColumn; +} + +void UICodeEditor::setLineBreakingColumn( const Uint32& lineBreakingColumn ) { + if ( lineBreakingColumn != mLineBreakingColumn ) { + mLineBreakingColumn = lineBreakingColumn; + invalidateDraw(); + } +} + +void UICodeEditor::addUnlockedCommand( const std::string& command ) { + mUnlockedCmd.insert( command ); +} + Int64 UICodeEditor::getColFromXOffset( Int64 lineNumber, const Float& x ) const { if ( x <= 0 ) return 0; @@ -974,11 +1022,16 @@ void UICodeEditor::registerCommands() { mDoc.setCommand( "font-size-grow", [&] { fontSizeGrow(); } ); mDoc.setCommand( "font-size-shrink", [&] { fontSizeShrink(); } ); mDoc.setCommand( "font-size-reset", [&] { fontSizeReset(); } ); + mDoc.setCommand( "lock", [&] { setLocked( true ); } ); + mDoc.setCommand( "unlock", [&] { setLocked( false ); } ); + mDoc.setCommand( "lock-toggle", [&] { setLocked( !isLocked() ); } ); + mUnlockedCmd.insert( {"copy", "select-all"} ); } void UICodeEditor::registerKeybindings() { mKeyBindings.addKeybinds( { {{KEY_BACKSPACE, KEYMOD_CTRL}, "delete-to-previous-word"}, + {{KEY_BACKSPACE, KEYMOD_SHIFT}, "delete-to-previous-char"}, {{KEY_BACKSPACE, 0}, "delete-to-previous-char"}, {{KEY_DELETE, KEYMOD_CTRL}, "delete-to-next-word"}, {{KEY_DELETE, 0}, "delete-to-next-char"}, diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 542704051..c9c9b8d7d 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -510,6 +510,8 @@ Uint32 UIMenu::onKeyDown( const KeyEvent& Event ) { mItemSelected->messagePost( &Msg ); } + break; + default: break; } } diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index c94a3538c..15e27c7d7 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -778,8 +778,9 @@ void UISceneNode::checkShortcuts( const Uint32& KeyCode, const Uint32& Mod ) { } UIKeyboardShortcuts::iterator UISceneNode::existsShortcut( const Uint32& KeyCode, - const Uint32& Mod ) { - for ( UIKeyboardShortcuts::iterator it = mKbShortcuts.begin(); it != mKbShortcuts.end(); ++it ) { + const Uint32& Mod ) { + for ( UIKeyboardShortcuts::iterator it = mKbShortcuts.begin(); it != mKbShortcuts.end(); + ++it ) { if ( it->KeyCode == KeyCode && it->Mod == Mod ) return it; } @@ -787,7 +788,7 @@ UIKeyboardShortcuts::iterator UISceneNode::existsShortcut( const Uint32& KeyCode return mKbShortcuts.end(); } -bool UISceneNode::addShortcut( const Uint32& KeyCode, const Uint32& Mod, UIWidget* Widget ) { +bool UISceneNode::addShortcut( const Keycode& KeyCode, const Uint32& Mod, UIWidget* Widget ) { if ( inParentTreeOf( Widget ) && mKbShortcuts.end() == existsShortcut( KeyCode, Mod ) ) { mKbShortcuts.push_back( UIKeyShortcut( KeyCode, Mod, Widget ) ); @@ -797,7 +798,7 @@ bool UISceneNode::addShortcut( const Uint32& KeyCode, const Uint32& Mod, UIWidge return false; } -bool UISceneNode::removeShortcut( const Uint32& KeyCode, const Uint32& Mod ) { +bool UISceneNode::removeShortcut( const Keycode& KeyCode, const Uint32& Mod ) { UIKeyboardShortcuts::iterator it = existsShortcut( KeyCode, Mod ); if ( mKbShortcuts.end() != it ) { diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index 6d08f4f59..f9ec616ce 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -275,7 +275,7 @@ void UITheme::setName( const std::string& name ) { mNameHash = String::hash( mName ); } -const Uint32& UITheme::getId() const { +const String::HashType& UITheme::getId() const { return mNameHash; } diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index 944340f88..578afceff 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -1332,8 +1332,10 @@ void UIWindow::checkShortcuts( const Uint32& KeyCode, const Uint32& Mod ) { } } -UIKeyboardShortcuts::iterator UIWindow::existsShortcut( const Uint32& KeyCode, const Uint32& Mod ) { - for ( UIKeyboardShortcuts::iterator it = mKbShortcuts.begin(); it != mKbShortcuts.end(); ++it ) { +UIKeyboardShortcuts::iterator UIWindow::existsShortcut( const Keycode& KeyCode, + const Uint32& Mod ) { + for ( UIKeyboardShortcuts::iterator it = mKbShortcuts.begin(); it != mKbShortcuts.end(); + ++it ) { if ( ( *it ).KeyCode == KeyCode && ( *it ).Mod == Mod ) return it; } @@ -1341,7 +1343,7 @@ UIKeyboardShortcuts::iterator UIWindow::existsShortcut( const Uint32& KeyCode, c return mKbShortcuts.end(); } -bool UIWindow::addShortcut( const Uint32& KeyCode, const Uint32& Mod, UIWidget* Widget ) { +bool UIWindow::addShortcut( const Keycode& KeyCode, const Uint32& Mod, UIWidget* Widget ) { if ( inParentTreeOf( Widget ) && mKbShortcuts.end() == existsShortcut( KeyCode, Mod ) ) { mKbShortcuts.push_back( UIKeyShortcut( KeyCode, Mod, Widget ) ); @@ -1351,7 +1353,7 @@ bool UIWindow::addShortcut( const Uint32& KeyCode, const Uint32& Mod, UIWidget* return false; } -bool UIWindow::removeShortcut( const Uint32& KeyCode, const Uint32& Mod ) { +bool UIWindow::removeShortcut( const Keycode& KeyCode, const Uint32& Mod ) { UIKeyboardShortcuts::iterator it = existsShortcut( KeyCode, Mod ); if ( mKbShortcuts.end() != it ) { diff --git a/src/eepp/window/cursor.cpp b/src/eepp/window/cursor.cpp index 9bee29c64..7d8a28296 100644 --- a/src/eepp/window/cursor.cpp +++ b/src/eepp/window/cursor.cpp @@ -87,7 +87,7 @@ Cursor::Type Cursor::fromName( std::string name ) { return Arrow; } -const Uint32& Cursor::getId() const { +const String::HashType& Cursor::getId() const { return mId; } diff --git a/src/eepp/window/cursormanager.cpp b/src/eepp/window/cursormanager.cpp index ccf54d5b1..8c2db0d67 100644 --- a/src/eepp/window/cursormanager.cpp +++ b/src/eepp/window/cursormanager.cpp @@ -35,7 +35,7 @@ void CursorManager::remove( const std::string& name, bool Delete ) { remove( String::hash( name ), Delete ); } -void CursorManager::remove( const Uint32& id, bool Delete ) { +void CursorManager::remove( const String::HashType& id, bool Delete ) { for ( CursorsList::iterator it = mCursors.begin(); it != mCursors.end(); ++it ) { if ( ( *it )->getId() == id ) { remove( ( *it ), Delete ); @@ -48,7 +48,7 @@ Cursor* CursorManager::get( const std::string& name ) { return getById( String::hash( name ) ); } -Cursor* CursorManager::getById( const Uint32& id ) { +Cursor* CursorManager::getById( const String::HashType& id ) { for ( CursorsList::iterator it = mCursors.begin(); it != mCursors.end(); ++it ) { if ( ( *it )->getId() == id ) { return ( *it ); @@ -62,7 +62,7 @@ void CursorManager::set( const std::string& name ) { setById( String::hash( name ) ); } -void CursorManager::setById( const Uint32& id ) { +void CursorManager::setById( const String::HashType& id ) { for ( CursorsList::iterator it = mCursors.begin(); it != mCursors.end(); ++it ) { if ( ( *it )->getId() == id ) { set( *it ); diff --git a/src/eepp/window/input.cpp b/src/eepp/window/input.cpp index e1934ec61..d7d5e668e 100644 --- a/src/eepp/window/input.cpp +++ b/src/eepp/window/input.cpp @@ -336,6 +336,14 @@ bool Input::isAltPressed() const { return ( mInputMod & KEYMOD_ALT ) != 0; } +bool Input::isLeftAltPressed() const { + return ( mInputMod & KEYMOD_LALT ) != 0; +} + +bool Input::isAltGrPressed() const { + return ( mInputMod & KEYMOD_RALT ) != 0; +} + bool Input::isMetaPressed() const { return ( mInputMod & KEYMOD_META ) != 0; } diff --git a/src/eepp/window/inputtextbuffer.cpp b/src/eepp/window/inputtextbuffer.cpp index 3fc3ad712..ab9235ebc 100644 --- a/src/eepp/window/inputtextbuffer.cpp +++ b/src/eepp/window/inputtextbuffer.cpp @@ -194,7 +194,7 @@ void InputTextBuffer::eraseToNextNoChar() { } } -bool InputTextBuffer::isIgnoredChar( const Uint32& c ) { +bool InputTextBuffer::isIgnoredChar( const String::StringBaseType& c ) { if ( mIgnoredChars.size() ) { for ( std::size_t i = 0; i < mIgnoredChars.size(); i++ ) { if ( mIgnoredChars[i] == c ) @@ -205,7 +205,7 @@ bool InputTextBuffer::isIgnoredChar( const Uint32& c ) { return false; } -bool InputTextBuffer::validChar( const Uint32& c ) { +bool InputTextBuffer::validChar( const String::StringBaseType& c ) { if ( canAdd() && String::isCharacter( c ) ) { bool Ignored = false; @@ -225,7 +225,7 @@ bool InputTextBuffer::validChar( const Uint32& c ) { return false; } -void InputTextBuffer::tryAddChar( const Uint32& c ) { +void InputTextBuffer::tryAddChar( const String::StringBaseType& c ) { if ( isFreeEditingEnabled() ) { if ( validChar( c ) ) { removeSelection(); diff --git a/src/thirdparty/crc/CRC.h b/src/thirdparty/crc/CRC.h deleted file mode 100644 index 3a7dc64d4..000000000 --- a/src/thirdparty/crc/CRC.h +++ /dev/null @@ -1,1705 +0,0 @@ -/** - @file CRC.h - @author Daniel Bahr - @version 1.0.1.0 - @copyright - @parblock - CRC++ - Copyright (c) 2020, Daniel Bahr - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of CRC++ nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - @endparblock -*/ - -/* - CRC++ can be configured by setting various #defines before #including this header file: - - #define crcpp_uint8 - Specifies the type used to store CRCs that have a width of 8 bits or less. - This type is not used in CRC calculations. Defaults to ::std::uint8_t. - #define crcpp_uint16 - Specifies the type used to store CRCs that have a width between 9 and 16 bits (inclusive). - This type is not used in CRC calculations. Defaults to ::std::uint16_t. - #define crcpp_uint32 - Specifies the type used to store CRCs that have a width between 17 and 32 bits (inclusive). - This type is not used in CRC calculations. Defaults to ::std::uint32_t. - #define crcpp_uint64 - Specifies the type used to store CRCs that have a width between 33 and 64 bits (inclusive). - This type is not used in CRC calculations. Defaults to ::std::uint64_t. - #define crcpp_size - This type is used for loop iteration and function signatures only. Defaults to ::std::size_t. - #define CRCPP_USE_NAMESPACE - Define to place all CRC++ code within the ::CRCPP namespace. - #define CRCPP_BRANCHLESS - Define to enable a branchless CRC implementation. The branchless implementation uses a single integer - multiplication in the bit-by-bit calculation instead of a small conditional. The branchless implementation - may be faster on processor architectures which support single-instruction integer multiplication. - #define CRCPP_USE_CPP11 - Define to enables C++11 features (move semantics, constexpr, static_assert, etc.). - #define CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - Define to include definitions for little-used CRCs. -*/ - -#ifndef CRCPP_CRC_H_ -#define CRCPP_CRC_H_ - -#include // Includes CHAR_BIT -#ifdef CRCPP_USE_CPP11 -#include // Includes ::std::size_t -#include // Includes ::std::uint8_t, ::std::uint16_t, ::std::uint32_t, ::std::uint64_t -#else -#include // Includes size_t -#include // Includes uint8_t, uint16_t, uint32_t, uint64_t -#endif -#include // Includes ::std::numeric_limits -#include // Includes ::std::move - -#ifndef crcpp_uint8 -# ifdef CRCPP_USE_CPP11 - /// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions. -# define crcpp_uint8 ::std::uint8_t -# else - /// @brief Unsigned 8-bit integer definition, used primarily for parameter definitions. -# define crcpp_uint8 uint8_t -# endif -#endif - -#ifndef crcpp_uint16 -# ifdef CRCPP_USE_CPP11 - /// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions. -# define crcpp_uint16 ::std::uint16_t -# else - /// @brief Unsigned 16-bit integer definition, used primarily for parameter definitions. -# define crcpp_uint16 uint16_t -# endif -#endif - -#ifndef crcpp_uint32 -# ifdef CRCPP_USE_CPP11 - /// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions. -# define crcpp_uint32 ::std::uint32_t -# else - /// @brief Unsigned 32-bit integer definition, used primarily for parameter definitions. -# define crcpp_uint32 uint32_t -# endif -#endif - -#ifndef crcpp_uint64 -# ifdef CRCPP_USE_CPP11 - /// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions. -# define crcpp_uint64 ::std::uint64_t -# else - /// @brief Unsigned 64-bit integer definition, used primarily for parameter definitions. -# define crcpp_uint64 uint64_t -# endif -#endif - -#ifndef crcpp_size -# ifdef CRCPP_USE_CPP11 - /// @brief Unsigned size definition, used for specifying data sizes. -# define crcpp_size ::std::size_t -# else - /// @brief Unsigned size definition, used for specifying data sizes. -# define crcpp_size size_t -# endif -#endif - -#ifdef CRCPP_USE_CPP11 - /// @brief Compile-time expression definition. -# define crcpp_constexpr constexpr -#else - /// @brief Compile-time expression definition. -# define crcpp_constexpr const -#endif - -#ifdef CRCPP_USE_NAMESPACE -namespace CRCPP -{ -#endif - -/** - @brief Static class for computing CRCs. - @note This class supports computation of full and multi-part CRCs, using a bit-by-bit algorithm or a - byte-by-byte lookup table. The CRCs are calculated using as many optimizations as is reasonable. - If compiling with C++11, the constexpr keyword is used liberally so that many calculations are - performed at compile-time instead of at runtime. -*/ -class CRC -{ -public: - // Forward declaration - template - struct Table; - - /** - @brief CRC parameters. - */ - template - struct Parameters - { - CRCType polynomial; ///< CRC polynomial - CRCType initialValue; ///< Initial CRC value - CRCType finalXOR; ///< Value to XOR with the final CRC - bool reflectInput; ///< true to reflect all input bytes - bool reflectOutput; ///< true to reflect the output CRC (reflection occurs before the final XOR) - - Table MakeTable() const; - }; - - /** - @brief CRC lookup table. After construction, the CRC parameters are fixed. - @note A CRC table can be used for multiple CRC calculations. - */ - template - struct Table - { - // Constructors are intentionally NOT marked explicit. - Table(const Parameters & parameters); - -#ifdef CRCPP_USE_CPP11 - Table(Parameters && parameters); -#endif - - const Parameters & GetParameters() const; - - const CRCType * GetTable() const; - - CRCType operator[](unsigned char index) const; - - private: - void InitTable(); - - Parameters parameters; ///< CRC parameters used to construct the table - CRCType table[1 << CHAR_BIT]; ///< CRC lookup table - }; - - // The number of bits in CRCType must be at least as large as CRCWidth. - // CRCType must be an unsigned integer type or a custom type with operator overloads. - template - static CRCType Calculate(const void * data, crcpp_size size, const Parameters & parameters); - - template - static CRCType Calculate(const void * data, crcpp_size size, const Parameters & parameters, CRCType crc); - - template - static CRCType Calculate(const void * data, crcpp_size size, const Table & lookupTable); - - template - static CRCType Calculate(const void * data, crcpp_size size, const Table & lookupTable, CRCType crc); - - // Common CRCs up to 64 bits. - // Note: Check values are the computed CRCs when given an ASCII input of "123456789" (without null terminator) -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - static const Parameters< crcpp_uint8, 4> & CRC_4_ITU(); - static const Parameters< crcpp_uint8, 5> & CRC_5_EPC(); - static const Parameters< crcpp_uint8, 5> & CRC_5_ITU(); - static const Parameters< crcpp_uint8, 5> & CRC_5_USB(); - static const Parameters< crcpp_uint8, 6> & CRC_6_CDMA2000A(); - static const Parameters< crcpp_uint8, 6> & CRC_6_CDMA2000B(); - static const Parameters< crcpp_uint8, 6> & CRC_6_ITU(); - static const Parameters< crcpp_uint8, 7> & CRC_7(); -#endif - static const Parameters< crcpp_uint8, 8> & CRC_8(); -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - static const Parameters< crcpp_uint8, 8> & CRC_8_EBU(); - static const Parameters< crcpp_uint8, 8> & CRC_8_MAXIM(); - static const Parameters< crcpp_uint8, 8> & CRC_8_WCDMA(); - static const Parameters & CRC_10(); - static const Parameters & CRC_10_CDMA2000(); - static const Parameters & CRC_11(); - static const Parameters & CRC_12_CDMA2000(); - static const Parameters & CRC_12_DECT(); - static const Parameters & CRC_12_UMTS(); - static const Parameters & CRC_13_BBC(); - static const Parameters & CRC_15(); - static const Parameters & CRC_15_MPT1327(); -#endif - static const Parameters & CRC_16_ARC(); - static const Parameters & CRC_16_BUYPASS(); - static const Parameters & CRC_16_CCITTFALSE(); -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - static const Parameters & CRC_16_CDMA2000(); - static const Parameters & CRC_16_CMS(); - static const Parameters & CRC_16_DECTR(); - static const Parameters & CRC_16_DECTX(); - static const Parameters & CRC_16_DNP(); -#endif - static const Parameters & CRC_16_GENIBUS(); - static const Parameters & CRC_16_KERMIT(); -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - static const Parameters & CRC_16_MAXIM(); - static const Parameters & CRC_16_MODBUS(); - static const Parameters & CRC_16_T10DIF(); - static const Parameters & CRC_16_USB(); -#endif - static const Parameters & CRC_16_X25(); - static const Parameters & CRC_16_XMODEM(); -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - static const Parameters & CRC_17_CAN(); - static const Parameters & CRC_21_CAN(); - static const Parameters & CRC_24(); - static const Parameters & CRC_24_FLEXRAYA(); - static const Parameters & CRC_24_FLEXRAYB(); - static const Parameters & CRC_30(); -#endif - static const Parameters & CRC_32(); - static const Parameters & CRC_32_BZIP2(); -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - static const Parameters & CRC_32_C(); -#endif - static const Parameters & CRC_32_MPEG2(); - static const Parameters & CRC_32_POSIX(); -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - static const Parameters & CRC_32_Q(); - static const Parameters & CRC_40_GSM(); - static const Parameters & CRC_64(); -#endif - -#ifdef CRCPP_USE_CPP11 - CRC() = delete; - CRC(const CRC & other) = delete; - CRC & operator=(const CRC & other) = delete; - CRC(CRC && other) = delete; - CRC & operator=(CRC && other) = delete; -#endif - -private: -#ifndef CRCPP_USE_CPP11 - CRC(); - CRC(const CRC & other); - CRC & operator=(const CRC & other); -#endif - - template - static IntegerType Reflect(IntegerType value, crcpp_uint16 numBits); - - template - static CRCType Finalize(CRCType remainder, CRCType finalXOR, bool reflectOutput); - - template - static CRCType UndoFinalize(CRCType remainder, CRCType finalXOR, bool reflectOutput); - - template - static CRCType CalculateRemainder(const void * data, crcpp_size size, const Parameters & parameters, CRCType remainder); - - template - static CRCType CalculateRemainder(const void * data, crcpp_size size, const Table & lookupTable, CRCType remainder); -}; - -/** - @brief Returns a CRC lookup table construct using these CRC parameters. - @note This function primarily exists to allow use of the auto keyword instead of instantiating - a table directly, since template parameters are not inferred in constructors. - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return CRC lookup table -*/ -template -inline CRC::Table CRC::Parameters::MakeTable() const -{ - // This should take advantage of RVO and optimize out the copy. - return CRC::Table(*this); -} - -/** - @brief Constructs a CRC table from a set of CRC parameters - @param[in] params CRC parameters - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC -*/ -template -inline CRC::Table::Table(const Parameters & params) : - parameters(params) -{ - InitTable(); -} - -#ifdef CRCPP_USE_CPP11 -/** - @brief Constructs a CRC table from a set of CRC parameters - @param[in] params CRC parameters - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC -*/ -template -inline CRC::Table::Table(Parameters && params) : - parameters(::std::move(params)) -{ - InitTable(); -} -#endif - -/** - @brief Gets the CRC parameters used to construct the CRC table - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return CRC parameters -*/ -template -inline const CRC::Parameters & CRC::Table::GetParameters() const -{ - return parameters; -} - -/** - @brief Gets the CRC table - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return CRC table -*/ -template -inline const CRCType * CRC::Table::GetTable() const -{ - return table; -} - -/** - @brief Gets an entry in the CRC table - @param[in] index Index into the CRC table - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return CRC table entry -*/ -template -inline CRCType CRC::Table::operator[](unsigned char index) const -{ - return table[index]; -} - -/** - @brief Initializes a CRC table. - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC -*/ -template -inline void CRC::Table::InitTable() -{ - // For masking off the bits for the CRC (in the event that the number of bits in CRCType is larger than CRCWidth) - static crcpp_constexpr CRCType BIT_MASK((CRCType(1) << (CRCWidth - CRCType(1))) | - ((CRCType(1) << (CRCWidth - CRCType(1))) - CRCType(1))); - - // The conditional expression is used to avoid a -Wshift-count-overflow warning. - static crcpp_constexpr CRCType SHIFT((CHAR_BIT >= CRCWidth) ? static_cast(CHAR_BIT - CRCWidth) : 0); - - CRCType crc; - unsigned char byte = 0; - - // Loop over each dividend (each possible number storable in an unsigned char) - do - { - crc = CRC::CalculateRemainder(&byte, sizeof(byte), parameters, CRCType(0)); - - // This mask might not be necessary; all unit tests pass with this line commented out, - // but that might just be a coincidence based on the CRC parameters used for testing. - // In any case, this is harmless to leave in and only adds a single machine instruction per loop iteration. - crc &= BIT_MASK; - - if (!parameters.reflectInput && CRCWidth < CHAR_BIT) - { - // Undo the special operation at the end of the CalculateRemainder() - // function for non-reflected CRCs < CHAR_BIT. - crc = static_cast(crc << SHIFT); - } - - table[byte] = crc; - } - while (++byte); -} - -/** - @brief Computes a CRC. - @param[in] data Data over which CRC will be computed - @param[in] size Size of the data - @param[in] parameters CRC parameters - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return CRC -*/ -template -inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Parameters & parameters) -{ - CRCType remainder = CalculateRemainder(data, size, parameters, parameters.initialValue); - - // No need to mask the remainder here; the mask will be applied in the Finalize() function. - - return Finalize(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput); -} -/** - @brief Appends additional data to a previous CRC calculation. - @note This function can be used to compute multi-part CRCs. - @param[in] data Data over which CRC will be computed - @param[in] size Size of the data - @param[in] parameters CRC parameters - @param[in] crc CRC from a previous calculation - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return CRC -*/ -template -inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Parameters & parameters, CRCType crc) -{ - CRCType remainder = UndoFinalize(crc, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput); - - remainder = CalculateRemainder(data, size, parameters, remainder); - - // No need to mask the remainder here; the mask will be applied in the Finalize() function. - - return Finalize(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput); -} - -/** - @brief Computes a CRC via a lookup table. - @param[in] data Data over which CRC will be computed - @param[in] size Size of the data - @param[in] lookupTable CRC lookup table - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return CRC -*/ -template -inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Table & lookupTable) -{ - const Parameters & parameters = lookupTable.GetParameters(); - - CRCType remainder = CalculateRemainder(data, size, lookupTable, parameters.initialValue); - - // No need to mask the remainder here; the mask will be applied in the Finalize() function. - - return Finalize(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput); -} - -/** - @brief Appends additional data to a previous CRC calculation using a lookup table. - @note This function can be used to compute multi-part CRCs. - @param[in] data Data over which CRC will be computed - @param[in] size Size of the data - @param[in] lookupTable CRC lookup table - @param[in] crc CRC from a previous calculation - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return CRC -*/ -template -inline CRCType CRC::Calculate(const void * data, crcpp_size size, const Table & lookupTable, CRCType crc) -{ - const Parameters & parameters = lookupTable.GetParameters(); - - CRCType remainder = UndoFinalize(crc, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput); - - remainder = CalculateRemainder(data, size, lookupTable, remainder); - - // No need to mask the remainder here; the mask will be applied in the Finalize() function. - - return Finalize(remainder, parameters.finalXOR, parameters.reflectInput != parameters.reflectOutput); -} - -/** - @brief Reflects (i.e. reverses the bits within) an integer value. - @param[in] value Value to reflect - @param[in] numBits Number of bits in the integer which will be reflected - @tparam IntegerType Integer type of the value being reflected - @return Reflected value -*/ -template -inline IntegerType CRC::Reflect(IntegerType value, crcpp_uint16 numBits) -{ - IntegerType reversedValue(0); - - for (crcpp_uint16 i = 0; i < numBits; ++i) - { - reversedValue = static_cast((reversedValue << 1) | (value & 1)); - value = static_cast(value >> 1); - } - - return reversedValue; -} - -/** - @brief Computes the final reflection and XOR of a CRC remainder. - @param[in] remainder CRC remainder to reflect and XOR - @param[in] finalXOR Final value to XOR with the remainder - @param[in] reflectOutput true to reflect each byte of the remainder before the XOR - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return Final CRC -*/ -template -inline CRCType CRC::Finalize(CRCType remainder, CRCType finalXOR, bool reflectOutput) -{ - // For masking off the bits for the CRC (in the event that the number of bits in CRCType is larger than CRCWidth) - static crcpp_constexpr CRCType BIT_MASK = (CRCType(1) << (CRCWidth - CRCType(1))) | - ((CRCType(1) << (CRCWidth - CRCType(1))) - CRCType(1)); - - if (reflectOutput) - { - remainder = Reflect(remainder, CRCWidth); - } - - return (remainder ^ finalXOR) & BIT_MASK; -} - -/** - @brief Undoes the process of computing the final reflection and XOR of a CRC remainder. - @note This function allows for computation of multi-part CRCs - @note Calling UndoFinalize() followed by Finalize() (or vice versa) will always return the original remainder value: - - CRCType x = ...; - CRCType y = Finalize(x, finalXOR, reflectOutput); - CRCType z = UndoFinalize(y, finalXOR, reflectOutput); - assert(x == z); - - @param[in] crc Reflected and XORed CRC - @param[in] finalXOR Final value XORed with the remainder - @param[in] reflectOutput true if the remainder is to be reflected - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return Un-finalized CRC remainder -*/ -template -inline CRCType CRC::UndoFinalize(CRCType crc, CRCType finalXOR, bool reflectOutput) -{ - // For masking off the bits for the CRC (in the event that the number of bits in CRCType is larger than CRCWidth) - static crcpp_constexpr CRCType BIT_MASK = (CRCType(1) << (CRCWidth - CRCType(1))) | - ((CRCType(1) << (CRCWidth - CRCType(1))) - CRCType(1)); - - crc = (crc & BIT_MASK) ^ finalXOR; - - if (reflectOutput) - { - crc = Reflect(crc, CRCWidth); - } - - return crc; -} - -/** - @brief Computes a CRC remainder. - @param[in] data Data over which the remainder will be computed - @param[in] size Size of the data - @param[in] parameters CRC parameters - @param[in] remainder Running CRC remainder. Can be an initial value or the result of a previous CRC remainder calculation. - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return CRC remainder -*/ -template -inline CRCType CRC::CalculateRemainder(const void * data, crcpp_size size, const Parameters & parameters, CRCType remainder) -{ -#ifdef CRCPP_USE_CPP11 - // This static_assert is put here because this function will always be compiled in no matter what - // the template parameters are and whether or not a table lookup or bit-by-bit algorithm is used. - static_assert(::std::numeric_limits::digits >= CRCWidth, "CRCType is too small to contain a CRC of width CRCWidth."); -#else - // Catching this compile-time error is very important. Sadly, the compiler error will be very cryptic, but it's - // better than nothing. - enum { static_assert_failed_CRCType_is_too_small_to_contain_a_CRC_of_width_CRCWidth = 1 / (::std::numeric_limits::digits >= CRCWidth ? 1 : 0) }; -#endif - - const unsigned char * current = reinterpret_cast(data); - - // Slightly different implementations based on the parameters. The current implementations try to eliminate as much - // computation from the inner loop (looping over each bit) as possible. - if (parameters.reflectInput) - { - CRCType polynomial = CRC::Reflect(parameters.polynomial, CRCWidth); - while (size--) - { - remainder = static_cast(remainder ^ *current++); - - // An optimizing compiler might choose to unroll this loop. - for (crcpp_size i = 0; i < CHAR_BIT; ++i) - { -#ifdef CRCPP_BRANCHLESS - // Clever way to avoid a branch at the expense of a multiplication. This code is equivalent to the following: - // if (remainder & 1) - // remainder = (remainder >> 1) ^ polynomial; - // else - // remainder >>= 1; - remainder = static_cast((remainder >> 1) ^ ((remainder & 1) * polynomial)); -#else - remainder = static_cast((remainder & 1) ? ((remainder >> 1) ^ polynomial) : (remainder >> 1)); -#endif - } - } - } - else if (CRCWidth >= CHAR_BIT) - { - static crcpp_constexpr CRCType CRC_WIDTH_MINUS_ONE(CRCWidth - CRCType(1)); -#ifndef CRCPP_BRANCHLESS - static crcpp_constexpr CRCType CRC_HIGHEST_BIT_MASK(CRCType(1) << CRC_WIDTH_MINUS_ONE); -#endif - // The conditional expression is used to avoid a -Wshift-count-overflow warning. - static crcpp_constexpr CRCType SHIFT((CRCWidth >= CHAR_BIT) ? static_cast(CRCWidth - CHAR_BIT) : 0); - - while (size--) - { - remainder = static_cast(remainder ^ (static_cast(*current++) << SHIFT)); - - // An optimizing compiler might choose to unroll this loop. - for (crcpp_size i = 0; i < CHAR_BIT; ++i) - { -#ifdef CRCPP_BRANCHLESS - // Clever way to avoid a branch at the expense of a multiplication. This code is equivalent to the following: - // if (remainder & CRC_HIGHEST_BIT_MASK) - // remainder = (remainder << 1) ^ parameters.polynomial; - // else - // remainder <<= 1; - remainder = static_cast((remainder << 1) ^ (((remainder >> CRC_WIDTH_MINUS_ONE) & 1) * parameters.polynomial)); -#else - remainder = static_cast((remainder & CRC_HIGHEST_BIT_MASK) ? ((remainder << 1) ^ parameters.polynomial) : (remainder << 1)); -#endif - } - } - } - else - { - static crcpp_constexpr CRCType CHAR_BIT_MINUS_ONE(CHAR_BIT - 1); -#ifndef CRCPP_BRANCHLESS - static crcpp_constexpr CRCType CHAR_BIT_HIGHEST_BIT_MASK(CRCType(1) << CHAR_BIT_MINUS_ONE); -#endif - // The conditional expression is used to avoid a -Wshift-count-overflow warning. - static crcpp_constexpr CRCType SHIFT((CHAR_BIT >= CRCWidth) ? static_cast(CHAR_BIT - CRCWidth) : 0); - - CRCType polynomial = static_cast(parameters.polynomial << SHIFT); - remainder = static_cast(remainder << SHIFT); - - while (size--) - { - remainder = static_cast(remainder ^ *current++); - - // An optimizing compiler might choose to unroll this loop. - for (crcpp_size i = 0; i < CHAR_BIT; ++i) - { -#ifdef CRCPP_BRANCHLESS - // Clever way to avoid a branch at the expense of a multiplication. This code is equivalent to the following: - // if (remainder & CHAR_BIT_HIGHEST_BIT_MASK) - // remainder = (remainder << 1) ^ polynomial; - // else - // remainder <<= 1; - remainder = static_cast((remainder << 1) ^ (((remainder >> CHAR_BIT_MINUS_ONE) & 1) * polynomial)); -#else - remainder = static_cast((remainder & CHAR_BIT_HIGHEST_BIT_MASK) ? ((remainder << 1) ^ polynomial) : (remainder << 1)); -#endif - } - } - - remainder = static_cast(remainder >> SHIFT); - } - - return remainder; -} - -/** - @brief Computes a CRC remainder using lookup table. - @param[in] data Data over which the remainder will be computed - @param[in] size Size of the data - @param[in] lookupTable CRC lookup table - @param[in] remainder Running CRC remainder. Can be an initial value or the result of a previous CRC remainder calculation. - @tparam CRCType Integer type for storing the CRC result - @tparam CRCWidth Number of bits in the CRC - @return CRC remainder -*/ -template -inline CRCType CRC::CalculateRemainder(const void * data, crcpp_size size, const Table & lookupTable, CRCType remainder) -{ - const unsigned char * current = reinterpret_cast(data); - - if (lookupTable.GetParameters().reflectInput) - { - while (size--) - { -#if defined(WIN32) || defined(_WIN32) || defined(WINCE) - // Disable warning about data loss when doing (remainder >> CHAR_BIT) when - // remainder is one byte long. The algorithm is still correct in this case, - // though it's possible that one additional machine instruction will be executed. -# pragma warning (push) -# pragma warning (disable : 4333) -#endif - remainder = static_cast((remainder >> CHAR_BIT) ^ lookupTable[static_cast(remainder ^ *current++)]); -#if defined(WIN32) || defined(_WIN32) || defined(WINCE) -# pragma warning (pop) -#endif - } - } - else if (CRCWidth >= CHAR_BIT) - { - // The conditional expression is used to avoid a -Wshift-count-overflow warning. - static crcpp_constexpr CRCType SHIFT((CRCWidth >= CHAR_BIT) ? static_cast(CRCWidth - CHAR_BIT) : 0); - - while (size--) - { - remainder = static_cast((remainder << CHAR_BIT) ^ lookupTable[static_cast((remainder >> SHIFT) ^ *current++)]); - } - } - else - { - // The conditional expression is used to avoid a -Wshift-count-overflow warning. - static crcpp_constexpr CRCType SHIFT((CHAR_BIT >= CRCWidth) ? static_cast(CHAR_BIT - CRCWidth) : 0); - - remainder = static_cast(remainder << SHIFT); - - while (size--) - { - // Note: no need to mask here since remainder is guaranteed to fit in a single byte. - remainder = lookupTable[static_cast(remainder ^ *current++)]; - } - - remainder = static_cast(remainder >> SHIFT); - } - - return remainder; -} - -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS -/** - @brief Returns a set of parameters for CRC-4 ITU. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-4 ITU has the following parameters and check value: - - polynomial = 0x3 - - initial value = 0x0 - - final XOR = 0x0 - - reflect input = true - - reflect output = true - - check value = 0x7 - @return CRC-4 ITU parameters -*/ -inline const CRC::Parameters & CRC::CRC_4_ITU() -{ - static const Parameters parameters = { 0x3, 0x0, 0x0, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-5 EPC. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-5 EPC has the following parameters and check value: - - polynomial = 0x09 - - initial value = 0x09 - - final XOR = 0x00 - - reflect input = false - - reflect output = false - - check value = 0x00 - @return CRC-5 EPC parameters -*/ -inline const CRC::Parameters & CRC::CRC_5_EPC() -{ - static const Parameters parameters = { 0x09, 0x09, 0x00, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-5 ITU. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-5 ITU has the following parameters and check value: - - polynomial = 0x15 - - initial value = 0x00 - - final XOR = 0x00 - - reflect input = true - - reflect output = true - - check value = 0x07 - @return CRC-5 ITU parameters -*/ -inline const CRC::Parameters & CRC::CRC_5_ITU() -{ - static const Parameters parameters = { 0x15, 0x00, 0x00, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-5 USB. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-5 USB has the following parameters and check value: - - polynomial = 0x05 - - initial value = 0x1F - - final XOR = 0x1F - - reflect input = true - - reflect output = true - - check value = 0x19 - @return CRC-5 USB parameters -*/ -inline const CRC::Parameters & CRC::CRC_5_USB() -{ - static const Parameters parameters = { 0x05, 0x1F, 0x1F, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-6 CDMA2000-A. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-6 CDMA2000-A has the following parameters and check value: - - polynomial = 0x27 - - initial value = 0x3F - - final XOR = 0x00 - - reflect input = false - - reflect output = false - - check value = 0x0D - @return CRC-6 CDMA2000-A parameters -*/ -inline const CRC::Parameters & CRC::CRC_6_CDMA2000A() -{ - static const Parameters parameters = { 0x27, 0x3F, 0x00, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-6 CDMA2000-B. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-6 CDMA2000-A has the following parameters and check value: - - polynomial = 0x07 - - initial value = 0x3F - - final XOR = 0x00 - - reflect input = false - - reflect output = false - - check value = 0x3B - @return CRC-6 CDMA2000-B parameters -*/ -inline const CRC::Parameters & CRC::CRC_6_CDMA2000B() -{ - static const Parameters parameters = { 0x07, 0x3F, 0x00, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-6 ITU. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-6 ITU has the following parameters and check value: - - polynomial = 0x03 - - initial value = 0x00 - - final XOR = 0x00 - - reflect input = true - - reflect output = true - - check value = 0x06 - @return CRC-6 ITU parameters -*/ -inline const CRC::Parameters & CRC::CRC_6_ITU() -{ - static const Parameters parameters = { 0x03, 0x00, 0x00, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-7 JEDEC. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-7 JEDEC has the following parameters and check value: - - polynomial = 0x09 - - initial value = 0x00 - - final XOR = 0x00 - - reflect input = false - - reflect output = false - - check value = 0x75 - @return CRC-7 JEDEC parameters -*/ -inline const CRC::Parameters & CRC::CRC_7() -{ - static const Parameters parameters = { 0x09, 0x00, 0x00, false, false }; - return parameters; -} -#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - -/** - @brief Returns a set of parameters for CRC-8 SMBus. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-8 SMBus has the following parameters and check value: - - polynomial = 0x07 - - initial value = 0x00 - - final XOR = 0x00 - - reflect input = false - - reflect output = false - - check value = 0xF4 - @return CRC-8 SMBus parameters -*/ -inline const CRC::Parameters & CRC::CRC_8() -{ - static const Parameters parameters = { 0x07, 0x00, 0x00, false, false }; - return parameters; -} - -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS -/** - @brief Returns a set of parameters for CRC-8 EBU (aka CRC-8 AES). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-8 EBU has the following parameters and check value: - - polynomial = 0x1D - - initial value = 0xFF - - final XOR = 0x00 - - reflect input = true - - reflect output = true - - check value = 0x97 - @return CRC-8 EBU parameters -*/ -inline const CRC::Parameters & CRC::CRC_8_EBU() -{ - static const Parameters parameters = { 0x1D, 0xFF, 0x00, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-8 MAXIM (aka CRC-8 DOW-CRC). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-8 MAXIM has the following parameters and check value: - - polynomial = 0x31 - - initial value = 0x00 - - final XOR = 0x00 - - reflect input = true - - reflect output = true - - check value = 0xA1 - @return CRC-8 MAXIM parameters -*/ -inline const CRC::Parameters & CRC::CRC_8_MAXIM() -{ - static const Parameters parameters = { 0x31, 0x00, 0x00, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-8 WCDMA. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-8 WCDMA has the following parameters and check value: - - polynomial = 0x9B - - initial value = 0x00 - - final XOR = 0x00 - - reflect input = true - - reflect output = true - - check value = 0x25 - @return CRC-8 WCDMA parameters -*/ -inline const CRC::Parameters & CRC::CRC_8_WCDMA() -{ - static const Parameters parameters = { 0x9B, 0x00, 0x00, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-10 ITU. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-10 ITU has the following parameters and check value: - - polynomial = 0x233 - - initial value = 0x000 - - final XOR = 0x000 - - reflect input = false - - reflect output = false - - check value = 0x199 - @return CRC-10 ITU parameters -*/ -inline const CRC::Parameters & CRC::CRC_10() -{ - static const Parameters parameters = { 0x233, 0x000, 0x000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-10 CDMA2000. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-10 CDMA2000 has the following parameters and check value: - - polynomial = 0x3D9 - - initial value = 0x3FF - - final XOR = 0x000 - - reflect input = false - - reflect output = false - - check value = 0x233 - @return CRC-10 CDMA2000 parameters -*/ -inline const CRC::Parameters & CRC::CRC_10_CDMA2000() -{ - static const Parameters parameters = { 0x3D9, 0x3FF, 0x000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-11 FlexRay. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-11 FlexRay has the following parameters and check value: - - polynomial = 0x385 - - initial value = 0x01A - - final XOR = 0x000 - - reflect input = false - - reflect output = false - - check value = 0x5A3 - @return CRC-11 FlexRay parameters -*/ -inline const CRC::Parameters & CRC::CRC_11() -{ - static const Parameters parameters = { 0x385, 0x01A, 0x000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-12 CDMA2000. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-12 CDMA2000 has the following parameters and check value: - - polynomial = 0xF13 - - initial value = 0xFFF - - final XOR = 0x000 - - reflect input = false - - reflect output = false - - check value = 0xD4D - @return CRC-12 CDMA2000 parameters -*/ -inline const CRC::Parameters & CRC::CRC_12_CDMA2000() -{ - static const Parameters parameters = { 0xF13, 0xFFF, 0x000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-12 DECT (aka CRC-12 X-CRC). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-12 DECT has the following parameters and check value: - - polynomial = 0x80F - - initial value = 0x000 - - final XOR = 0x000 - - reflect input = false - - reflect output = false - - check value = 0xF5B - @return CRC-12 DECT parameters -*/ -inline const CRC::Parameters & CRC::CRC_12_DECT() -{ - static const Parameters parameters = { 0x80F, 0x000, 0x000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-12 UMTS (aka CRC-12 3GPP). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-12 UMTS has the following parameters and check value: - - polynomial = 0x80F - - initial value = 0x000 - - final XOR = 0x000 - - reflect input = false - - reflect output = true - - check value = 0xDAF - @return CRC-12 UMTS parameters -*/ -inline const CRC::Parameters & CRC::CRC_12_UMTS() -{ - static const Parameters parameters = { 0x80F, 0x000, 0x000, false, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-13 BBC. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-13 BBC has the following parameters and check value: - - polynomial = 0x1CF5 - - initial value = 0x0000 - - final XOR = 0x0000 - - reflect input = false - - reflect output = false - - check value = 0x04FA - @return CRC-13 BBC parameters -*/ -inline const CRC::Parameters & CRC::CRC_13_BBC() -{ - static const Parameters parameters = { 0x1CF5, 0x0000, 0x0000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-15 CAN. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-15 CAN has the following parameters and check value: - - polynomial = 0x4599 - - initial value = 0x0000 - - final XOR = 0x0000 - - reflect input = false - - reflect output = false - - check value = 0x059E - @return CRC-15 CAN parameters -*/ -inline const CRC::Parameters & CRC::CRC_15() -{ - static const Parameters parameters = { 0x4599, 0x0000, 0x0000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-15 MPT1327. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-15 MPT1327 has the following parameters and check value: - - polynomial = 0x6815 - - initial value = 0x0000 - - final XOR = 0x0001 - - reflect input = false - - reflect output = false - - check value = 0x2566 - @return CRC-15 MPT1327 parameters -*/ -inline const CRC::Parameters & CRC::CRC_15_MPT1327() -{ - static const Parameters parameters = { 0x6815, 0x0000, 0x0001, false, false }; - return parameters; -} -#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - -/** - @brief Returns a set of parameters for CRC-16 ARC (aka CRC-16 IBM, CRC-16 LHA). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 ARC has the following parameters and check value: - - polynomial = 0x8005 - - initial value = 0x0000 - - final XOR = 0x0000 - - reflect input = true - - reflect output = true - - check value = 0xBB3D - @return CRC-16 ARC parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_ARC() -{ - static const Parameters parameters = { 0x8005, 0x0000, 0x0000, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-16 BUYPASS (aka CRC-16 VERIFONE, CRC-16 UMTS). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 BUYPASS has the following parameters and check value: - - polynomial = 0x8005 - - initial value = 0x0000 - - final XOR = 0x0000 - - reflect input = false - - reflect output = false - - check value = 0xFEE8 - @return CRC-16 BUYPASS parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_BUYPASS() -{ - static const Parameters parameters = { 0x8005, 0x0000, 0x0000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-16 CCITT FALSE. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 CCITT FALSE has the following parameters and check value: - - polynomial = 0x1021 - - initial value = 0xFFFF - - final XOR = 0x0000 - - reflect input = false - - reflect output = false - - check value = 0x29B1 - @return CRC-16 CCITT FALSE parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_CCITTFALSE() -{ - static const Parameters parameters = { 0x1021, 0xFFFF, 0x0000, false, false }; - return parameters; -} - -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS -/** - @brief Returns a set of parameters for CRC-16 CDMA2000. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 CDMA2000 has the following parameters and check value: - - polynomial = 0xC867 - - initial value = 0xFFFF - - final XOR = 0x0000 - - reflect input = false - - reflect output = false - - check value = 0x4C06 - @return CRC-16 CDMA2000 parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_CDMA2000() -{ - static const Parameters parameters = { 0xC867, 0xFFFF, 0x0000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-16 CMS. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 CMS has the following parameters and check value: - - polynomial = 0x8005 - - initial value = 0xFFFF - - final XOR = 0x0000 - - reflect input = false - - reflect output = false - - check value = 0xAEE7 - @return CRC-16 CMS parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_CMS() -{ - static const Parameters parameters = { 0x8005, 0xFFFF, 0x0000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-16 DECT-R (aka CRC-16 R-CRC). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 DECT-R has the following parameters and check value: - - polynomial = 0x0589 - - initial value = 0x0000 - - final XOR = 0x0001 - - reflect input = false - - reflect output = false - - check value = 0x007E - @return CRC-16 DECT-R parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_DECTR() -{ - static const Parameters parameters = { 0x0589, 0x0000, 0x0001, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-16 DECT-X (aka CRC-16 X-CRC). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 DECT-X has the following parameters and check value: - - polynomial = 0x0589 - - initial value = 0x0000 - - final XOR = 0x0000 - - reflect input = false - - reflect output = false - - check value = 0x007F - @return CRC-16 DECT-X parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_DECTX() -{ - static const Parameters parameters = { 0x0589, 0x0000, 0x0000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-16 DNP. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 DNP has the following parameters and check value: - - polynomial = 0x3D65 - - initial value = 0x0000 - - final XOR = 0xFFFF - - reflect input = true - - reflect output = true - - check value = 0xEA82 - @return CRC-16 DNP parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_DNP() -{ - static const Parameters parameters = { 0x3D65, 0x0000, 0xFFFF, true, true }; - return parameters; -} -#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - -/** - @brief Returns a set of parameters for CRC-16 GENIBUS (aka CRC-16 EPC, CRC-16 I-CODE, CRC-16 DARC). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 GENIBUS has the following parameters and check value: - - polynomial = 0x1021 - - initial value = 0xFFFF - - final XOR = 0xFFFF - - reflect input = false - - reflect output = false - - check value = 0xD64E - @return CRC-16 GENIBUS parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_GENIBUS() -{ - static const Parameters parameters = { 0x1021, 0xFFFF, 0xFFFF, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-16 KERMIT (aka CRC-16 CCITT, CRC-16 CCITT-TRUE). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 KERMIT has the following parameters and check value: - - polynomial = 0x1021 - - initial value = 0x0000 - - final XOR = 0x0000 - - reflect input = true - - reflect output = true - - check value = 0x2189 - @return CRC-16 KERMIT parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_KERMIT() -{ - static const Parameters parameters = { 0x1021, 0x0000, 0x0000, true, true }; - return parameters; -} - -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS -/** - @brief Returns a set of parameters for CRC-16 MAXIM. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 MAXIM has the following parameters and check value: - - polynomial = 0x8005 - - initial value = 0x0000 - - final XOR = 0xFFFF - - reflect input = true - - reflect output = true - - check value = 0x44C2 - @return CRC-16 MAXIM parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_MAXIM() -{ - static const Parameters parameters = { 0x8005, 0x0000, 0xFFFF, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-16 MODBUS. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 MODBUS has the following parameters and check value: - - polynomial = 0x8005 - - initial value = 0xFFFF - - final XOR = 0x0000 - - reflect input = true - - reflect output = true - - check value = 0x4B37 - @return CRC-16 MODBUS parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_MODBUS() -{ - static const Parameters parameters = { 0x8005, 0xFFFF, 0x0000, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-16 T10-DIF. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 T10-DIF has the following parameters and check value: - - polynomial = 0x8BB7 - - initial value = 0x0000 - - final XOR = 0x0000 - - reflect input = false - - reflect output = false - - check value = 0xD0DB - @return CRC-16 T10-DIF parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_T10DIF() -{ - static const Parameters parameters = { 0x8BB7, 0x0000, 0x0000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-16 USB. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 USB has the following parameters and check value: - - polynomial = 0x8005 - - initial value = 0xFFFF - - final XOR = 0xFFFF - - reflect input = true - - reflect output = true - - check value = 0xB4C8 - @return CRC-16 USB parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_USB() -{ - static const Parameters parameters = { 0x8005, 0xFFFF, 0xFFFF, true, true }; - return parameters; -} - -#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - -/** - @brief Returns a set of parameters for CRC-16 X-25 (aka CRC-16 IBM-SDLC, CRC-16 ISO-HDLC, CRC-16 B). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 X-25 has the following parameters and check value: - - polynomial = 0x1021 - - initial value = 0xFFFF - - final XOR = 0xFFFF - - reflect input = true - - reflect output = true - - check value = 0x906E - @return CRC-16 X-25 parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_X25() -{ - static const Parameters parameters = { 0x1021, 0xFFFF, 0xFFFF, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-16 XMODEM (aka CRC-16 ZMODEM, CRC-16 ACORN, CRC-16 LTE). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-16 XMODEM has the following parameters and check value: - - polynomial = 0x1021 - - initial value = 0x0000 - - final XOR = 0x0000 - - reflect input = false - - reflect output = false - - check value = 0x31C3 - @return CRC-16 XMODEM parameters -*/ -inline const CRC::Parameters & CRC::CRC_16_XMODEM() -{ - static const Parameters parameters = { 0x1021, 0x0000, 0x0000, false, false }; - return parameters; -} - -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS -/** - @brief Returns a set of parameters for CRC-17 CAN. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-17 CAN has the following parameters and check value: - - polynomial = 0x1685B - - initial value = 0x00000 - - final XOR = 0x00000 - - reflect input = false - - reflect output = false - - check value = 0x04F03 - @return CRC-17 CAN parameters -*/ -inline const CRC::Parameters & CRC::CRC_17_CAN() -{ - static const Parameters parameters = { 0x1685B, 0x00000, 0x00000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-21 CAN. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-21 CAN has the following parameters and check value: - - polynomial = 0x102899 - - initial value = 0x000000 - - final XOR = 0x000000 - - reflect input = false - - reflect output = false - - check value = 0x0ED841 - @return CRC-21 CAN parameters -*/ -inline const CRC::Parameters & CRC::CRC_21_CAN() -{ - static const Parameters parameters = { 0x102899, 0x000000, 0x000000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-24 OPENPGP. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-24 OPENPGP has the following parameters and check value: - - polynomial = 0x864CFB - - initial value = 0xB704CE - - final XOR = 0x000000 - - reflect input = false - - reflect output = false - - check value = 0x21CF02 - @return CRC-24 OPENPGP parameters -*/ -inline const CRC::Parameters & CRC::CRC_24() -{ - static const Parameters parameters = { 0x864CFB, 0xB704CE, 0x000000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-24 FlexRay-A. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-24 FlexRay-A has the following parameters and check value: - - polynomial = 0x5D6DCB - - initial value = 0xFEDCBA - - final XOR = 0x000000 - - reflect input = false - - reflect output = false - - check value = 0x7979BD - @return CRC-24 FlexRay-A parameters -*/ -inline const CRC::Parameters & CRC::CRC_24_FLEXRAYA() -{ - static const Parameters parameters = { 0x5D6DCB, 0xFEDCBA, 0x000000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-24 FlexRay-B. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-24 FlexRay-B has the following parameters and check value: - - polynomial = 0x5D6DCB - - initial value = 0xABCDEF - - final XOR = 0x000000 - - reflect input = false - - reflect output = false - - check value = 0x1F23B8 - @return CRC-24 FlexRay-B parameters -*/ -inline const CRC::Parameters & CRC::CRC_24_FLEXRAYB() -{ - static const Parameters parameters = { 0x5D6DCB, 0xABCDEF, 0x000000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-30 CDMA. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-30 CDMA has the following parameters and check value: - - polynomial = 0x2030B9C7 - - initial value = 0x3FFFFFFF - - final XOR = 0x00000000 - - reflect input = false - - reflect output = false - - check value = 0x3B3CB540 - @return CRC-30 CDMA parameters -*/ -inline const CRC::Parameters & CRC::CRC_30() -{ - static const Parameters parameters = { 0x2030B9C7, 0x3FFFFFFF, 0x00000000, false, false }; - return parameters; -} -#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - -/** - @brief Returns a set of parameters for CRC-32 (aka CRC-32 ADCCP, CRC-32 PKZip). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-32 has the following parameters and check value: - - polynomial = 0x04C11DB7 - - initial value = 0xFFFFFFFF - - final XOR = 0xFFFFFFFF - - reflect input = true - - reflect output = true - - check value = 0xCBF43926 - @return CRC-32 parameters -*/ -inline const CRC::Parameters & CRC::CRC_32() -{ - static const Parameters parameters = { 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-32 BZIP2 (aka CRC-32 AAL5, CRC-32 DECT-B, CRC-32 B-CRC). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-32 BZIP2 has the following parameters and check value: - - polynomial = 0x04C11DB7 - - initial value = 0xFFFFFFFF - - final XOR = 0xFFFFFFFF - - reflect input = false - - reflect output = false - - check value = 0xFC891918 - @return CRC-32 BZIP2 parameters -*/ -inline const CRC::Parameters & CRC::CRC_32_BZIP2() -{ - static const Parameters parameters = { 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, false, false }; - return parameters; -} - -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS -/** - @brief Returns a set of parameters for CRC-32 C (aka CRC-32 ISCSI, CRC-32 Castagnoli, CRC-32 Interlaken). - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-32 C has the following parameters and check value: - - polynomial = 0x1EDC6F41 - - initial value = 0xFFFFFFFF - - final XOR = 0xFFFFFFFF - - reflect input = true - - reflect output = true - - check value = 0xE3069283 - @return CRC-32 C parameters -*/ -inline const CRC::Parameters & CRC::CRC_32_C() -{ - static const Parameters parameters = { 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true }; - return parameters; -} -#endif - -/** - @brief Returns a set of parameters for CRC-32 MPEG-2. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-32 MPEG-2 has the following parameters and check value: - - polynomial = 0x04C11DB7 - - initial value = 0xFFFFFFFF - - final XOR = 0x00000000 - - reflect input = false - - reflect output = false - - check value = 0x0376E6E7 - @return CRC-32 MPEG-2 parameters -*/ -inline const CRC::Parameters & CRC::CRC_32_MPEG2() -{ - static const Parameters parameters = { 0x04C11DB7, 0xFFFFFFFF, 0x00000000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-32 POSIX. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-32 POSIX has the following parameters and check value: - - polynomial = 0x04C11DB7 - - initial value = 0x00000000 - - final XOR = 0xFFFFFFFF - - reflect input = false - - reflect output = false - - check value = 0x765E7680 - @return CRC-32 POSIX parameters -*/ -inline const CRC::Parameters & CRC::CRC_32_POSIX() -{ - static const Parameters parameters = { 0x04C11DB7, 0x00000000, 0xFFFFFFFF, false, false }; - return parameters; -} - -#ifdef CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS -/** - @brief Returns a set of parameters for CRC-32 Q. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-32 Q has the following parameters and check value: - - polynomial = 0x814141AB - - initial value = 0x00000000 - - final XOR = 0x00000000 - - reflect input = false - - reflect output = false - - check value = 0x3010BF7F - @return CRC-32 Q parameters -*/ -inline const CRC::Parameters & CRC::CRC_32_Q() -{ - static const Parameters parameters = { 0x814141AB, 0x00000000, 0x00000000, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-40 GSM. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-40 GSM has the following parameters and check value: - - polynomial = 0x0004820009 - - initial value = 0x0000000000 - - final XOR = 0xFFFFFFFFFF - - reflect input = false - - reflect output = false - - check value = 0xD4164FC646 - @return CRC-40 GSM parameters -*/ -inline const CRC::Parameters & CRC::CRC_40_GSM() -{ - static const Parameters parameters = { 0x0004820009, 0x0000000000, 0xFFFFFFFFFF, false, false }; - return parameters; -} - -/** - @brief Returns a set of parameters for CRC-64 ECMA. - @note The parameters are static and are delayed-constructed to reduce memory footprint. - @note CRC-64 ECMA has the following parameters and check value: - - polynomial = 0x42F0E1EBA9EA3693 - - initial value = 0x0000000000000000 - - final XOR = 0x0000000000000000 - - reflect input = false - - reflect output = false - - check value = 0x6C40DF5F0B497347 - @return CRC-64 ECMA parameters -*/ -inline const CRC::Parameters & CRC::CRC_64() -{ - static const Parameters parameters = { 0x42F0E1EBA9EA3693, 0x0000000000000000, 0x0000000000000000, false, false }; - return parameters; -} -#endif // CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS - -#ifdef CRCPP_USE_NAMESPACE -} -#endif - -#endif // CRCPP_CRC_H_ diff --git a/src/tools/codeeditor/codeeditor.cpp b/src/tools/codeeditor/codeeditor.cpp index 62096942e..00dfc66d3 100644 --- a/src/tools/codeeditor/codeeditor.cpp +++ b/src/tools/codeeditor/codeeditor.cpp @@ -96,10 +96,6 @@ void mainLoop() { setAppTitle( docDirtyState ? curFile + "*" : curFile ); } - if ( ( input->isControlPressed() && input->isKeyUp( KEY_O ) ) || input->isKeyUp( KEY_F2 ) ) { - openFileDialog(); - } - if ( input->isKeyUp( KEY_F6 ) ) { uiSceneNode->setHighlightFocus( !uiSceneNode->getHighlightFocus() ); uiSceneNode->setHighlightOver( !uiSceneNode->getHighlightOver() ); @@ -113,21 +109,10 @@ void mainLoop() { uiSceneNode->setDrawDebugData( !uiSceneNode->getDrawDebugData() ); } - if ( input->isAltPressed() && input->isKeyUp( KEY_RETURN ) ) { - win->toggleFullscreen(); - } - - if ( input->isScancodeUp( SCANCODE_GRAVE ) ) { - console->toggle(); - } - - if ( input->isControlPressed() && input->isKeyUp( KEY_L ) ) { - codeEditor->setLocked( !codeEditor->isLocked() ); - } - SceneManager::instance()->update(); - if ( SceneManager::instance()->getUISceneNode()->invalidated() ) { + if ( SceneManager::instance()->getUISceneNode()->invalidated() || console->isActive() || + console->isFading() ) { win->clear(); SceneManager::instance()->draw(); console->draw(); @@ -219,11 +204,21 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { codeEditor->getDocument().setCommand( "find", []() { findTextMessageBox(); } ); codeEditor->getDocument().setCommand( "repeat-find", []() { findText(); } ); codeEditor->getDocument().setCommand( "close-app", []() { closeApp(); } ); - codeEditor->addKeyBindingString( "ctrl+s", "save" ); - codeEditor->addKeyBindingString( "ctrl+f", "find" ); - codeEditor->addKeyBindingString( "f3", "repeat-find" ); - codeEditor->addKeyBindingString( "escape", "close-app" ); - codeEditor->addKeyBindingString( "ctrl+q", "close-app" ); + codeEditor->getDocument().setCommand( "fullscreen-toggle", + []() { win->toggleFullscreen(); } ); + codeEditor->getDocument().setCommand( "open-file", [] { openFileDialog(); } ); + codeEditor->getDocument().setCommand( "console-toggle", [] { console->toggle(); } ); + codeEditor->addKeyBindingString( "ctrl+s", "save", false ); + codeEditor->addKeyBindingString( "ctrl+f", "find", false ); + codeEditor->addKeyBindingString( "f3", "repeat-find", false ); + codeEditor->addKeyBindingString( "escape", "close-app", true ); + codeEditor->addKeyBindingString( "ctrl+q", "close-app", true ); + codeEditor->addKeyBindingString( "alt+return", "fullscreen-toggle", true ); + codeEditor->addKeyBindingString( "ctrl+o", "open-file", true ); + codeEditor->addKeyBindingString( "f2", "open-file", true ); + codeEditor->addKeyBindingString( "ctrl+l", "lock-toggle", true ); + codeEditor->addKeyBinding( {win->getInput()->getKeyFromScancode( SCANCODE_GRAVE ), 0}, + "console-toggle", true ); codeEditor->setFocus();