Need help to improve my framework

Hey Guys,

I'm currently on a Project to build my own little C++ framework with CMake, where I'll place everything i make in C++.

I started about 2 Weeks ago and allready run out of ideas what I could need in the future, it also would be nice if you could tell me if it looks good to you.

I have a hirachie like this:
1
2
3
4
5
6
7
8
9
10
- Librepp (root)
  - Builds
    - bla bla bla
  - Sources
    - include
      -  Types
      - ... (boost, SDL2, SFML2, Box2D)
    - lib
    - Playground
    - Projects


The Part where i currently work is in the Types Folder:
Current content:
1
2
3
4
- Types
  - Char.h
  - String.h
  - Vector.h


They loook like this:

Char.h
1
2
3
4
5
6
7
8
9
10
11
12
13
class Char
{
private:
    /// Char-Object should not be created
    Char();

public:
    static bool IsCapitalLetter(char Character);
    static bool IsSmallLetter(char Character);
    static bool IsLetter(char Character);

    static bool IsNumber(char Character);
};

String.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class String
{
private:
    /// String-Object should not be created
    String();

public:
    /// Splits the String into a Vector of Strings with a defined Length
    /// If String.size() % Length is not 0 the last String has less Elements
    static std::vector<std::string> Split(const std::string& rString, unsigned int Length, const std::string& rEnding = "");

    /// Splits the String into a Vector of Strings
    static std::vector<std::string> Explode(const std::string& rString, const std::string& rDelimiter, int SearchStart = 0);

    /// Splits the String into a Vector of Strings, but doesn't erase delimiter
    static std::vector<std::string> SoftExplode(const std::string& rString, const std::string& rDelimiter, int SearchStart = 0);

    /// Takes the StringVector and Connects its Elements by "Delimiter"
    static std::string Implode(const std::vector<std::string>& rvString, const std::string& rDelimiter = "");


    /// Returns a String repeated RepeatCount times
    static std::string Repeat(const std::string& rString, unsigned int RepeatCount);

    /// Removes TrimChars from both sides of the String
    /// Modifies the content of rString
    static void Trim(std::string& rString, const std::string& rTrimChars = "\0\t\n\x0B\r ");

    /// Returns the String in reversed Order
    static std::string Reverse(const std::string& rString);


    /// insert "Sequence" before each Pattern
    /// Modifies the content of rString
    static void InsertBeforePattern(std::string& rString, const std::string& rPattern, const std::string& rSequence);

    /// Make sure "Sequence" appears before each Pattern
    /// Modifies the content of rString
    static void HaveBeforePattern(std::string& rString, const std::string& rPattern, const std::string& rSequence);


    /// Replaces all occurences of 'Char' with 'Replaces'
    /// Modifies the content of rString
    static void ReplaceChar(std::string& rString, char Char, char Replace);

    //// Replaces all occurences of 'Char' with 'Replaces'
    /// Modifies the content of rString
    static void ReplaceChars(std::string& rString, const std::string& rChars, const std::string& rReplaces);

    /// if rReplaces.length() < rChars.length() the last characters will be replaced with " "
    static void ReplaceChars(std::string& rString, const std::string& rChars, std::string& rReplaces);

    /// Replaces all occurences of Pattern with Replace
    /// Modifies the content of rString
    static void ReplacePattern(std::string& rString, const std::string& rPattern, const std::string& rReplace);


    /// Count the Appearences of Char
    /// Case Sensetive
    static unsigned int CountChar(const std::string& rString, char Char);

    /// Count the Sum of appearences of the Chars
    /// Case Sensetive
    static unsigned int CountChars(const std::string& rString, const std::string& rChars);

    /// Count the Appearences of Pattern
    /// Case Sensetive
    static unsigned int CountPattern(const std::string& rString, const std::string& rPattern);


    /// Returns 1 of there are Only Letters in the String
    static bool HasOnlyLetters(const std::string& rString);

    /// Returns 1 of there are Only Numbers in the String
    static bool HasOnlyNumbers(const std::string& rString);

    /// Returns 1 of there is at least 1 Letter in the String
    static bool HasLetters(const std::string& rString);

    /// Returns 1 of there is at least 1 Number in the String
    static bool HasNumbers(const std::string& rString);
}


Vector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

class Vector
{
private:
    /// Vector-Object should not be created
    Vector();

public:
    /// Call a Function with all Objects
    template <typename T>
    static void CallOnEach(const std::vector<T>& rVector, void (*func)(const T&));

    /// Get the Sum of all Elements
    template <typename T>
    static T GetSum(const std::vector<T>& rVector);

    /// Compare all elements and the size, if any Elements or the size differ the result is false
    template <typename T>
    static bool AreEqual(const std::vector<T>& rVector1, const std::vector<T>& rVector2);

