Turboscreen news

Pages: 12
Hi guys

Been working slowly in turboscreen library. Finish library datatypes. Not online yet. Saving them for major version 1.0.0

site: http://www.turboscreen.org

What do you think of them ?

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
#ifndef TS_DATATYPE_HPP
#define TS_DATATYPE_HPP

#include <string>

namespace ts
{
    typedef std::string TS_STRING;

    typedef unsigned char           TS_ASCII;     ///< 1  byte.    Range: 0 to 255
    typedef unsigned short int     TS_UTF8;	     ///< 2  bytes.   Range: 0 to 65,535
    typedef unsigned int           TS_UNICODE;   ///< 4  bytes.   Range: 0 to 4,294,967,295
    typedef unsigned long long int TS_UNISYMBOL; ///< 8  bytes.	  Range: 0 to 18,446,744,073,709,551,615

    typedef char                   TS_CHAR; 	 ///< 1  byte. 	  Range: -127 to 127 or 0 to 255
    typedef unsigned char          TS_UCHAR; 	 ///< 1  byte.	  Range: 0 to 255
    typedef signed char            TS_SCHAR; 	 ///< 1  byte.	  Range: -127 to 127
    typedef wchar_t 	           TS_WCHAR;     ///< 2  bytes.   Range: 0 to 65,535

    typedef short int 	           TS_WORD;      ///< 2  bytes.   Range: -32,768 to 32,767
    typedef unsigned short int     TS_UWORD;	 ///< 2  bytes.   Range: 0 to 65,535
    typedef signed short int       TS_SWORD;	 ///< 2  bytes.   Range: -32768 to 32767
    
    typedef int 	               TS_INT;       ///< 4  bytes.   Range: -2,147,483,648 to 2,147,483,647
    typedef unsigned int           TS_UINT;      ///< 4  bytes.   Range: 0 to 4,294,967,295
    typedef signed int 	           TS_SINT;      ///< 4  bytes.   Range: -2,147,483,648 to 2,147,483,647
        
    typedef long int 	           TS_LONG; 	 ///< 4  bytes.   Range: -2,147,483,648 to 2,147,483,647
    typedef unsigned long int      TS_ULONG; 	 ///< 4  bytes.	  Range: 0 to 4,294,967,295
    typedef signed long int        TS_SLONG;	 ///< 4  bytes.	  Range: -2,147,483,648 to 2,147,483,647

    typedef long long int 	       TS_QUAD;      ///< 8  bytes.	  Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
    typedef unsigned long long int TS_UQUAD; 	 ///< 8  bytes.	  Range: 0 to 18,446,744,073,709,551,615
    typedef signed long long int   TS_SQUAD; 	 ///< 8  bytes.	  Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
            
    typedef float 	               TS_FLOAT;     ///< 4  bytes.   Range: 1.17549e-38  to 3.40282e+38	
    typedef double 	               TS_DOUBLE;    ///< 8  bytes.	  Range: 2.22507e-308 to 1.79769e+308
    typedef long double 	       TS_LDOUBLE;   ///< 16 bytes.	  Range: 3.3621e-4932 to 1.18973e+4932

} // namespace ts

#endif // TS_DATATYPE_HPP 
Last edited on
What’s wrong with <stdint.h> / <cstdint> ?
Hi Duthomhas

I just want to give a personal touch to library datatypes. :)
Last edited on
IMO, don't. Use the standard types. There are (u)int8_t, (u)int16_t etc.

See https://en.cppreference.com/w/cpp/types/integer
Hi seeplus

Thanks for link.
Made a function for my string object with library datatypes. Isn't that bad. :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
TS_UINT TSO_string::fn_length(TS_STRING string)
  {
    TS_UINT out = 0;
    TS_UINT index = 0;
    TS_UINT count = 0;

    while (string[index] != '\0')
    {
      if (string[index] != '\0')
      {
        count++;
      }
      index++;
    }

    out = count;

    return out;
  }
Isn't this just std::string.size() - as TS_STRING is type std::string? Note that a std::string can contain a '\0' as a valid char - not just at the end.

L9 will always be true.

However, without using .size(), then:

1
2
3
4
size_t fn_length(const std::string& str)
{
	return std::distance(str.begin(), str.end());
}

hi seeplus

if your str = "asa\0delta"; what is your output 3 or 9 ? i think it will break at '\0' and give you 3. So you will never get the string real length. I could be wrong or not. My function is working well.

str.size() is giving me output: 3
str.length() is giving me output: 3
Last edited on
If the string is "asa\0delta" then for std::string its size is 9.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>
#include <string>
using namespace std::string_literals;

size_t fn_length(const std::string& str)
{
	return std::distance(str.begin(), str.end());
}

int main()
{
	const std::string foo {"asa\0delta"s};

	std::cout << fn_length(foo) << '\n';
}



9


It depends upon what you want. Do you want to treat as c-style null terminated or as std::string? If you create a std::string from a c-style string, then the std::string is only created up to the first '\0'. Following chars are not part of the std::string.

If you do want the size just until the '\0', then:

1
2
3
4
5
6
7
8
size_t fn_length(const std::string& str)
{
	auto ter {str.c_str()};

	for (; *ter; ++ter);

	return ter - str.c_str();
}


which gives

3

Last edited on
I think i will use std::string but function will stop counting when it encounters '\0'.
Just want to say that this project looks very cool! And way out of my league to understand/use...

Also like the website, very professional.
Hi agent max

What you see in site is just the first version. Next version will be completely different and will have things like:

> 1 - Many string functions. Ex: fn_length (working on this now)
> 2 - A sub-library called TSO_file to deal with files
> 3 - A sub-library called TSO_bed to deal with data structures. JSON and XML are
going to "die" after this. :)
> 4 - A sub-library called TSO_font to deal with fonts
> 5 - A default font file.
>
> and many empty sub-libraries with no functions in them. They will be added in future versions.
Consider:
1
2
    typedef unsigned short int     TS_UTF8;	     ///< 2  bytes.   Range: 0 to 65,535
    typedef unsigned int           TS_UNICODE;   ///< 4  bytes.   Range: 0 to 4,294,967,295 

It does not make any sense for UTF-8 to be represented using 2-byte integers. UTF-8 is a variable width encoding that transmits Unicode code points using a sequence of 8-bit code units.

You should read the Unicode FAQ:
https://unicode.org/faq/

Consider
typedef int TS_INT; ///< 4 bytes. Range: -2,147,483,648 to 2,147,483,647

The size of int is not always 4 bytes. If you want a 4-byte int, you should ask for one specifically:
typedef std::int32_t TS_INT
Similar issues exist for many other type aliases in the file.

I just want to give a personal touch to library datatypes.

Is there much room for preference in API design?
If cost-benefit analysis doesn't support a feature's presence, it shouldn't exist.

All code has a cost. After all, the more code in your project, the more opportunity you have to screw up.


Overall, I'm glad you're still working on this. Good luck!
Last edited on
Overall, I'm glad you're still working on this. Good luck!

Agreed!
And also agreed, do not define new int types. each int type already has at least 5 ways to say it in standard c++. Double that if you count microsoftisms.
I'm not going to sugar coat this. I don't understand the point of it. But if you're learning something by doing this, then please continue.
@Ganado

I have considered writing something similar myself many times — I have simply never had the time to do so. (Mine would be multi-platform, though: Win32 + X11.)

It is the very reason that people still post regularly about <graphics.h>, because it provides a very simple, easy to use and easy to understand way to simply draw some basic graphics.


@forgottencoder

The reason to use <stdint.h> is more subtle than first appears: you get a standardized way to be much more exacting about types. For example, you have TS_INT listed as a four-byte object, but that may not be the case! Standard C++ only mandates that it be a minimum of two bytes. More concretely, if you get someone compiling for a 32-bit executable, you’ll get a two-byte integer.

Unless your project is specific about only working with a specific, versioned collection of compilers, you cannot assume anything unless you use either <stdint.h> or the Windows typedefs directly.

One more note: including <windows.h> is heavy and it has potential to affect user code. It should therefore only appear in implementation code and internal headers for your library. It should never appear in anything that the user may include, either directly or indirectly.

You should consider the future possibility of a multi-platform implementation of your API. This would make it immensely more usable and adoptable by people like college professors.

My $0.02
Last edited on
Hi all

I have been listenning all of you. Thanks for the comments. Made a new version of it. Just for fun. Took me a lot of time converting all my cpp and hpp files. Now it compiles with no errors.

So what do you think of the new version ? Please don't spare on comments. Give me your worst. LOL. :)

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

#ifndef TS_DATATYPE_HPP
#define TS_DATATYPE_HPP

#include <string>

namespace ts
{
    /// TST_ Turbo Screen Type

    typedef std::string         TST_STRING;
    typedef bool                TST_BOOL;
    typedef std::nullptr_t      TST_VOID;

    typedef std::uint_least8_t  TST_CHAR8;       ///< 1  byte.   Range: 0 to 255 (ASCII)
    typedef std::uint_least16_t TST_CHAR16;      ///< 2  bytes.  Range: 0 to 65.535
    typedef std::uint_least32_t TST_CHAR32;      ///< 4  bytes.  Range: 0 to 4.294.967.295 (UNICODE, UTF8)
    typedef std::uint_least64_t TST_CHAR64;      ///< 8  bytes.  Range: 0 to 18.446.744.073.709.551.615 (UNISYMBOL)

    // S - Signed int
    typedef std::int8_t         TST_S_INT8;      ///< 1 byte.  Range: -128 to 127
    typedef std::int16_t        TST_S_INT16;     ///< 2 bytes. Range: -32.768 to 32.767
    typedef std::int32_t        TST_S_INT32;     ///< 4 bytes. Range: -2.147.483.648 to 2.147.483.647
    typedef std::int64_t        TST_S_INT64;     ///< 8 bytes. Range: -9.223.372.036.854.775.808 to 9.223.372.036.854.775.807

