On Fri, Oct 04, 2024 at 12:51:56PM +0200, Enrico Forestieri wrote: > On Fri, Oct 04, 2024 at 11:52:01AM +0200, Pavel Sanda wrote: > > > > I am all for ditching trivstring, but it all depends on Enrico's stance, > > I didn't > > folow the previous discussion on strings and COW, so I have little idea > > what is the right course of action. > > Cygwin does not need trivstring. It was using the implementation in > src/support/trivstring.cpp simply because we wrongly decide that std::string > implementation uses cow when _GLIBCXX_USE_CXX11_ABI is set. > > I think that if we ditch trivstring we don't need to set > STD_STRING_USES_COW. In this case, the patch I proposed to check whether cow > is actually used or not will also not be necessary.
So are you able to compile on cygwin after these two patches applied on top of each other (first strfwd out, then trivstring out)? Pavel
diff --git a/development/cmake/configCompiler.h.msvc b/development/cmake/configCompiler.h.msvc index bec1a4113c..771286af9f 100644 --- a/development/cmake/configCompiler.h.msvc +++ b/development/cmake/configCompiler.h.msvc @@ -168,9 +168,4 @@ #define HAVE_MODE_T #endif -#if defined(_MSC_VER) && (_MSC_VER >= 1600) -#include "support/strfwd.h" // always first, to prevent compiler's interpretation/instantiations of some typedef -#endif - - #endif diff --git a/src/Box.h b/src/Box.h index 9522ad0a79..e0aa633b43 100644 --- a/src/Box.h +++ b/src/Box.h @@ -12,7 +12,7 @@ #ifndef BOX_H #define BOX_H -#include "support/strfwd.h" +#include <ostream> namespace lyx { diff --git a/src/Buffer.h b/src/Buffer.h index d4e8db8748..fa240a4cbf 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -16,13 +16,12 @@ #include "OutputEnums.h" #include "support/unique_ptr.h" -#include "support/strfwd.h" +#include "support/docstring.h" #include "support/types.h" #include <map> #include <list> #include <set> -#include <string> #include <vector> diff --git a/src/BufferEncodings.h b/src/BufferEncodings.h index d5a9081f09..917a8371a1 100644 --- a/src/BufferEncodings.h +++ b/src/BufferEncodings.h @@ -16,8 +16,6 @@ #include "Encoding.h" -#include "support/strfwd.h" - namespace lyx { class Buffer; diff --git a/src/BufferList.h b/src/BufferList.h index ff5156657b..1384467c73 100644 --- a/src/BufferList.h +++ b/src/BufferList.h @@ -12,8 +12,7 @@ #ifndef BUFFER_LIST_H #define BUFFER_LIST_H -#include "support/strfwd.h" - +#include <string> #include <vector> diff --git a/src/BufferView.h b/src/BufferView.h index 0f673e38e6..deeeb7061b 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -20,7 +20,6 @@ #include "TexRow.h" #include "update_flags.h" -#include "support/strfwd.h" #include "support/types.h" namespace lyx { diff --git a/src/Changes.h b/src/Changes.h index d53887556d..1bad1b2bc0 100644 --- a/src/Changes.h +++ b/src/Changes.h @@ -15,7 +15,6 @@ #ifndef CHANGES_H #define CHANGES_H -#include "support/strfwd.h" #include "support/types.h" #include "support/lyxtime.h" diff --git a/src/Citation.h b/src/Citation.h index 747599d5f8..4be8c3f09a 100644 --- a/src/Citation.h +++ b/src/Citation.h @@ -13,7 +13,6 @@ #define CITATION_H #include "support/docstring.h" -#include <string> #include <vector> namespace lyx { diff --git a/src/CmdDef.h b/src/CmdDef.h index 946730e64e..e250015bee 100644 --- a/src/CmdDef.h +++ b/src/CmdDef.h @@ -12,10 +12,9 @@ #ifndef CMDDEF_H #define CMDDEF_H -#include "support/strfwd.h" - #include <map> #include <set> +#include <string> namespace lyx { diff --git a/src/Color.h b/src/Color.h index d67c4989a7..e85efbfbae 100644 --- a/src/Color.h +++ b/src/Color.h @@ -21,7 +21,7 @@ #include "ColorCode.h" -#include "support/strfwd.h" +#include <string> namespace lyx { diff --git a/src/ColorSet.h b/src/ColorSet.h index c1de480f4f..88684079ba 100644 --- a/src/ColorSet.h +++ b/src/ColorSet.h @@ -19,10 +19,10 @@ #ifndef COLORSET_H #define COLORSET_H +#include "support/docstring.h" #include "Color.h" #include <map> -#include <string> namespace lyx { diff --git a/src/Converter.h b/src/Converter.h index 720990013a..c1abe62fee 100644 --- a/src/Converter.h +++ b/src/Converter.h @@ -13,12 +13,11 @@ #define CONVERTER_H #include "Graph.h" -#include "support/trivstring.h" +#include "support/docstring.h" #include <memory> #include <vector> #include <set> -#include <string> namespace lyx { diff --git a/src/ConverterCache.h b/src/ConverterCache.h index 72afe293e5..46176c70bf 100644 --- a/src/ConverterCache.h +++ b/src/ConverterCache.h @@ -21,7 +21,7 @@ #ifndef CONVERTERCACHE_H #define CONVERTERCACHE_H -#include "support/strfwd.h" +#include <string> namespace lyx { diff --git a/src/CursorSlice.h b/src/CursorSlice.h index eb865de948..6eb6ff5aba 100644 --- a/src/CursorSlice.h +++ b/src/CursorSlice.h @@ -18,7 +18,6 @@ #define CURSORSLICE_H #include "support/types.h" -#include "support/strfwd.h" #include "insets/Inset.h" diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index 0692afe596..edea773321 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -17,7 +17,6 @@ #include "Author.h" #include "DocumentClassPtr.h" -#include "support/strfwd.h" #include "support/types.h" #include "frontends/Clipboard.h" diff --git a/src/ErrorList.h b/src/ErrorList.h index 29cb03cfe6..267c2f82d0 100644 --- a/src/ErrorList.h +++ b/src/ErrorList.h @@ -14,8 +14,6 @@ #include "TexRow.h" -#include "support/strfwd.h" - #include <vector> diff --git a/src/Floating.h b/src/Floating.h index ab57c4dd94..6fabe729ce 100644 --- a/src/Floating.h +++ b/src/Floating.h @@ -12,10 +12,7 @@ #ifndef FLOATING_H #define FLOATING_H -#include "support/strfwd.h" - -#include <string> - +#include "support/docstring.h" namespace lyx { diff --git a/src/Font.h b/src/Font.h index b59f015eca..61e2a535b0 100644 --- a/src/Font.h +++ b/src/Font.h @@ -17,8 +17,6 @@ #include "FontInfo.h" -#include "support/strfwd.h" - namespace lyx { diff --git a/src/FontInfo.cpp b/src/FontInfo.cpp index b6f45f88b5..86e995e6d3 100644 --- a/src/FontInfo.cpp +++ b/src/FontInfo.cpp @@ -27,7 +27,6 @@ #include "support/lstrings.h" #include <algorithm> -#include <ostream> #include <sstream> using namespace std; diff --git a/src/FontInfo.h b/src/FontInfo.h index bd0f125a7a..008504653e 100644 --- a/src/FontInfo.h +++ b/src/FontInfo.h @@ -20,7 +20,7 @@ #include "FontEnums.h" #include "support/Changer.h" -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/Format.h b/src/Format.h index d1d6d74183..9895b0193b 100644 --- a/src/Format.h +++ b/src/Format.h @@ -12,11 +12,9 @@ #ifndef FORMAT_H #define FORMAT_H -#include "support/strfwd.h" -#include "support/trivstring.h" +#include "support/docstring.h" #include <vector> -#include <string> namespace lyx { diff --git a/src/KeyMap.h b/src/KeyMap.h index ac9de6298b..9644835224 100644 --- a/src/KeyMap.h +++ b/src/KeyMap.h @@ -17,8 +17,6 @@ #include "FuncRequest.h" #include "KeySequence.h" -#include "support/strfwd.h" - #include <memory> #include <vector> diff --git a/src/LaTeX.h b/src/LaTeX.h index 502834348b..185b9ebdd9 100644 --- a/src/LaTeX.h +++ b/src/LaTeX.h @@ -16,7 +16,6 @@ #include "OutputParams.h" -#include "support/strfwd.h" #include "support/FileName.h" #include "support/signals.h" diff --git a/src/Layout.h b/src/Layout.h index c8f08439f5..421ab239fd 100644 --- a/src/Layout.h +++ b/src/Layout.h @@ -22,7 +22,6 @@ #include <map> #include <set> -#include <string> namespace lyx { diff --git a/src/LayoutFile.h b/src/LayoutFile.h index 87548187ed..ad7effdab6 100644 --- a/src/LayoutFile.h +++ b/src/LayoutFile.h @@ -15,8 +15,6 @@ #include "TextClass.h" -#include "support/strfwd.h" - #include <string> #include <vector> diff --git a/src/LyX.h b/src/LyX.h index c35464e210..b7c71ce660 100644 --- a/src/LyX.h +++ b/src/LyX.h @@ -14,8 +14,7 @@ #ifndef LYX_H #define LYX_H -#include "support/strfwd.h" - +#include <string> #include <vector> namespace lyx { diff --git a/src/LyXRC.h b/src/LyXRC.h index a8b4b04452..8c34712d90 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -22,7 +22,6 @@ #include "update_flags.h" #include "support/Length.h" -#include "support/strfwd.h" #include "support/userinfo.h" #include <map> diff --git a/src/LyXVC.h b/src/LyXVC.h index fd22357017..48e544808f 100644 --- a/src/LyXVC.h +++ b/src/LyXVC.h @@ -15,8 +15,6 @@ #include "support/docstring.h" #include "support/unique_ptr.h" -#include <string> - namespace lyx { diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h index 6f1d404822..48d313ba71 100644 --- a/src/MetricsInfo.h +++ b/src/MetricsInfo.h @@ -17,7 +17,6 @@ #include "ColorCode.h" #include "FontInfo.h" -#include "support/strfwd.h" #include "support/Changer.h" #include "insets/Inset.h" diff --git a/src/PDFOptions.cpp b/src/PDFOptions.cpp index c3d057eba8..6a7c80144a 100644 --- a/src/PDFOptions.cpp +++ b/src/PDFOptions.cpp @@ -26,7 +26,6 @@ #include "support/lstrings.h" #include <sstream> -#include <string> #include <algorithm> using namespace std; diff --git a/src/Paragraph.h b/src/Paragraph.h index 0de720e2d8..467054499c 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -19,7 +19,6 @@ #include "LayoutEnums.h" #include "SpellChecker.h" -#include "support/strfwd.h" #include "support/types.h" #include "insets/InsetCode.h" diff --git a/src/ParagraphParameters.h b/src/ParagraphParameters.h index 6f5b4f1b3f..540ea95679 100644 --- a/src/ParagraphParameters.h +++ b/src/ParagraphParameters.h @@ -18,7 +18,6 @@ #include "Spacing.h" #include "support/types.h" -#include "support/strfwd.h" #include "support/Length.h" diff --git a/src/PersonalWordList.h b/src/PersonalWordList.h index 0194bbcbe6..9abb3fd146 100644 --- a/src/PersonalWordList.h +++ b/src/PersonalWordList.h @@ -12,7 +12,6 @@ #ifndef PERSONAL_WORD_LIST_H #define PERSONAL_WORD_LIST_H -#include "support/strfwd.h" #include "support/docstring_list.h" #include "support/FileName.h" diff --git a/src/Spacing.h b/src/Spacing.h index 7311f792b5..d394b28b2b 100644 --- a/src/Spacing.h +++ b/src/Spacing.h @@ -12,8 +12,6 @@ #ifndef SPACING_H #define SPACING_H -#include "support/strfwd.h" - #include <string> namespace lyx { diff --git a/src/SpellChecker.h b/src/SpellChecker.h index 58e5de6bd2..fe8cb9dfc0 100644 --- a/src/SpellChecker.h +++ b/src/SpellChecker.h @@ -13,7 +13,7 @@ #ifndef SPELL_BASE_H #define SPELL_BASE_H -#include "support/strfwd.h" +#include "support/docstring.h" #include <vector> diff --git a/src/Statistics.h b/src/Statistics.h index 195af0382c..4ccd276752 100644 --- a/src/Statistics.h +++ b/src/Statistics.h @@ -12,7 +12,7 @@ #ifndef STATISTICS_H #define STATISTICS_H -#include "support/strfwd.h" +#include "support/docstring.h" #include "support/types.h" namespace lyx { diff --git a/src/TextClass.h b/src/TextClass.h index 7626dc329d..ef5ed7789e 100644 --- a/src/TextClass.h +++ b/src/TextClass.h @@ -26,7 +26,6 @@ #include <list> #include <map> #include <set> -#include <string> #include <vector> #ifdef ERROR diff --git a/src/Thesaurus.h b/src/Thesaurus.h index 9c13b044cb..b85c81621c 100644 --- a/src/Thesaurus.h +++ b/src/Thesaurus.h @@ -13,7 +13,7 @@ #ifndef THESAURUS_H #define THESAURUS_H -#include "support/strfwd.h" +#include "support/docstring.h" #include <map> #include <vector> diff --git a/src/TocBackend.h b/src/TocBackend.h index 68eb825c6d..eefe7873c6 100644 --- a/src/TocBackend.h +++ b/src/TocBackend.h @@ -21,7 +21,6 @@ #include "Toc.h" #include "TocBuilder.h" -#include "support/strfwd.h" #include "support/unique_ptr.h" diff --git a/src/TocBuilder.h b/src/TocBuilder.h index eca655ca16..af9c41cb24 100644 --- a/src/TocBuilder.h +++ b/src/TocBuilder.h @@ -14,7 +14,7 @@ #include "Toc.h" -#include "support/strfwd.h" +#include "support/docstring.h" #include <stack> diff --git a/src/frontends/Application.h b/src/frontends/Application.h index 4d2d249b23..f52b124e2c 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -15,7 +15,7 @@ #include "FuncCode.h" #include "update_flags.h" -#include "support/strfwd.h" +#include "support/docstring.h" #include <functional> diff --git a/src/frontends/Clipboard.h b/src/frontends/Clipboard.h index 5e16a26bbf..13066eb279 100644 --- a/src/frontends/Clipboard.h +++ b/src/frontends/Clipboard.h @@ -14,8 +14,6 @@ #ifndef BASE_CLIPBOARD_H #define BASE_CLIPBOARD_H -#include "support/strfwd.h" - namespace lyx { class Cursor; diff --git a/src/frontends/Delegates.h b/src/frontends/Delegates.h index c50df6b33f..715505edc6 100644 --- a/src/frontends/Delegates.h +++ b/src/frontends/Delegates.h @@ -12,7 +12,7 @@ #ifndef DELEGATES_H #define DELEGATES_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/frontends/FontLoader.h b/src/frontends/FontLoader.h index e876e78200..c59885b77e 100644 --- a/src/frontends/FontLoader.h +++ b/src/frontends/FontLoader.h @@ -12,7 +12,7 @@ #ifndef FONTLOADER_H #define FONTLOADER_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/frontends/FontMetrics.h b/src/frontends/FontMetrics.h index c9a1d86cda..28e3dec4dd 100644 --- a/src/frontends/FontMetrics.h +++ b/src/frontends/FontMetrics.h @@ -16,7 +16,7 @@ #include "support/mute_warning.h" -#include "support/strfwd.h" +#include "support/docstring.h" #include <vector> diff --git a/src/frontends/Painter.h b/src/frontends/Painter.h index 60953341af..d408ca68b2 100644 --- a/src/frontends/Painter.h +++ b/src/frontends/Painter.h @@ -13,7 +13,7 @@ #ifndef PAINTER_H #define PAINTER_H -#include "support/strfwd.h" +#include "support/docstring.h" #include "support/types.h" namespace lyx { diff --git a/src/frontends/Selection.h b/src/frontends/Selection.h index 931cb4470e..1aba5bfdd2 100644 --- a/src/frontends/Selection.h +++ b/src/frontends/Selection.h @@ -14,7 +14,7 @@ #ifndef SELECTION_H #define SELECTION_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { namespace frontend { diff --git a/src/frontends/alert.h b/src/frontends/alert.h index a4556ca2d4..dd1318614f 100644 --- a/src/frontends/alert.h +++ b/src/frontends/alert.h @@ -12,7 +12,7 @@ #ifndef LYX_ALERT_H #define LYX_ALERT_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/frontends/qt/CategorizedCombo.h b/src/frontends/qt/CategorizedCombo.h index 51bdb4ff07..f2a19a69c2 100644 --- a/src/frontends/qt/CategorizedCombo.h +++ b/src/frontends/qt/CategorizedCombo.h @@ -17,8 +17,6 @@ #ifndef LYX_CATEGORIZEDCOMBO_H #define LYX_CATEGORIZEDCOMBO_H -#include "support/strfwd.h" - #include <QComboBox> diff --git a/src/frontends/qt/Dialog.h b/src/frontends/qt/Dialog.h index 928513c3fe..b778f18755 100644 --- a/src/frontends/qt/Dialog.h +++ b/src/frontends/qt/Dialog.h @@ -16,8 +16,6 @@ #include "insets/InsetCode.h" -#include "support/strfwd.h" - #include <QString> class QSettings; diff --git a/src/frontends/qt/FindAndReplace.h b/src/frontends/qt/FindAndReplace.h index 07c03eab0f..cb4691a07b 100644 --- a/src/frontends/qt/FindAndReplace.h +++ b/src/frontends/qt/FindAndReplace.h @@ -18,7 +18,6 @@ #include "ui_FindAndReplaceUi.h" #include "support/docstring.h" -#include <string> namespace lyx { diff --git a/src/frontends/qt/GuiCitation.cpp b/src/frontends/qt/GuiCitation.cpp index 1800543d4a..8c3be320ad 100644 --- a/src/frontends/qt/GuiCitation.cpp +++ b/src/frontends/qt/GuiCitation.cpp @@ -49,7 +49,6 @@ #include <algorithm> #include <regex> -#include <string> #include <vector> using namespace std; diff --git a/src/frontends/qt/GuiDelimiter.cpp b/src/frontends/qt/GuiDelimiter.cpp index 3d064288f5..3cb70449f6 100644 --- a/src/frontends/qt/GuiDelimiter.cpp +++ b/src/frontends/qt/GuiDelimiter.cpp @@ -34,7 +34,6 @@ #include <QScrollBar> #include <map> -#include <string> using namespace std; diff --git a/src/frontends/qt/GuiDelimiter.h b/src/frontends/qt/GuiDelimiter.h index e0450a296d..f36ecd10ee 100644 --- a/src/frontends/qt/GuiDelimiter.h +++ b/src/frontends/qt/GuiDelimiter.h @@ -12,6 +12,8 @@ #ifndef GUIDELIMITERDIALOG_H #define GUIDELIMITERDIALOG_H +#include "support/docstring.h" + #include "GuiDialog.h" #include "ui_DelimiterUi.h" diff --git a/src/frontends/qt/GuiSymbols.h b/src/frontends/qt/GuiSymbols.h index 260ce53a74..775969012b 100644 --- a/src/frontends/qt/GuiSymbols.h +++ b/src/frontends/qt/GuiSymbols.h @@ -12,11 +12,12 @@ #ifndef GUISYMBOLSDIALOG_H #define GUISYMBOLSDIALOG_H +#include "support/docstring.h" + #include "DialogView.h" #include "ui_SymbolsUi.h" #include <map> -#include <string> #include <vector> namespace lyx { diff --git a/src/frontends/qt/GuiToolbar.h b/src/frontends/qt/GuiToolbar.h index 23ee9610d1..1b780b6bbb 100644 --- a/src/frontends/qt/GuiToolbar.h +++ b/src/frontends/qt/GuiToolbar.h @@ -20,8 +20,6 @@ #include <QToolBar> #include <QToolButton> -#include "support/strfwd.h" - class QSettings; namespace lyx { diff --git a/src/frontends/qt/GuiView.h b/src/frontends/qt/GuiView.h index b7726e0230..7ff366c3b4 100644 --- a/src/frontends/qt/GuiView.h +++ b/src/frontends/qt/GuiView.h @@ -17,8 +17,6 @@ #include "frontends/Delegates.h" -#include "support/strfwd.h" - #include <QMainWindow> #include <QLabel> #include <QMenu> diff --git a/src/frontends/qt/InsetParamsDialog.h b/src/frontends/qt/InsetParamsDialog.h index 2683a4da83..cab2c5edf9 100644 --- a/src/frontends/qt/InsetParamsDialog.h +++ b/src/frontends/qt/InsetParamsDialog.h @@ -12,6 +12,8 @@ #ifndef INSET_PARAMS_DIALOG_H #define INSET_PARAMS_DIALOG_H +#include "support/docstring.h" + #include "DialogView.h" #include "ui_InsetParamsUi.h" diff --git a/src/frontends/qt/InsetParamsWidget.h b/src/frontends/qt/InsetParamsWidget.h index 0811ca5e49..8a0fb98fd5 100644 --- a/src/frontends/qt/InsetParamsWidget.h +++ b/src/frontends/qt/InsetParamsWidget.h @@ -16,7 +16,7 @@ #include "FuncCode.h" -#include "support/strfwd.h" +#include "support/docstring.h" #include <QWidget> diff --git a/src/frontends/qt/LayoutBox.h b/src/frontends/qt/LayoutBox.h index bbccb74ae8..90dde03449 100644 --- a/src/frontends/qt/LayoutBox.h +++ b/src/frontends/qt/LayoutBox.h @@ -16,7 +16,7 @@ #ifndef LYX_LAYOUT_BOX_H #define LYX_LAYOUT_BOX_H -#include "support/strfwd.h" +#include "support/docstring.h" #include <QComboBox> diff --git a/src/graphics/GraphicsTypes.h b/src/graphics/GraphicsTypes.h index 90d390cae1..a0625a4a42 100644 --- a/src/graphics/GraphicsTypes.h +++ b/src/graphics/GraphicsTypes.h @@ -15,9 +15,6 @@ #ifndef GRAPHICSTYPES_H #define GRAPHICSTYPES_H -#include "support/strfwd.h" - - namespace lyx { namespace graphics { diff --git a/src/graphics/PreviewImage.h b/src/graphics/PreviewImage.h index 6d26748092..c36c607a11 100644 --- a/src/graphics/PreviewImage.h +++ b/src/graphics/PreviewImage.h @@ -12,7 +12,7 @@ #ifndef PREVIEWIMAGE_H #define PREVIEWIMAGE_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 336843d41a..19ca818073 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -24,7 +24,6 @@ #include "RowFlags.h" #include "support/docstring.h" -#include "support/strfwd.h" #include "support/types.h" #include <climits> diff --git a/src/insets/InsetCommandParams.h b/src/insets/InsetCommandParams.h index 2faaf3f545..bfb8b04cf6 100644 --- a/src/insets/InsetCommandParams.h +++ b/src/insets/InsetCommandParams.h @@ -18,7 +18,6 @@ #include "support/docstring.h" -#include <string> #include <vector> #include <map> diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index 21f5095d1a..eb1bb1df86 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -20,7 +20,6 @@ #include "support/docstring.h" #include <set> -#include <string> namespace lyx { diff --git a/src/lyxfind.h b/src/lyxfind.h index b700e0ce1a..84d2400e2b 100644 --- a/src/lyxfind.h +++ b/src/lyxfind.h @@ -16,8 +16,6 @@ #ifndef LYXFIND_H #define LYXFIND_H -#include "support/strfwd.h" - // FIXME #include "support/docstring.h" diff --git a/src/mathed/InsetMathDecoration.cpp b/src/mathed/InsetMathDecoration.cpp index 960b6b78ab..92140368c3 100644 --- a/src/mathed/InsetMathDecoration.cpp +++ b/src/mathed/InsetMathDecoration.cpp @@ -30,7 +30,6 @@ #include "support/lstrings.h" #include <algorithm> -#include <ostream> using namespace lyx::support; diff --git a/src/mathed/InsetMathMatrix.h b/src/mathed/InsetMathMatrix.h index 6aa44c1d5c..3b752c22b9 100644 --- a/src/mathed/InsetMathMatrix.h +++ b/src/mathed/InsetMathMatrix.h @@ -13,7 +13,6 @@ #define MATH_MATRIXINSET_H #include "InsetMathGrid.h" -#include "support/strfwd.h" namespace lyx { diff --git a/src/mathed/MathAutoCorrect.h b/src/mathed/MathAutoCorrect.h index a782d678ee..3a4a25a811 100644 --- a/src/mathed/MathAutoCorrect.h +++ b/src/mathed/MathAutoCorrect.h @@ -12,7 +12,7 @@ #ifndef MATHAUTOCORRECT_H #define MATHAUTOCORRECT_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/mathed/MathClass.cpp b/src/mathed/MathClass.cpp index 1d352cd746..f2d015ada5 100644 --- a/src/mathed/MathClass.cpp +++ b/src/mathed/MathClass.cpp @@ -20,8 +20,6 @@ #include "support/docstring.h" #include "support/lassert.h" -#include <ostream> - using namespace std; namespace lyx { diff --git a/src/mathed/MathClass.h b/src/mathed/MathClass.h index af4f884cca..f78ea2bae3 100644 --- a/src/mathed/MathClass.h +++ b/src/mathed/MathClass.h @@ -12,7 +12,7 @@ #ifndef MATH_CLASS_H #define MATH_CLASS_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h index 6ff477f592..dc04a9bb4c 100644 --- a/src/mathed/MathData.h +++ b/src/mathed/MathData.h @@ -21,8 +21,6 @@ #include "Dimension.h" #include "OutputEnums.h" -#include "support/strfwd.h" - #include <cstddef> #include <vector> diff --git a/src/mathed/MathExtern.h b/src/mathed/MathExtern.h index 2544ebf811..a1a9020ac9 100644 --- a/src/mathed/MathExtern.h +++ b/src/mathed/MathExtern.h @@ -12,7 +12,7 @@ #ifndef MATH_EXTERN_H #define MATH_EXTERN_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/mathed/MathFactory.h b/src/mathed/MathFactory.h index b6fdb5044a..d653c54fb3 100644 --- a/src/mathed/MathFactory.h +++ b/src/mathed/MathFactory.h @@ -14,8 +14,6 @@ #include "MathParser.h" -#include "support/strfwd.h" - #include <map> namespace lyx { diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp index a9d6e0498e..6c0bb31940 100644 --- a/src/mathed/MathStream.cpp +++ b/src/mathed/MathStream.cpp @@ -25,7 +25,6 @@ #include <algorithm> #include <cstring> -#include <ostream> #include <FontInfo.h> using namespace std; diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h index c49384cdda..bd0e90c3f5 100644 --- a/src/mathed/MathStream.h +++ b/src/mathed/MathStream.h @@ -19,7 +19,6 @@ #include "texstream.h" #include "support/Changer.h" -#include "support/strfwd.h" namespace lyx { diff --git a/src/mathed/MathSupport.h b/src/mathed/MathSupport.h index 1f83ffb6f2..d3766c693e 100644 --- a/src/mathed/MathSupport.h +++ b/src/mathed/MathSupport.h @@ -14,7 +14,7 @@ #define MATH_SUPPORT_H #include "MathParser_flags.h" -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/output_docbook.h b/src/output_docbook.h index 1fd8d5e896..aaf17559f2 100644 --- a/src/output_docbook.h +++ b/src/output_docbook.h @@ -28,7 +28,6 @@ #include "ParagraphList.h" #include "support/docstream.h" -#include "support/strfwd.h" #include "xml.h" namespace lyx { diff --git a/src/output_plaintext.h b/src/output_plaintext.h index 8b2e4f9d1c..63519cf338 100644 --- a/src/output_plaintext.h +++ b/src/output_plaintext.h @@ -12,7 +12,7 @@ #ifndef OUTPUT_PLAINTEXT_H #define OUTPUT_PLAINTEXT_H -#include "support/strfwd.h" +#include "support/docstring.h" #include "support/types.h" #include <climits> diff --git a/src/output_xhtml.h b/src/output_xhtml.h index 3877fb0c7b..930798b777 100644 --- a/src/output_xhtml.h +++ b/src/output_xhtml.h @@ -14,7 +14,6 @@ #include "LayoutEnums.h" -#include "support/strfwd.h" #include "xml.h" diff --git a/src/support/ConsoleApplication.h b/src/support/ConsoleApplication.h index 2b8ed2b80b..4c025cdb8f 100644 --- a/src/support/ConsoleApplication.h +++ b/src/support/ConsoleApplication.h @@ -11,7 +11,7 @@ #ifndef CONSOLEAPPLICATION_H #define CONSOLEAPPLICATION_H -#include "support/strfwd.h" +#include <string> namespace lyx { diff --git a/src/support/FileName.h b/src/support/FileName.h index 35f182e428..4611ee8b6f 100644 --- a/src/support/FileName.h +++ b/src/support/FileName.h @@ -13,7 +13,6 @@ #define FILENAME_H #include "support/os.h" -#include "support/strfwd.h" #include <ctime> #include <set> diff --git a/src/support/ForkedCalls.h b/src/support/ForkedCalls.h index e64e53c6df..734f193b87 100644 --- a/src/support/ForkedCalls.h +++ b/src/support/ForkedCalls.h @@ -15,7 +15,7 @@ #define FORKEDCALLS_H #include "support/signals.h" -#include "support/strfwd.h" +#include "support/docstring.h" #ifdef HAVE_SYS_TYPES_H # include <sys/types.h> diff --git a/src/support/Length.h b/src/support/Length.h index cb612b6135..0a4e1adb1c 100644 --- a/src/support/Length.h +++ b/src/support/Length.h @@ -15,7 +15,7 @@ #ifndef LENGTH_H #define LENGTH_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/support/Lexer.h b/src/support/Lexer.h index 96ac205aba..9ca6e1e6f7 100644 --- a/src/support/Lexer.h +++ b/src/support/Lexer.h @@ -17,8 +17,7 @@ #ifndef LEXER_H #define LEXER_H -#include "support/strfwd.h" -#include <string> +#include "support/docstring.h" namespace lyx { diff --git a/src/support/Makefile.am b/src/support/Makefile.am index efcefb6736..2122cc4a42 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -106,7 +106,6 @@ liblyxsupport_a_SOURCES = \ signals.h \ socktools.cpp \ socktools.h \ - strfwd.h \ Systemcall.cpp \ Systemcall.h \ SystemcallPrivate.h \ diff --git a/src/support/Messages.h b/src/support/Messages.h index 9f33d45e6f..e4670e4f6f 100644 --- a/src/support/Messages.h +++ b/src/support/Messages.h @@ -14,7 +14,6 @@ #include "support/docstring.h" #include <map> -#include <string> namespace lyx { diff --git a/src/support/ProgressInterface.h b/src/support/ProgressInterface.h index 4a9a1edb68..2f411abcfe 100644 --- a/src/support/ProgressInterface.h +++ b/src/support/ProgressInterface.h @@ -12,7 +12,7 @@ #ifndef LYX_SUPPORT_PROGRESSINTERFACE_H #define LYX_SUPPORT_PROGRESSINTERFACE_H -#include "support/strfwd.h" +#include "support/docstring.h" class QString; diff --git a/src/support/Systemcall.h b/src/support/Systemcall.h index 537a701afa..d73a928097 100644 --- a/src/support/Systemcall.h +++ b/src/support/Systemcall.h @@ -15,8 +15,6 @@ #ifndef SYSTEMCALL_H #define SYSTEMCALL_H -#include "strfwd.h" - namespace lyx { namespace support { diff --git a/src/support/convert.cpp b/src/support/convert.cpp index 46de4b455c..d172469bc8 100644 --- a/src/support/convert.cpp +++ b/src/support/convert.cpp @@ -14,7 +14,6 @@ #include "support/convert.h" #include "support/docstring.h" -#include <string> #include <sstream> //needed for Mac OSX 10.5.2 Leopard #include <cstdlib> diff --git a/src/support/convert.h b/src/support/convert.h index ac0fd2903a..e49f5bd880 100644 --- a/src/support/convert.h +++ b/src/support/convert.h @@ -16,7 +16,7 @@ #ifndef CONVERT_H #define CONVERT_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/support/counter_reps.h b/src/support/counter_reps.h index 59305dc427..bafec250f9 100644 --- a/src/support/counter_reps.h +++ b/src/support/counter_reps.h @@ -17,7 +17,7 @@ #ifndef COUNTER_REPS_H #define COUNTER_REPS_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/support/debug.h b/src/support/debug.h index f823ee156e..6ab59b5538 100644 --- a/src/support/debug.h +++ b/src/support/debug.h @@ -15,7 +15,7 @@ #ifndef LYXDEBUG_H #define LYXDEBUG_H -#include "support/strfwd.h" +#include "support/docstring.h" // Forward definitions do not work with libc++ // but ios_base has already been defined in strfwd diff --git a/src/support/docstring.h b/src/support/docstring.h index 2c2901bf9d..2a760eacee 100644 --- a/src/support/docstring.h +++ b/src/support/docstring.h @@ -13,12 +13,71 @@ #ifndef LYX_DOCSTRING_H #define LYX_DOCSTRING_H -#include "support/strfwd.h" +#ifdef USE_WCHAR_T + +// Prefer this if possible because GNU libstdc++ has usable +// std::ctype<wchar_t> locale facets but not +// std::ctype<boost::uint32_t>. gcc older than 3.4 is also missing +// usable std::char_traits<boost::uint32_t>. +namespace lyx { typedef wchar_t char_type; } + +#else + +#include <cstdint> + +#if defined(_MSC_VER) && (_MSC_VER >= 1600) +namespace lyx { typedef uint32_t char_type; } +#include "support/numpunct_lyx_char_type.h" // implementation for our char_type needed +#else +namespace lyx { typedef std::uint32_t char_type; } +#endif + +#endif #include <string> namespace lyx { +/** + * String type for storing the main text in UCS4 encoding. + * Use std::string only in cases 7-bit ASCII is to be manipulated + * within the variable. + */ +typedef std::basic_string<char_type, std::char_traits<char_type>, + std::allocator<char_type> > docstring; + +/// Base class for UCS4 input streams +typedef std::basic_istream<char_type, std::char_traits<char_type> > idocstream; + +/// Base class for UCS4 output streams +typedef std::basic_ostream<char_type, std::char_traits<char_type> > odocstream; + +/// UCS4 output stringstream +typedef std::basic_ostringstream<char_type, std::char_traits<char_type>, std::allocator<char_type> > odocstringstream; + +#if ! defined(USE_WCHAR_T) +extern odocstream & operator<<(odocstream &, char); +#endif + +// defined in lstrings.cpp +docstring const & empty_docstring(); +std::string const & empty_string(); +// defined in docstring.cpp +bool operator==(docstring const &, char const *); + +#ifdef STD_STRING_USES_COW +template<typename Char> class trivial_string; +typedef trivial_string<char> trivstring; +typedef trivial_string<char_type> trivdocstring; +#else +typedef std::string trivstring; +typedef docstring trivdocstring; +#endif + +} // namespace lyx + +namespace lyx { + /// Creates a docstring from a C string of ASCII characters docstring const from_ascii(char const *); diff --git a/src/support/filetools.h b/src/support/filetools.h index ceb1da62be..14aea9c216 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -15,7 +15,6 @@ #include "support/docstring.h" #include <utility> -#include <string> #include <set> namespace lyx { diff --git a/src/support/gettext.h b/src/support/gettext.h index 317feec82e..19ba3bf0fa 100644 --- a/src/support/gettext.h +++ b/src/support/gettext.h @@ -13,7 +13,7 @@ #ifndef GETTEXT_H #define GETTEXT_H -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/support/lassert.h b/src/support/lassert.h index 58f299f7af..2d53a3b52f 100644 --- a/src/support/lassert.h +++ b/src/support/lassert.h @@ -15,7 +15,7 @@ #ifdef __cplusplus -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/support/lyxtime.h b/src/support/lyxtime.h index 05cbc50841..366ee221a1 100644 --- a/src/support/lyxtime.h +++ b/src/support/lyxtime.h @@ -14,9 +14,8 @@ #define LYXTIME_H #include <time.h> -#include <string> -#include "support/strfwd.h" +#include "support/docstring.h" namespace lyx { diff --git a/src/support/os.h b/src/support/os.h index 20b4e96346..1b664e4444 100644 --- a/src/support/os.h +++ b/src/support/os.h @@ -14,7 +14,7 @@ #ifndef OS_H #define OS_H -#include "support/strfwd.h" +#include "support/docstring.h" #include <cstddef> diff --git a/src/support/qstring_helpers.h b/src/support/qstring_helpers.h index 905343e77d..bb608b2334 100644 --- a/src/support/qstring_helpers.h +++ b/src/support/qstring_helpers.h @@ -12,7 +12,7 @@ #ifndef QSTRING_HELPERS_H #define QSTRING_HELPERS_H -#include "support/strfwd.h" +#include "support/docstring.h" class QString; diff --git a/src/support/strfwd.h b/src/support/strfwd.h index eef3a83a0c..7a943009e8 100644 --- a/src/support/strfwd.h +++ b/src/support/strfwd.h @@ -13,102 +13,5 @@ #ifndef STRFWD_H #define STRFWD_H -#ifdef USE_WCHAR_T - -// Prefer this if possible because GNU libstdc++ has usable -// std::ctype<wchar_t> locale facets but not -// std::ctype<boost::uint32_t>. gcc older than 3.4 is also missing -// usable std::char_traits<boost::uint32_t>. -namespace lyx { typedef wchar_t char_type; } - -#else - -#include <cstdint> - -#if defined(_MSC_VER) && (_MSC_VER >= 1600) -namespace lyx { typedef uint32_t char_type; } -#include "support/numpunct_lyx_char_type.h" // implementation for our char_type needed -#else -namespace lyx { typedef std::uint32_t char_type; } -#endif - -#endif - -// Forward definitions do not work with libc++ -// For gcc5 with the new std::string ABI forward declarations would work in -// principle, but I am not sure whether we want non-standard -// "namespace __cxx11" in our sources. -#if defined(USE_LLVM_LIBCPP) || defined(USE_GLIBCXX_CXX11_ABI) -#include <string> -#else - -namespace std { - -template<typename Alloc> class allocator; - -template<typename Char> struct char_traits; -template<> struct char_traits<char>; -#ifdef USE_WCHAR_T -template<> struct char_traits<wchar_t>; -#endif - -template<typename Char, typename Traits, typename Alloc> class basic_string; -typedef basic_string<char, char_traits<char>, allocator<char> > string; - -template<class Char, class Traits> class basic_istream; -template<class Char, class Traits> class basic_ostream; -template<class Char, class Traits, class Allocator> class basic_ostringstream; - -typedef basic_istream<char, char_traits<char> > istream; -typedef basic_ostream<char, char_traits<char> > ostream; -typedef basic_ostringstream<char, char_traits<char>, allocator<char> > ostringstream; - -} // namespace std - -#endif - - - - - -namespace lyx { - -/** - * String type for storing the main text in UCS4 encoding. - * Use std::string only in cases 7-bit ASCII is to be manipulated - * within the variable. - */ -typedef std::basic_string<char_type, std::char_traits<char_type>, - std::allocator<char_type> > docstring; - -/// Base class for UCS4 input streams -typedef std::basic_istream<char_type, std::char_traits<char_type> > idocstream; - -/// Base class for UCS4 output streams -typedef std::basic_ostream<char_type, std::char_traits<char_type> > odocstream; - -/// UCS4 output stringstream -typedef std::basic_ostringstream<char_type, std::char_traits<char_type>, std::allocator<char_type> > odocstringstream; - -#if ! defined(USE_WCHAR_T) -extern odocstream & operator<<(odocstream &, char); -#endif - -// defined in lstrings.cpp -docstring const & empty_docstring(); -std::string const & empty_string(); -// defined in docstring.cpp -bool operator==(docstring const &, char const *); - -#ifdef STD_STRING_USES_COW -template<typename Char> class trivial_string; -typedef trivial_string<char> trivstring; -typedef trivial_string<char_type> trivdocstring; -#else -typedef std::string trivstring; -typedef docstring trivdocstring; -#endif - -} // namespace lyx #endif diff --git a/src/support/textutils.h b/src/support/textutils.h index 64498fab70..1409b0a2fb 100644 --- a/src/support/textutils.h +++ b/src/support/textutils.h @@ -15,9 +15,6 @@ #ifndef TEXTUTILS_H #define TEXTUTILS_H -#include "support/strfwd.h" - - namespace lyx { /// return true if the char is a line separator diff --git a/src/support/trivstring.cpp b/src/support/trivstring.cpp index d2325cbbab..c5102526a8 100644 --- a/src/support/trivstring.cpp +++ b/src/support/trivstring.cpp @@ -15,7 +15,6 @@ #ifdef STD_STRING_USES_COW #include <algorithm> -#include <ostream> #include <stdexcept> using namespace std; diff --git a/src/support/trivstring.h b/src/support/trivstring.h index 6b935eee02..3b47f6dc85 100644 --- a/src/support/trivstring.h +++ b/src/support/trivstring.h @@ -12,8 +12,6 @@ #ifndef LYX_TRIVSTRING_H #define LYX_TRIVSTRING_H -#include "support/strfwd.h" - #ifdef STD_STRING_USES_COW #include <cstdlib> diff --git a/src/support/unicode.h b/src/support/unicode.h index 74c37bdf4a..46cea696cc 100644 --- a/src/support/unicode.h +++ b/src/support/unicode.h @@ -14,11 +14,10 @@ #ifndef LYX_SUPPORT_UNICODE_H #define LYX_SUPPORT_UNICODE_H -#include "support/strfwd.h" +#include "support/docstring.h" #include "support/unique_ptr.h" #include <cstddef> -#include <string> #include <vector> diff --git a/src/support/userinfo.h b/src/support/userinfo.h index 096e8ff47b..deee3ed809 100644 --- a/src/support/userinfo.h +++ b/src/support/userinfo.h @@ -12,7 +12,7 @@ #ifndef USERINFO_H #define USERINFO_H -#include "support/strfwd.h" +#include <string> namespace lyx {
commit 10a2d3b2a41b34bbf73b251fa685f751ecc5d789 Author: Pavel Sanda <sa...@lyx.org> Date: Fri Oct 4 15:02:41 2024 +0200 Ditch trivstring. Needed in times when std:string was not thread-safe, but should be ok nowadays. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21334 https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg223068.html diff --git a/src/Encoding.h b/src/Encoding.h index 297650c847..b097d7f44b 100644 --- a/src/Encoding.h +++ b/src/Encoding.h @@ -14,7 +14,6 @@ #define ENCODING_H #include "support/docstring.h" -#include "support/trivstring.h" #include "support/types.h" #include <map> diff --git a/src/Language.h b/src/Language.h index ddd6edf7c2..56e324a359 100644 --- a/src/Language.h +++ b/src/Language.h @@ -16,7 +16,6 @@ #define LANGUAGE_H #include "support/docstring.h" -#include "support/trivstring.h" #include <map> #include <set> diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 2122cc4a42..4ff0ebd2cb 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -115,8 +115,6 @@ liblyxsupport_a_SOURCES = \ Translator.h \ Timeout.cpp \ Timeout.h \ - trivstring.cpp \ - trivstring.h \ types.h \ unique_ptr.h \ userinfo.cpp \ diff --git a/src/support/docstring.h b/src/support/docstring.h index 2a760eacee..40806e1f40 100644 --- a/src/support/docstring.h +++ b/src/support/docstring.h @@ -65,14 +65,11 @@ std::string const & empty_string(); // defined in docstring.cpp bool operator==(docstring const &, char const *); -#ifdef STD_STRING_USES_COW -template<typename Char> class trivial_string; -typedef trivial_string<char> trivstring; -typedef trivial_string<char_type> trivdocstring; -#else +//trivstring signalizes thread-safety request; should not be needed for any +//C++11 conformant std::basic_string, e.g. GCC >= 5. +//Once properly tested we can ditch these two in favour of std::string/docstring. typedef std::string trivstring; typedef docstring trivdocstring; -#endif } // namespace lyx diff --git a/src/support/tests/check_trivstring.cpp b/src/support/tests/check_trivstring.cpp index 1b604657f4..844164510d 100644 --- a/src/support/tests/check_trivstring.cpp +++ b/src/support/tests/check_trivstring.cpp @@ -1,6 +1,5 @@ #include <config.h> -#include "../trivstring.h" #include "../docstring.h" #include <iostream> diff --git a/src/support/trivstring.cpp b/src/support/trivstring.cpp deleted file mode 100644 index c5102526a8..0000000000 --- a/src/support/trivstring.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/** - * \file trivstring.cpp - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Georg Baum - * - * Full author contact details are available in file CREDITS. - */ - -#include <config.h> - -#include "support/trivstring.h" -#include "support/docstring.h" - -#ifdef STD_STRING_USES_COW -#include <algorithm> -#include <stdexcept> - -using namespace std; - -namespace lyx { - -template trivial_string<char>::trivial_string(trivial_string const &); -template trivial_string<char_type>::trivial_string(trivial_string const &); -template<typename Char> -trivial_string<Char>::trivial_string(trivial_string const & that) : size_(that.size_) -{ - if (use_sso()) - copy(that.data_sso(), that.data_sso() + size_ + 1, data_sso()); - else if (size_ > 0) { - data_ = new Char[size_ + 1]; - copy(that.data_, that.data_ + size_ + 1, data_); - } else { - // Happens only for really big Char types - data_ = 0; - } -} - - -template<typename Char> -trivial_string<Char>::trivial_string(Char const * that, size_t n) : size_(n) -{ - if (use_sso()) { - copy(that, that + size_, data_sso()); - data_sso()[size_] = '\0'; - } else if (size_ > 0) { - data_ = new Char[size_ + 1]; - copy(that, that + size_, data_); - data_[size_] = '\0'; - } else { - // Happens only for really big Char types - data_ = 0; - } -} - - -template trivial_string<char>::trivial_string(string const &); -template trivial_string<char_type>::trivial_string(docstring const &); -template<typename Char> -trivial_string<Char>::trivial_string(_stdstring const & that) - : size_(that.length()) -{ - if (use_sso()) { - copy(that.begin(), that.end(), data_sso()); - data_sso()[size_] = '\0'; - } else if (size_ > 0) { - data_ = new Char[size_ + 1]; - copy(that.begin(), that.end(), data_); - data_[size_] = '\0'; - } else { - // Happens only for really big Char types - data_ = 0; - } -} - - -template trivial_string<char> & -trivial_string<char>::operator=(trivial_string const &); -template trivial_string<char_type> & -trivial_string<char_type>::operator=(trivial_string const &); -template<typename Char> -trivial_string<Char> & trivial_string<Char>::operator=(trivial_string const & that) -{ - if (&that == this) - return *this; - if (!use_sso()) - delete[] data_; - size_ = that.size_; - if (use_sso()) - copy(that.data_sso(), that.data_sso() + size_ + 1, data_sso()); - else if (size_ > 0) { - data_ = new Char[size_ + 1]; - copy(that.data_, that.data_ + size_ + 1, data_); - } else { - // Happens only for really big Char types - data_ = 0; - } - return *this; -} - - -template trivial_string<char> & -trivial_string<char>::operator=(string const &); -template trivial_string<char_type> & -trivial_string<char_type>::operator=(docstring const &); -template<typename Char> -trivial_string<Char> & -trivial_string<Char>::operator=(_stdstring const & that) -{ - if (!use_sso()) - delete[] data_; - size_ = that.size(); - if (use_sso()) { - copy(that.begin(), that.end(), data_sso()); - data_sso()[size_] = '\0'; - } else if (size_ > 0) { - data_ = new Char[size_ + 1]; - copy(that.begin(), that.end(), data_); - } else { - // Happens only for really big Char types - data_ = 0; - } - return *this; -} - - -template void -trivial_string<char>::swap(trivial_string<char> &); -template void -trivial_string<char_type>::swap(trivial_string<char_type> &); -template<typename Char> -void trivial_string<Char>::swap(trivial_string & that) -{ - size_t const sizetmp = that.size_; - that.size_ = size_; - size_ = sizetmp; - Char * const datatmp = that.data_; - that.data_ = data_; - data_ = datatmp; -} - - -template<typename Char> -int trivial_string<Char>::compare(trivial_string const & other) const -{ - size_t const lsize = this->length(); - size_t const rsize = other.length(); - size_t const len = min(lsize, rsize); - int r = char_traits<Char>::compare(c_str(), other.c_str(), len); - if (r == 0) { - if (lsize > rsize) - r = 1; - else if (lsize < rsize) - r = -1; - } - return r; -} - - -template trivial_string<char> trivial_string<char>::substr(size_t, size_t) const; -template trivial_string<char_type> trivial_string<char_type>::substr(size_t, size_t) const; -template<typename Char> -trivial_string<Char> trivial_string<Char>::substr(size_t pos, size_t n) const -{ - if (pos > length()) - throw out_of_range("trivial_string::substr"); - if (n == _stdstring::npos) - n = length() - pos; - size_t const l = min(pos + n, length()); - return trivial_string(c_str() + pos, l - pos); -} - - -template trivial_string<char>::operator string() const; -template trivial_string<char_type>::operator docstring() const; -template<typename Char> -trivial_string<Char>::operator _stdstring() const -{ - if (use_sso()) - return _stdstring(data_sso(), size_); - if (size_ > 0) - return _stdstring(data_, size_); - // Happens only for really big Char types - return _stdstring(); -} - - -template char const * trivial_string<char>::c_str() const; -template char_type const * trivial_string<char_type>::c_str() const; -template<typename Char> Char const * trivial_string<Char>::c_str() const -{ - if (use_sso()) - return data_sso(); - if (size_ > 0) - return data_; - // Happens only for really big Char types - static const Char empty_char = '\0'; - return &empty_char; -} - - -template char trivial_string<char>::operator[](size_t) const; -template char_type trivial_string<char_type>::operator[](size_t) const; -template <typename Char> Char trivial_string<Char>::operator[](size_t i) const -{ - return c_str()[i]; -} - - -template bool operator<(trivial_string<char> const &, - trivial_string<char> const &); -template bool operator<(trivial_string<char_type> const &, - trivial_string<char_type> const &); -template <typename Char> -bool operator<(trivial_string<Char> const & lhs, trivial_string<Char> const & rhs) -{ - return lhs.compare(rhs) < 0; -} - - -template bool operator==(trivial_string<char> const &, - trivial_string<char> const &); -template bool operator==(trivial_string<char_type> const &, - trivial_string<char_type> const &); -template <typename Char> -bool operator==(trivial_string<Char> const & lhs, trivial_string<Char> const & rhs) -{ - return lhs.compare(rhs) == 0; -} - - -template bool operator==(trivial_string<char> const &, char const *); -template bool operator==(trivial_string<char_type> const &, char_type const *); -template <typename Char> -bool operator==(trivial_string<Char> const & lhs, Char const * rhs) -{ - return lhs.compare(trivial_string<Char>(rhs)) == 0; -} - - -template bool operator==(char const *, trivial_string<char> const &); -template bool operator==(char_type const *, trivial_string<char_type> const &); -template <typename Char> -bool operator==(Char const * lhs, trivial_string<Char> const & rhs) -{ - return rhs.compare(trivial_string<Char>(lhs)) == 0; -} - - -template ostream & operator<<(ostream &, trivial_string<char> const &); -template odocstream & operator<<(odocstream &, trivial_string<char_type> const &); -template <typename Char> -basic_ostream<Char, char_traits<Char> > & -operator<<(basic_ostream<Char, char_traits<Char> > & os, trivial_string<Char> const & s) -{ - return os << basic_string<Char, char_traits<Char>, allocator<Char> >(s); -} - -} // namespace lyx -#endif diff --git a/src/support/trivstring.h b/src/support/trivstring.h deleted file mode 100644 index 3b47f6dc85..0000000000 --- a/src/support/trivstring.h +++ /dev/null @@ -1,114 +0,0 @@ -// -*- C++ -*- -/** - * \file trivstring.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Georg Baum - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef LYX_TRIVSTRING_H -#define LYX_TRIVSTRING_H - -#ifdef STD_STRING_USES_COW -#include <cstdlib> - -namespace lyx { - -/** - * Trivial string class with almost no features. - * The public interface is a subset of the std::basic_string interface. - * The only important feature is that any read-only access does not need - * synchronization between multiple threads, i.e. it is thread-safe without - * locking. - * Therefore you can safely use a const trivial_string object in multiple - * threads at the same time. This is not the case for std::basic_string in some - * STL implementations (e. g. GNU libcstd++, see bug 9336 and - * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21334. - * This class should not be used for anything else than providing thread-safety. - * It should be removed as soon as LyX requires C++11, and all supported STL - * implementations provide a C++11 conformant std::basic_string. - * - * If you change anything in this class please ensure that the unit test - * tests/check_trivstring.cpp still tests 100% of the public interface. - */ -template <typename Char> class trivial_string -{ -public: - /// Corresponding std::basic_string - typedef std::basic_string<Char, std::char_traits<Char>, std::allocator<Char> > _stdstring; - /// Construct an empty string - trivial_string() : size_(0), data_(0) {} - /// Construct a string from a copy of \p that - trivial_string(trivial_string const & that); - /// Construct a string from a copy of \p that - trivial_string(Char const * that, size_t n); - /// Construct a string from a copy of \p that - trivial_string(_stdstring const & that); - /// - ~trivial_string() { if (!use_sso()) delete[] data_; } - /// Assign a copy of \p that - trivial_string & operator=(trivial_string const & that); - /// Assign a copy of \p that - trivial_string & operator=(_stdstring const & that); - /// Exchange contents with contents of \p that - void swap(trivial_string & that); - /// The length of the string, excluding the final 0 character - size_t length() const { return size_; } - /// Is this string empty? - bool empty() const { return size_ == 0; } - /// Is this string ordered before, at the same position or after \p other? - int compare(trivial_string const & other) const; - /// Return substring of length \p n starting at \p pos - trivial_string substr(size_t pos = 0, size_t n = _stdstring::npos) const; - /// Create a copy as std::basic_string - operator _stdstring() const; - /// Return a C-compatible string, terminated by a 0 character. - /// This is never a copy and only valid for the life time of the trivial_string instance. - Char const * c_str() const; - /// Return character at position \p i (validity of \i is not checked) - Char operator[](size_t i) const; -private: - /** - * Whether short string optimization is used. - * Short string optimization is a technique where no additional memory - * needs to be allocated to store the string contents. - * Instead, the memory which would be used to store the pointer to the - * character buffer is reinterpreted to be a Char * buffer. - * On most 64 bit systems and with Char == char this allows to store - * strings of up to 7 characters without allocating additional memory. - */ - bool use_sso() const { return (size_ + 1) * sizeof(Char) <= sizeof(Char *); } - /// The character storage if sso is used - Char * data_sso() { return reinterpret_cast<Char * >(&data_); } - /// The character storage if sso is used - Char const * data_sso() const { return reinterpret_cast<Char const *>(&data_); } - /// The length of the string, excluding the final 0 character - size_t size_; - /// The character storage - Char * data_; -}; - - -/// Comparison operator (needed for std::set etc) -template <typename Char> bool operator<(trivial_string<Char> const & lhs, trivial_string<Char> const & rhs); - - -/// Equality operator -template <typename Char> bool operator==(trivial_string<Char> const & lhs, trivial_string<Char> const & rhs); -template <typename Char> bool operator==(trivial_string<Char> const & lhs, Char const * rhs); -template <typename Char> bool operator==(Char const * lhs, trivial_string<Char> const & rhs); - - -/// Stream output operator -template <typename Char> -std::basic_ostream<Char, std::char_traits<Char> > & -operator<<(std::basic_ostream<Char, std::char_traits<Char> > &, trivial_string<Char> const &); - -} // namespace lyx -#else -#include <string> -#endif -#endif
-- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel