What does MOZ_ASSERT(static_cast<> == reinterpret_cast<>) do? - c++

I saw a bunch of code in Firefox written like static_cast<>(obj) == reinterpret_cast<>(obj); anyone could help here for why the developers writing so?
bool
Wrap(JSContext* aCx, mozilla::dom::LegacyMozTCPSocket* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
{
MOZ_ASSERT(static_cast<mozilla::dom::LegacyMozTCPSocket*>(aObject) ==
reinterpret_cast<mozilla::dom::LegacyMozTCPSocket*>(aObject),
"Multiple inheritance for mozilla::dom::LegacyMozTCPSocket is broken.");
...
}

Related

Using Json.cpp in Cocos2dx v4

https://github.com/cocos2d/cocos2d-x/blob/v4/cocos/editor-support/spine/Json.cpp
I need help loading a .txt and pulling out some text using cocos for an old App. Can anyone work up a simple example?
The backstory is that I wrote a working app about 5-6 years ago when cocos used a different json library. They changed the library and I can't decipher the new one enough to get it working again. I am not a programmer, but made the app as a favor for a hospital. The json is used to switch between languages for the script. I don't really even know how to ask a technical question about the library. I know the code is all there, but I don't know how to make it work...
Thanks :)
cocos2dx v4 Json implementation
This is what I figured out eventually. Any improvements you can suggest are welcome.
I use this to read json-response from a translation api:
std::vector<char> * buffer = response->getResponseData();
char * concatenated = (char *) malloc(buffer->size() + 1);
std::string s2(buffer->begin(), buffer->end());
strcpy(concatenated, s2.c_str());
CCLOG ("DEBUG |%s|", concatenated);
Json * json = Json_create(concatenated);
Json *responseData = Json_getItem(json, "responseData");
const char * var22 = Json_getString(responseData, "translatedText", "default");
USED JSON response
{"responseData":
{"translatedText":"ni\u00f1o"}, .....
and copyed the old json.c and json.h in my classes dir.
static void readCurve (Json* frame, spCurveTimeline* timeline, int frameIndex) {
Json* curve = Json_getItem(frame, "curve");
if (!curve) return;
if (curve->type == Json_String && strcmp(curve->valueString, "stepped") == 0)
spCurveTimeline_setStepped(timeline, frameIndex);
else if (curve->type == Json_Array) {
Json* child0 = curve->child;
Json* child1 = child0->next;
Json* child2 = child1->next;
Json* child3 = child2->next;
spCurveTimeline_setCurve(timeline, frameIndex, child0->valueFloat, child1->valueFloat, child2->valueFloat,
child3->valueFloat);
}
}

VivoxCore for Unreal Engine 4

Has anyone used VivoxCore for unreal engine 4 and know what this error means? I'm not able to really understand what this means. I've tried reading through the source code for vivox, as well as the documentation and that error code (1105) is mentioned nowhere. Also, the company which makes this does not respond to emails, and their public forum is not active. I've tried calling them, emailing them, using the public forum, reading online for answers, and I've found nothing, so stackoverflow is my last option. I hope someone here can help me.
LogVivoxVoiceChat: Warning: onConnectFailed server:https://vdx5.www.vivox.com/api2 error:SIP Backend Required (1105)
Here is my code:
VoiceChat = (FVivoxVoiceChat*)FVivoxVoiceChat::Get();
if (!VoiceChat->IsInitialized())
{
GLog->Log("Is not initialized, trying to initialize.");
VoiceChat->Initialize();
return;
}
if (!VoiceChat->IsConnected())
{
GLog->Log("Is not connected, trying to connect.");
VoiceChat->Connect(FOnVoiceChatConnectCompleteDelegate::CreateLambda([](const FVoiceChatResult& Result)
{
}));
return;
}
FString PlayerName = PlayerState->GetPlayerName();
FString LoginToken = VoiceChat->InsecureGetLoginToken(PlayerName);
if (!VoiceChat->IsLoggedIn())
{
GLog->Log("Is not logged in, trying to login.");
VoiceChat->Login(0, PlayerName, LoginToken, FOnVoiceChatLoginCompleteDelegate::CreateLambda([](const FString& LoggedInPlayerName, const FVoiceChatResult& Result)
{
}));
return;
}
FString ChannelName = "TestChannel";
EVoiceChatChannelType ChannelType = EVoiceChatChannelType::Echo; // Echo for testing.
TOptional<FVoiceChatChannel3dProperties> Channel3dProperties;
FString JoinToken = VoiceChat->InsecureGetJoinToken(ChannelName, ChannelType, Channel3dProperties);
VoiceChat->JoinChannel(ChannelName, JoinToken, ChannelType, FOnVoiceChatChannelJoinCompleteDelegate::CreateLambda([](const FString& JoinedChannelName, const FVoiceChatResult& Result)
{
GLog->Log("JOin Channel successful");
}), Channel3dProperties);
VoiceChat->TransmitToSpecificChannel(ChannelName);
This error means that you have an outdated SDK. The SDK included in UE4 is outdated: it is using backend version 4, but the actual version is 5.
Try disabling the Vivox Interface plugin if it's enabled.

Prettier putting if statement on one line

Prettier formats if statement without curley braces into one line.
This means that this :
function getErrorMessage(response) {
let errorMessage = null;
if (!response.originalError.response)
errorMessage = 'network error';
else
errorMessage = response.originalError.response.data.errorMessage;
return errorMessage;
}
becomes this :
function getErrorMessage(response) {
let errorMessage = null;
if (!response.originalError.response) errorMessage = 'network error';
else errorMessage = response.originalError.response.data.errorMessage;
return errorMessage;
}
which is FAR more unreadable.
Is there a way of disabling this?
As asked in a similar question, it turns out that the answer is that you can not and will not be able to.
As for the WFT that an average senses, well... Apparently, opinionated doesn't mean respected and well-considered in opinion of many. It means that it's implementing the author's opinion.
So, surprisingly, the unexpected thing isn't the lack of configurability but rather that there are any options to be set at all! Go figure... Someone should create a new package called EvenPrettier or FexiblyPrettier and fork in more options. If I only knew how, I'd do it.
I finally ended up using Beautify - HookyQR extension for vscode
https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify
Example Settings
File: .jsbeautifyrc
{
"brace_style": "collapse,preserve-inline",
"max_preserve_newlines": 2,
"end_with_newline": false
}
Example Code
File: a.js
function dfs(start) {
if (start > n)
return;
ans.push(start);
for (let i = 0; i <= 9; i++)
dfs(start * 10 + i);
}

How do I make an interactive command line interface?

I am trying to write a tool to compare my files but I found it difficult to interactive with. I want to support 2 operations: 1) load my files into memory 2) compare the files already loaded.
The idea is like below
while (true) {
getline(&line, &linesize, stdin);
if (strlen(line) < 2) continue;
token = strtok(line, DELIM);
if (!strcmp(token,"load")) {
puts("you want to load something");
} else if (!strcmp(token, "compare")) {
puts("you want to compare something");
} else if (!strcmp(token, "exit")) {
puts("exiting...");
exit(1);
} else {
puts("Cannot parse, try again");
}
}
In terminal, if I want to compare some MyVeryLongFileNameFile.foo and AnotherVeryLongFileNameFile.bar, I can just type diff My\tab Ano\tab \enter and it will auto completes the filenames for me.
I would like to also have these kind of features in my program, like using tab to autocomplete, using up/down to choose from previous commands, etc. How should I achieve this?
Using the ncurses.h library help you accomplish this.