    // SF - Signed Fast int
    typedef std::int_fast8_t    TST_SF_INT8;     ///< 1 byte.  Range: -128 to 127
    typedef std::int_fast16_t   TST_SF_INT16;    ///< 2 bytes. Range: -32.768 to 32.767
    typedef std::int_fast32_t   TST_SF_INT32;    ///< 4 bytes. Range: -2.147.483.648 to 2.147.483.647
    typedef std::int_fast64_t   TST_SF_INT64;    ///< 8 bytes. Range: -9.223.372.036.854.775.808 to 9.223.372.036.854.775.807

    // SL - Signed Least int
    typedef std::int_least8_t   TST_SL_INT8;     ///< 1 byte.  Range: -128 to 127
    typedef std::int_least16_t  TST_SL_INT16;    ///< 2 bytes. Range: -32.768 to 32.767
    typedef std::int_least32_t  TST_SL_INT32;    ///< 4 bytes. Range: -2.147.483.648 to 2.147.483.647
    typedef std::int_least64_t  TST_SL_INT64;    ///< 8 bytes. Range: -9.223.372.036.854.775.808 to 9.223.372.036.854.775.807

    // U - Unsigned int
    typedef std::uint8_t        TST_U_INT8;      ///< 1 byte.  Range: 0 to 255
    typedef std::uint16_t       TST_U_INT16;     ///< 2 bytes. Range: 0 to 65.535
    typedef std::uint32_t       TST_U_INT32;     ///< 4 bytes. Range: 0 to 4.294.967.295
    typedef std::uint64_t       TST_U_INT64;     ///< 8 bytes. Range: 0 to 18.446.744.073.709.551.615

    // UF - Unsigned Fast int
    typedef std::uint_fast8_t   TST_UF_INT8;     ///< 1 byte.  Range: 0 to 255
    typedef std::uint_fast16_t  TST_UF_INT16;    ///< 2 bytes. Range: 0 to 65.535
    typedef std::uint_fast32_t  TST_UF_INT32;    ///< 4 bytes. Range: 0 to 4.294.967.295
    typedef std::uint_fast64_t  TST_UF_INT64;    ///< 8 bytes. Range: 0 to 18.446.744.073.709.551.615

    // L - Unsigned Least int
    typedef std::uint_least8_t  TST_UL_INT8;     ///< 1 byte.  Range: 0 to 255
    typedef std::uint_least16_t TST_UL_INT16;    ///< 2 bytes. Range: 0 to 65.535
    typedef std::uint_least32_t TST_UL_INT32;    ///< 4 bytes. Range: 0 to 4.294.967.295
    typedef std::uint_least64_t TST_UL_INT64;    ///< 8 bytes. Range: 0 to 18.446.744.073.709.551.615
                
    // floating point
    typedef float               TST_FLOAT;       ///< 4  bytes. Range: 1.17549e-38  to 3.40282e+38	
    typedef double              TST_DOUBLE;      ///< 8  bytes. Range: 2.22507e-308 to 1.79769e+308
    typedef long double         TST_LONG_DOUBLE; ///< 16 bytes. Range: 3.3621e-4932 to 1.18973e+4932

} // namespace ts

#endif // TS_DATATYPE_HPP

Last edited on
Much better. You forgot to #include <cstdint> .
long double is compiler determined: all you know is that it is at least as good as a double. It could be 10 bytes, 16 bytes, or whatever.

also, I believe that 'using' has replaced 'typedef' in modern c++.
https://www.nextptr.com/tutorial/ta1193988140/how-cplusplus-using-or-aliasdeclaration-is-better-than-typedef

and I can't stress enough that renaming the types is just a frustration to the users. Win32 API is maddening because of this stuff. Its a style relic from the 90s that had a few merits back then (the size of types was a little weirder before the 98 standard) that has no place in anything today (and was 'questionable' at the time, but 'acceptable'). M$ took it so far as to hide all the pointers with typedefs to make it unclear when you had a thing and when you had a pointer to a thing, which makes it extra hard to use.

to put it another way, you can re-create the pascal language in c++ with typedefs and macros.
Doing so should get you taken out behind the woodshed for a 'talking' to, but you can do it. C and C++ let you do lots of weird stuff that you are just supposed to know not to do in serious code.

Ganado, I have also written something like this. I had a co-worker (in his 80s, aerospace engineer) who threw up his hands at the graphics stuff and asked for a routine to put a pixel at a screen location so he could plot a few 2-d graphs beside each other to what-if some stuff. I wrapped enough directx to do that, and he was happy as a 6 year old with an ice-cream. But I didn't write a whole library, just a couple of routines (ended up giving him a line and something else as well).
Last edited on
jonnin wrote:
But I didn't write a whole library, just a couple of routines (ended up giving him a line and something else as well).

Probably what I'd have done too– sort of half-assed it and given him a couple Bash scripts to compile and run the thing.

I've never used "typedef," but isn't "using" for namespaces, not data types? Or am I just confused...?
Last edited on
Pages: 12