    /// Call a Function with all Objects in a Vector, some objects may be modified
    template <typename T>
    static void ModifyAll(std::vector<T>& rVector, void (*func)(T&));

    /// Make a Vector from this vector and create Elements like func tells you
    template <typename T, typename U>
    static std::vector<U> MakeVector(const std::vector<T>& rVector, U (*func)(const T&));

    /// Erases all Datablocks with given conditions
    template <typename T>
    static void EraseWhen(std::vector<T>& rVector, bool (*func)(const T&));

private:
};


Now the explicit questions:

Do you have Ideas of Methods i could add?
Do you have Ideas of Libraries i could add? (and maybe some Methods for them)
What can i Improve? (bad style, to bad documentation?)
How can i Improve my Project Hirachy?
Where should i put my Test applications?

Also: Could you please rate my work?

I'm grateful for all answers

I hope I didn't miss anything important.

Greetings,
Gamer2015
Last edited on
You can't know what you will need in the future with so little experience.

My recommendation: get started with a library like SFML and make a game. Then make another. Then another. You will eventually see what is common between them and what is specific to each.

If you'd like to ignore my suggestion though, I'll take a look at your code.

Do you have a background in Java? Your programming style seems to suggest it. For one, making a constructor private does not mean the class cannot be instantiated - you need to mark the constructor as deleted with ClassName() = delete;. Additionally, these don't even need to be classes at all, they can just be namespaces with functions (since that's what they basically are already):
1
2
3
4
5
6
7
8
namespace utils
{
    namespace string
    {
        std::vector<std::string> split(/*...*/);
        //...
    }
}


Also, your vector utility functions duplicate existing functions in the C++ Standard Library:
CallOnEach: http://www.cplusplus.com/reference/algorithm/for_each/
GetSum: http://www.cplusplus.com/reference/numeric/accumulate/
AreEqual: std::vector overloads operator== already
ModifyAll: http://www.cplusplus.com/reference/algorithm/for_each/
MakeVector: http://www.cplusplus.com/reference/algorithm/generate/
EraseWhen: http://www.cplusplus.com/reference/algorithm/remove_if/
You should also be aware that lambdas and std::function exist - look up the difference between function and functors.
Hey LB and thanks for replying!

Yeah, that might be the case, but that's exactly why i asked you, because you have more experience than myself.

Allready started with SFML and SDL and I have a lot of work to do here to gather enough experience to tell if i should place them in this "Base Include Path" or just move them from Project to Project because they need a little modification each time.
As soon as I don't have to modify them anymore I think it's time i place them in a more general location and reuse them, but that'll need some more experience and Time^^

Unfortunetly I don't only want to make games, I'm currently working on some AudioSignalProcessing Libraries (just started with finishing a RingBuffer Class)

Java? Nope, I started learning C/C++ a few Years ago and made short trips outside the C/C++ world to Python, C#, Java, Javascript and Php but I'm not so comfortable with either of them.
I still thank you for pointing this out, I've never used private Constructors becore.
I made these Classes on purpose, because I was not sure if I'll ever need some private Members to store something in (I can't think of an example but that's why I'm not sure), which is due to my knowledge not possible with namespaces and "Header Only Libraries". I have the implementation in a *.inl file that i include at the end of the *.h Files.

Also, thanks for suggesting "Utils" as Namespace name, i used "Types" but that felt wrong because i do not actually implement any types...

Well, thanks for pointing this out, I actually wasn't even aware of any them and thank you for the link.
Also, thank you for telling me about std::function and functors, I allready heared about lambdas but never used them before. the only C++11 feature I used until now was shared_ptr.

Thank you for expanding my knowledge, i surely learned a lot from your post :D

Greetings,
Gamer 2015
It is hard to know in advance what you will need, especially without experience. Not even I know what would/should be in your library/framework. People make libraries because they notice that they are writing code that is useful in more than just their specific case. You don't know that until you try first.

I always make the assumption that people are interested in game development - if you're not, that's fine. The point is, make lots of projects and try to get them all to a mostly functional working state. That's not to say you should never plan things out - the point is that you need to learn how not to do things, because planning is the process of blocking off bad directions.
Yeah I think you're right. I wanted to make a generic Calculator, that's where i had some Ideas for my String Class from. Well, I'll just start some new projects then and see what's needed ;)

No, I am actually interested in game development, I just wanted to say that it isn't the only interesting Topic for me.


Well, I'll just thank you for now. I came up with a few things i want to add to the "framework" like a AudioSignalProcessing Library and a Section for Automatic Testing and most importantly, I got some nice advices from an experienced Programmer :D
I think this'll take some time.

Greetings,
Gamer2015
Last edited on
Topic archived. No new replies allowed.