-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creating a stub for all public interface functions
creating some global utilities for core and a few creation stubs DEBUG define for debug builds reuse default_int as a way to index SETSTR variables
- Loading branch information
1 parent
cf770ad
commit 84eb267
Showing
14 changed files
with
708 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,103 @@ | ||
// core.cpp | ||
// high level central operation of core functions | ||
// High level central operation of core functions. | ||
// Implementation of NSFCore members. | ||
// Global utilities. | ||
|
||
#include "core.h" | ||
#include "enums_data.h" | ||
|
||
#include <cstdio> // std::fprintf, std::vsnprintf, stdout, stderr | ||
#include <cstdlib> // std::malloc, std::free, std::exit | ||
#include <cstring> // std:;memset, std::memcpy | ||
#include <cstdarg> // va_list, va_start | ||
|
||
namespace nsfp { | ||
|
||
void (*debug_print_callback)(const char* msg) = NULL; | ||
void (*fatal_callback)(const char* msg) = NULL; | ||
|
||
void* alloc(size_t size) | ||
{ | ||
void* a = std::malloc(size); | ||
if (a == NULL) nsfp::fatal("Out of memory."); | ||
NSFP_DEBUG("alloc(%z)=%p",size,a); | ||
return a; | ||
} | ||
|
||
void free(void* ptr) | ||
{ | ||
NSFP_DEBUG("free(%p)",ptr); | ||
std::free(ptr); | ||
} | ||
|
||
void debug(const char* msg) | ||
{ | ||
if (debug_print_callback) debug_print_callback(msg); | ||
else std::fprintf(stdout,"%s\n",msg); | ||
} | ||
|
||
void debug_printf(const char* fmt,...) | ||
{ | ||
#ifdef DEBUG | ||
static char msg[1024]; | ||
va_list args; | ||
va_start(args,fmt); | ||
std::vsnprintf(msg,sizeof(msg),msg,args); | ||
#else | ||
(void)fmt; | ||
#endif | ||
} | ||
|
||
void fatal(const char* msg) | ||
{ | ||
if (fatal_callback) fatal_callback(msg); | ||
std::fprintf(stderr,"%s\n",msg); | ||
std::exit(-1); | ||
} | ||
|
||
} // namespace nsfp | ||
|
||
NSFCore* NSFCore::create() | ||
{ | ||
NSFCore* core = (NSFCore*)nsfp::alloc(sizeof(NSFCore)); | ||
NSFP_DEBUG("create()=%p",core); | ||
std::memset(core,0,sizeof(NSFCore)); | ||
core->set_default(); | ||
return core; | ||
} | ||
|
||
void NSFCore::destroy(NSFCore* core) | ||
{ | ||
NSFP_DEBUG("destroy(%p)",core); | ||
core->release(); | ||
nsfp::free(core); | ||
} | ||
|
||
void NSFCore::finalize() | ||
{ | ||
// TODO make any allocations needed based on the settings | ||
} | ||
|
||
void NSFCore::release() | ||
{ | ||
// TODO release any allocations | ||
} | ||
|
||
void NSFCore::set_default() | ||
{ | ||
// TODO | ||
} | ||
|
||
bool NSFCore::set_ini(const char* ini) | ||
{ | ||
(void)ini; | ||
// TODO | ||
return false; | ||
} | ||
|
||
bool NSFCore::set_init(const NSFSetInit* init) | ||
{ | ||
(void)init; | ||
// TODO | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.