Gtksourceviewmm syntax highlighting not working

I'm trying to use the C++ wrapper gtksourceview, I made this a long time ago and I remember that it was working, but now everything works except the higlight syntax. And I'm not pretty sure what it is. I hope you can help me, I read a lot about this library on internet but I can find a solution. Here is a simple code. Thanks in advance.
#include "twindow.h"
#include <iostream>
TWindow::TWindow() {
add(m_SourceView);
m_SourceView.set_size_request(640, 480);
m_SourceView.set_show_line_numbers();
m_SourceView.set_tab_width(4);
m_SourceView.set_auto_indent();
m_SourceView.set_show_right_margin();
m_SourceView.set_right_margin_position(80);
m_SourceView.set_highlight_current_line();
m_SourceView.set_smart_home_end(gtksourceview::SOURCE_SMART_HOME_END_ALWAYS);
gtksourceview::init ();
Glib::RefPtr<gtksourceview::SourceBuffer> buffer = m_SourceView.get_source_buffer () ;
if (!buffer) {
std::cerr << "gtksourceview::SourceView::get_source_buffer () failed" << std::endl ;
}
buffer->begin_not_undoable_action();
buffer->set_text(Glib::file_get_contents("main.c"));
buffer->end_not_undoable_action();
buffer->set_highlight_syntax(true);
Glib::RefPtr<gtksourceview::SourceLanguageManager> language_manager = gtksourceview::SourceLanguageManager::create();
Glib::RefPtr<gtksourceview::SourceLanguage> language = gtksourceview::SourceLanguage::create();
language = language_manager->get_language("c");
buffer->set_language(language);
show_all_children();
}
So you want to use the c++ wrapper of gtksourceview, so I guess you want to use gtksourceviewmm.
Why you create the LanguageManager, you can use the default one.
If you using 3.2 of gtksourceviewmm, then look at the docs.
You should also check out this function.
So an example would look like;
Glib::ustring file_path = "/home/user/whatever/main.c";
Glib::RefPtr<Gsv::LanguageManager> language_manager = Gsv::LanguageManager::get_default();
Glib::RefPtr<Gsv::Language> language = language_manager->guess_language(file_path, Glib::ustring());
Another thing I want to mention is that you should create a buffer to show the content of the file, as in my projects I got a seg fault when I wanted to use get_source_buffer(), so it seems to be null by default.
Glib::RefPtr<Gsv::Buffer> buffer = Gsv::Buffer::create(language);
buffer->set_text(Glib::get_file_contents(file_path));
this->m_SourceView.set_source_buffer(buffer);