Skip to content

Commit 2670307

Browse files
committed
custom optional class for legacy support.
1 parent f128108 commit 2670307

File tree

7 files changed

+86
-76
lines changed

7 files changed

+86
-76
lines changed

addons/ofxSvg/src/ofxSvg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,8 @@ void ofxSvg::_parsePath( ofXml& tnode, std::shared_ptr<ofxSvgPath> aSvgPath ) {
13231323

13241324
bool bRelative = false;
13251325
std::vector<glm::vec3> npositions= {glm::vec3(0.f, 0.f, 0.f)};
1326-
std::optional<ofPath::Command::Type> ctype;
1326+
/// \note: ofxSvgOptional is declared in ofxSvgUtils
1327+
ofxSvgOptional<ofPath::Command::Type> ctype;
13271328

13281329
// check if we are looking for a position
13291330
if( cchar == 'm' || cchar == 'M' ) {

addons/ofxSvg/src/ofxSvgCss.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "ofLog.h"
44
#include <regex>
55
#include <map>
6-
#include <optional>
6+
//#include <optional>
77

88

99
std::map<std::string, ofColor> sCommonColors = {

addons/ofxSvg/src/ofxSvgCss.h

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,19 @@
33
#include "ofColor.h"
44
#include "ofLog.h"
55
#include "ofXml.h"
6+
#include "ofxSvgUtils.h"
67

78
class ofxSvgCssClass {
89
public:
910

10-
// adding this Optional class since std::optional is not a part of all std:: distributions at the moment, looking at you gcc < 10 nh
11-
template<typename T>
12-
class Optional {
13-
public:
14-
Optional() : hasValue(false) {} // Default constructor, no value
15-
Optional(const T& value) : hasValue(true), data(value) {} // Construct with a value
16-
Optional(T&& value) : hasValue(true), data(std::move(value)) {} // Move constructor
17-
18-
// Copy and move constructors
19-
Optional(const Optional& other) = default;
20-
Optional(Optional&& other) noexcept = default;
21-
22-
// Assignment operators
23-
Optional& operator=(const Optional& other) = default;
24-
Optional& operator=(Optional&& other) noexcept = default;
25-
26-
// Destructor
27-
~Optional() = default;
28-
29-
// Check if there's a value
30-
bool has_value() const { return hasValue; }
31-
32-
// Accessors for the value
33-
T& value() {
34-
// if (!hasValue) throw std::runtime_error("No value present");
35-
if (!hasValue) {
36-
ofLogError("ofxSvgCssClass") << "No value present";
37-
}
38-
return data;
39-
}
40-
41-
const T& value() const {
42-
// if (!hasValue) throw std::runtime_error("No value present");
43-
if (!hasValue) {
44-
ofLogError("ofxSvgCssClass") << "No value present";
45-
}
46-
return data;
47-
}
48-
49-
// Reset to an empty state
50-
void reset() { hasValue = false; }
51-
52-
private:
53-
bool hasValue;
54-
T data;
55-
};
56-
11+
/// \note: ofxSvgOptional is declared in ofxSvgUtils
5712
class Property {
5813
public:
5914
std::string srcString;
60-
Optional<float> fvalue;
61-
Optional<int> ivalue;
62-
Optional<std::string> svalue;
63-
Optional<ofColor> cvalue;
15+
ofxSvgOptional<float> fvalue;
16+
ofxSvgOptional<int> ivalue;
17+
ofxSvgOptional<std::string> svalue;
18+
ofxSvgOptional<ofColor> cvalue;
6419
};
6520

6621
std::unordered_map<std::string, Property> properties;

addons/ofxSvg/src/ofxSvgElements.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -803,27 +803,27 @@ void ofxSvgText::customDraw() {
803803
// } restoreTransformGL();
804804
}
805805

806-
//--------------------------------------------------------------
807-
void ofxSvgText::draw(const std::string &astring, bool abCentered ) {
808-
if( textSpans.size() > 0 ) {
809-
transformGL(); {
810-
textSpans[0]->draw(astring, abCentered );
811-
} restoreTransformGL();
812-
} else {
813-
ofLogVerbose("ofxSvgText") << __FUNCTION__ << " : no text spans to draw with.";
814-
}
815-
}
816-
817-
//--------------------------------------------------------------
818-
void ofxSvgText::draw(const std::string& astring, const ofColor& acolor, bool abCentered ) {
819-
if( textSpans.size() > 0 ) {
820-
transformGL(); {
821-
textSpans[0]->draw(astring, acolor, abCentered );
822-
} restoreTransformGL();
823-
} else {
824-
ofLogVerbose("ofxSvgText") << __FUNCTION__ << " : no text spans to draw with.";
825-
}
826-
}
806+
////--------------------------------------------------------------
807+
//void ofxSvgText::draw(const std::string &astring, bool abCentered ) {
808+
// if( textSpans.size() > 0 ) {
809+
// transformGL(); {
810+
// textSpans[0]->draw(astring, abCentered );
811+
// } restoreTransformGL();
812+
// } else {
813+
// ofLogVerbose("ofxSvgText") << __FUNCTION__ << " : no text spans to draw with.";
814+
// }
815+
//}
816+
//
817+
////--------------------------------------------------------------
818+
//void ofxSvgText::draw(const std::string& astring, const ofColor& acolor, bool abCentered ) {
819+
// if( textSpans.size() > 0 ) {
820+
// transformGL(); {
821+
// textSpans[0]->draw(astring, acolor, abCentered );
822+
// } restoreTransformGL();
823+
// } else {
824+
// ofLogVerbose("ofxSvgText") << __FUNCTION__ << " : no text spans to draw with.";
825+
// }
826+
//}
827827

828828
//--------------------------------------------------------------
829829
void ofxSvgText::TextSpan::applyStyle(ofxSvgCssClass& aclass) {

addons/ofxSvg/src/ofxSvgElements.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,9 @@ class ofxSvgText : public ofxSvgElement {
554554
void setText( const std::string& astring, std::string aFontFamily, int aFontSize, float aMaxWidth );
555555
void create();
556556
void customDraw() override;
557-
void draw(const std::string &astring, bool abCentered );
558-
void draw(const std::string &astring, const ofColor& acolor, bool abCentered );
557+
// going to override
558+
// void draw(const std::string &astring, bool abCentered );
559+
// void draw(const std::string &astring, const ofColor& acolor, bool abCentered );
559560

560561
void setFontDirectory( std::string aPath ) {
561562
fdirectory = aPath;

addons/ofxSvg/src/ofxSvgUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,4 @@ ofPixels ofxSvgUtils::base64_decode(std::string const& encoded_string ) {
260260
// ofLogNotice("ofxSvgUtils::base64_decode") << "pixels ok: " << bok << " pixels: " << rpix.getWidth() << " x " << rpix.getHeight();
261261
return rpix;
262262
}
263+

addons/ofxSvg/src/ofxSvgUtils.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,55 @@
22
#include <string>
33
#include "ofPixels.h"
44

5+
// adding this Optional class since std::optional is not a part of all std:: distributions at the moment, looking at you gcc < 10 nh
6+
// and not included in older versions of OF on Windows.
7+
template<typename T>
8+
class ofxSvgOptional {
9+
public:
10+
ofxSvgOptional() : hasValue(false) {} // Default constructor, no value
11+
ofxSvgOptional(const T& value) : hasValue(true), data(value) {} // Construct with a value
12+
ofxSvgOptional(T&& value) : hasValue(true), data(std::move(value)) {} // Move constructor
13+
14+
// Copy and move constructors
15+
ofxSvgOptional(const ofxSvgOptional& other) = default;
16+
ofxSvgOptional(ofxSvgOptional&& other) noexcept = default;
17+
18+
// Assignment operators
19+
ofxSvgOptional& operator=(const ofxSvgOptional& other) = default;
20+
ofxSvgOptional& operator=(ofxSvgOptional&& other) noexcept = default;
21+
22+
// Destructor
23+
~ofxSvgOptional() = default;
24+
25+
// Check if there's a value
26+
bool has_value() const { return hasValue; }
27+
28+
// Accessors for the value
29+
T& value() {
30+
// if (!hasValue) throw std::runtime_error("No value present");
31+
if (!hasValue) {
32+
ofLogError("ofxSvgCssClass") << "No value present";
33+
}
34+
return data;
35+
}
36+
37+
const T& value() const {
38+
// if (!hasValue) throw std::runtime_error("No value present");
39+
if (!hasValue) {
40+
ofLogError("ofxSvgCssClass") << "No value present";
41+
}
42+
return data;
43+
}
44+
45+
// Reset to an empty state
46+
void reset() { hasValue = false; }
47+
48+
private:
49+
bool hasValue;
50+
T data;
51+
};
52+
53+
554
class ofxSvgUtils {
655
public:
756

@@ -14,4 +63,7 @@ class ofxSvgUtils {
1463

1564
static std::string base64_encode( const ofPixels& apixels );
1665
static ofPixels base64_decode(std::string const& encoded_string );
66+
67+
68+
1769
};

0 commit comments

Comments
 (0)