1. C++ / Говнокод #28222

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    #include <clcpp/clcpp.h>
    #include <clcpp/FunctionCall.h>
    
    
    // Reflect the entire namespace and implement each class
    clcpp_reflect(TestClassImpl)
    namespace TestClassImpl
    {
    	class A
    	{
    	public:
    		A()
    		{
    			x = 1;
    			y = 2;
    			z = 3;
    		}
    
    		int x, y, z;
    	};
    
    	struct B
    	{
    		B()
    		{
    			a = 1.5f;
    			b = 2.5f;
    			c = 3.5f;
    		}
    
    		float a, b, c;
    	};
    }
    
    clcpp_impl_class(TestClassImpl::A)
    clcpp_impl_class(TestClassImpl::B)
    
    void TestConstructorDestructor(clcpp::Database& db)
    {
    	const clcpp::Class* ca = clcpp::GetType<TestClassImpl::A>()->AsClass();
    	const clcpp::Class* cb = clcpp::GetType<TestClassImpl::B>()->AsClass();
    
    	TestClassImpl::A* a = (TestClassImpl::A*)new char[sizeof(TestClassImpl::A)];
    	TestClassImpl::B* b = (TestClassImpl::B*)new char[sizeof(TestClassImpl::B)];
    
    	CallFunction(ca->constructor, a);
    	CallFunction(cb->constructor, b);
    
    	CallFunction(ca->destructor, a);
    	CallFunction(cb->destructor, b);
    
    	delete [] (char*) a;
    	delete [] (char*) b;
    }

    https://github.com/Celtoys/clReflect/blob/master/src/clReflectTest/TestClassImpl.cpp

    kcalbCube, 14 Июня 2022

    Комментарии (11)
  2. Pascal / Говнокод #28215

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    // реализация интерфейса IArguments2 для самодельного скриптового движка, aka vbs to exe
    
    unit Arguments;
    
    interface
    
    uses
      Windows, ComObj, ActiveX, Stub_TLB, SysUtils,WSHNamedArguments,WSHUnNamedArguments, CmdUtils;
    
    type
      TIarguments=class(TAutoObject, IArguments2, IEnumVariant)
          FAArgs:array of WideString;
          FWSHNamedArguments:TIWSHNamedArguments;
          FWSHUnNamedArguments:TIWSHUnNamedArguments;
          function Item(Index: Integer): WideString; safecall;
        function Count: Integer; safecall;
        function Get_length: Integer; safecall;
        function _NewEnum: IUnknown; safecall;
        property length: Integer read Get_length;
            function Get_Named: IWSHNamedArguments; safecall;
        function Get_Unnamed: IWSHUnnamedArguments; safecall;
        procedure ShowUsage; safecall;
        property Named: IWSHNamedArguments read Get_Named;
        property Unnamed: IWSHUnnamedArguments read Get_Unnamed;
            function Next(celt: LongWord; var rgvar : OleVariant;
          out pceltFetched: LongWord): HResult; stdcall;
        function Skip(celt: LongWord): HResult; stdcall;
        function Reset: HResult; stdcall;
        function Clone(out Enum: IEnumVariant): HResult; stdcall;
        public
        constructor Create;
        end;

    implementation

    uses ComServ;

    var
    FIndex:Integer=0;

    { TIarguments }

    function TIarguments._NewEnum: IUnknown;
    begin
    Result:=self;
    end;

    function TIarguments.Count: Integer;
    begin
    Result:=System.Length(FAArgs);
    end;

    function TIarguments.Get_length: Integer;
    begin
    Result:=Count;
    end;

    function TIarguments.Item(Index: Integer): WideString;
    begin
    if (Index >= System.Length(FAArgs)) then
    raise EOleSysError.Create('Range check error', HRESULT($800A0009),0)
    else
    Result:=FAArgs[Index]
    end;

    function TIarguments.Get_Named: IWSHNamedArguments;
    begin
    Result:=FWSHNamedArguments;
    end;

    function TIarguments.Get_Unnamed: IWSHUnnamedArguments;
    begin
    Result:=FWSHUnNamedArguments;
    end;

    procedure TIarguments.ShowUsage;
    begin
    OleError(E_NOTIMPL);
    end;

    constructor TIarguments.Create;
    var
    I,J, PCnt:Integer;
    S, CmdLine:string;
    begin
    inherited Create;
    FIndex:=0;
    FWSHNamedArguments:=TIWSHNamedArguments.Create;
    FWSHUnNamedArguments:=TIWSHUnNamedArguments.Create;
    PCnt:=ParamCount;
    SetLength(FAArgs, PCnt);
    for I:=1 to PCnt do
    begin
    J:=I-1;
    FAArgs[J]:=ParamStr(I);
    end;

    //Parsing named args.

    CmdLine:='';
    S:=GetCommandLine;
    PCnt:=iParamCount(PChar(S));
    if PCnt > 1 then
    begin
    for I:=1 to PCnt-1 do
    begin
    CmdLine:=CmdLine+iParamStr(PChar(S), I);
    if I < PCnt-1 then
    CmdLine:=CmdLine+' ';
    end;
    end;

    Support, 09 Июня 2022

    Комментарии (6)
  3. C++ / Говнокод #28214

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    /**
     * @throw   std::system_error 
     */
    auto udp_echo_service(int64_t sd) -> no_return_t {
        sockaddr_in remote{};
        io_work_t work{};
        io_buffer_t buf{};              // memory view to the 'storage'
        io_buffer_reserved_t storage{}; // each coroutine frame contains buffer
    
        while (true) {
            // packet length(read)
            auto len = co_await recv_from(sd, remote, buf = storage, work);
            // instead of length check, see the error from the 'io_work_t' object
            if (work.error())
                goto OnError;
    
            buf = {storage.data(), static_cast<size_t>(len)};
            len = co_await send_to(sd, remote, buf, work);
            if (work.error())
                goto OnError;
    
            assert(len == buf.size_bytes());
        }
        co_return;
    OnError:
        // expect ERROR_OPERATION_ABORTED (the socket is closed in this case)
        const auto ec = work.error();
        const auto emsg = system_category().message(ec);
        fputs(emsg.c_str(), stderr);
    }

    https://github.com/luncliff/coroutine/blob/main/test/net_socket_udp_echo.cpp

    kcalbCube, 08 Июня 2022

    Комментарии (9)
  4. Куча / Говнокод #28206

    −3

    1. 1
    https://discord.gg/qFGgdPas?event=982592329527492638

    Войсовый холивар на дискорд гк
    Основные темы: C++ лучший язык для всех платформ и целей, ржавчина не нужна, где борманд

    kcalbCube, 04 Июня 2022

    Комментарии (13)
  5. C++ / Говнокод #28203

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    bool addPlayer(const Addr & addr,
        Poco::Nullable<const std::string> serverAddr,
        Poco::Nullable<bool> isKeyReceived,
        Poco::Nullable<std::string> key,
        Poco::Nullable<time_t> lastHashCheck,
        Poco::Nullable<std::string> digest)
    {
        bool isPlaying = !serverAddr.isNull();
        bool isKeyReceivedReal = isKeyReceived.isNull();
        time_t lastHashCheckReal = lastHashCheck.isNull() ? time(0) : lastHashCheck.value();
        std::string keyReal(key.isNull() ? "" : key.value());
        std::string playerAddr = addr.getHost();
        std::string serverAddrReal(serverAddr.isNull() ? "" : serverAddr.value());
        std::string digestReal = digest.isNull() ? "" : digest.value();
    
        Statement insert(*playersSession);
        insert << "INSERT INTO Players VALUES(?, ?, ?, ?, ?, ?, ?)",
            use(playerAddr),          // Addr
            use(serverAddrReal),      // Server
            use(isPlaying),
            use(isKeyReceivedReal),
            use(keyReal),             // Key
            use(lastHashCheckReal),
            use(digestReal);
        insert.execute();
    
        return true;
    }

    ISO, 03 Июня 2022

    Комментарии (20)
  6. C++ / Говнокод #28201

    0

    1. 1
    2. 2
    3. 3
    4. 4
    #define MIRAGE_COFU(T, name, ...) \
             inline struct _##name##cofu { T instance{ __VA_ARGS__ }; T& operator()(void) { return instance; }; \
             static bool destructed; ~_##name##cofu(void) { destructed = true; } static bool isDestructed(void) \
             { return destructed; } } name; inline bool _##name##cofu::destructed = false

    кофу

    kcalbCube, 01 Июня 2022

    Комментарии (45)
  7. Куча / Говнокод #28200

    −1

    1. 1
    Минск #5

    #1: https://govnokod.ru/25937 https://govnokod.xyz/_25937
    #2: https://govnokod.ru/26458 https://govnokod.xyz/_26458
    #3: https://govnokod.ru/27233 https://govnokod.xyz/_27233
    #4: https://govnokod.ru/27448 https://govnokod.xyz/_27448

    3_dar, 30 Мая 2022

    Комментарии (225)
  8. Куча / Говнокод #28199

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    http://varikvalefor.i2p
    https://github.com/varikvalefor
    http://varikvalefor.neocities.org/
    
    Кто в ш2з бывает, особенно рекомендую прорваться по первой ссылке.

    Дискасс. Вечером скину основные тейки из ш2з для клирнетовцев.

    vistefan, 30 Мая 2022

    Комментарии (217)
  9. C++ / Говнокод #28198

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    #include <stdio.h>
    
    int main() {
        char* pituh;
        puts(pituh);
        pituh = "kokoko";
        return 0;
    }

    Угадайте что выведет код?
    ISO и прочим скилловикам просьба воздержаться.

    https://ideone.com/sYrqiB

    3_dar, 29 Мая 2022

    Комментарии (77)
  10. C++ / Говнокод #28197

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    template<int I> struct Tag {};
    
    template<int I>
    struct StaticMock : mirage::ecs::Component<StaticMock<I>>
    {
    	static bool initializeds;
    	void initialize(void)
    	{
    		initializeds = true;
    	}
    };
    
    template<>
    struct StaticMock<2> : mirage::ecs::Component<StaticMock<2>>
    {
    	static bool initializeds;
    	void initialize(Tag<2>&)
    	{
    		initializeds = true;
    	}
    };
    
    template<int I>
    inline bool StaticMock<I>::initializeds = false;
    inline bool StaticMock<2>::initializeds = false;
    
    using Tag1 = Tag<1>;
    using StaticMock1 = StaticMock<1>;
    using Tag2 = Tag<2>;
    using StaticMock2 = StaticMock<2>;
    
    MIRAGE_CREATE_ON_STARTUP(StaticMock<0>, staticOnStartMock);
    MIRAGE_CREATE_ON_EVENT(Tag1, StaticMock1);
    MIRAGE_CREATE_WITH_EVENT(Tag2, StaticMock2);
    
    TEST(Ecs, StaticOnStart)
    {
    	EXPECT_EQ(StaticMock<0>::initializeds, true);
    }
    
    TEST(Ecs, StaticOnEvent)
    {
    	EXPECT_NE(StaticMock1::initializeds, true);
    	mirage::event::enqueueEvent<Tag1>();
    	std::this_thread::sleep_for(std::chrono::milliseconds(
    		mirage::ecs::processing::EventDispatcherProcessing::updatePeriod * 2));
    	EXPECT_EQ(StaticMock1::initializeds, true);
    }
    
    TEST(Ecs, StaticWithEvent)
    {
    	EXPECT_NE(StaticMock2::initializeds, true);
    	mirage::event::enqueueEvent<Tag2>();
    	std::this_thread::sleep_for(std::chrono::milliseconds(
    		mirage::ecs::processing::EventDispatcherProcessing::updatePeriod * 2));
    	EXPECT_EQ(StaticMock2::initializeds, true);
    }

    kcalbCube, 29 Мая 2022

    Комментарии (0)