Use correct namespace

This commit is contained in:
Baptiste Wicht 2013-12-22 19:24:43 +01:00
parent 1e2bd865ff
commit c0679aedab
15 changed files with 101 additions and 79 deletions

View File

@ -33,12 +33,12 @@ void k_print(uint64_t number);
void k_printf(const char* fmt, ...);
template<typename... Arguments>
typename enable_if<(sizeof...(Arguments) == 0), void>::type k_print_line(const Arguments&... args){
typename std::enable_if<(sizeof...(Arguments) == 0), void>::type k_print_line(const Arguments&... args){
k_print('\n');
}
template<typename... Arguments>
typename enable_if<(sizeof...(Arguments) > 0), void>::type k_print_line(const Arguments&... args){
typename std::enable_if<(sizeof...(Arguments) > 0), void>::type k_print_line(const Arguments&... args){
k_print(args...);
k_print('\n');
}

View File

@ -58,12 +58,12 @@ const char* disk_type_to_string(disk_type type);
const char* partition_type_to_string(partition_type type);
bool read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t count, void* destination);
unique_heap_array<partition_descriptor> partitions(const disk_descriptor& disk);
std::unique_heap_array<partition_descriptor> partitions(const disk_descriptor& disk);
bool partition_exists(const disk_descriptor& disk, uint64_t uuid);
void mount(const disk_descriptor& disk, uint64_t uuid);
void unmount();
vector<file> ls();
std::vector<file> ls();
uint64_t free_size();
std::string read_file(const std::string& file);
@ -71,8 +71,8 @@ std::string read_file(const std::string& file);
const disk_descriptor* mounted_disk();
const partition_descriptor* mounted_partition();
//TODO It is not a really good practice to directly expose the vector
vector<std::string>& current_directory();
//TODO It is not a really good practice to directly expose the std::vector
std::vector<std::string>& current_directory();
}

View File

@ -18,8 +18,8 @@ namespace fat32 {
typedef const disks::disk_descriptor& dd;
uint64_t free_size(dd disk, const disks::partition_descriptor& partition);
vector<disks::file> ls(dd disk, const disks::partition_descriptor& partition, const vector<std::string>& path);
std::string read_file(dd disk, const disks::partition_descriptor& partition, const vector<std::string>& path, const std::string& file);
std::vector<disks::file> ls(dd disk, const disks::partition_descriptor& partition, const std::vector<std::string>& path);
std::string read_file(dd disk, const disks::partition_descriptor& partition, const std::vector<std::string>& path, const std::string& file);
}

View File

@ -8,7 +8,7 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "thor.hpp"
namespace std {
template<typename T, uint64_t N>
class array {
@ -137,4 +137,6 @@ public:
}
};
} //end of namespace std
#endif

View File

@ -8,6 +8,8 @@
#ifndef ENABLE_IF_H
#define ENABLE_IF_H
namespace std {
template<bool B, class T = void>
struct enable_if {};
@ -20,4 +22,6 @@ struct disable_if {};
template<class T>
struct disable_if<false, T> { typedef T type; };
} //end of namespace std
#endif

View File

@ -10,6 +10,8 @@
#include "algorithms.hpp"
namespace std {
struct dummy_t {};
template<typename T>
@ -80,4 +82,6 @@ public:
}
};
} //end of namespace std
#endif

View File

@ -8,6 +8,8 @@
#ifndef PAIR_H
#define PAIR_H
namespace std {
template<typename T1, typename T2>
class pair {
public:
@ -66,4 +68,6 @@ inline constexpr pair<T1, T2> make_pair(T1&& x, T2&& y){
return pair<T1, T2>(std::forward<T1>(x), std::forward<T2>(y));
}
} //end of namespace std
#endif

View File

@ -10,6 +10,8 @@
#include "thor.hpp"
namespace std {
template<typename T>
struct default_delete {
default_delete() {}
@ -100,4 +102,6 @@ public:
}
};
} //end of namespace std
#endif

View File

@ -11,6 +11,8 @@
#include "stl/types.hpp"
#include "stl/algorithms.hpp"
namespace std {
template<typename T>
class vector {
public:
@ -126,4 +128,6 @@ public:
}
};
} //end of namespace std
#endif

View File

@ -11,6 +11,6 @@
#include "stl/string.hpp"
#include "stl/vector.hpp"
void sysinfo_command(const vector<std::string>& params);
void sysinfo_command(const std::vector<std::string>& params);
#endif

View File

@ -18,7 +18,7 @@
namespace {
//For now, 4 is enough as only the ata driver is implemented
array<disks::disk_descriptor, 4> _disks;
std::array<disks::disk_descriptor, 4> _disks;
uint64_t number_of_disks = 0;
@ -44,7 +44,7 @@ static_assert(sizeof(boot_record_t) == 512, "The boot record is 512 bytes long")
const disks::disk_descriptor* _mounted_disk;
const disks::partition_descriptor* _mounted_partition;
vector<std::string> pwd;
std::vector<std::string> pwd;
} //end of anonymous namespace
@ -122,8 +122,8 @@ bool disks::read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t co
}
}
unique_heap_array<disks::partition_descriptor> disks::partitions(const disk_descriptor& disk){
unique_ptr<boot_record_t> boot_record(new boot_record_t());
std::unique_heap_array<disks::partition_descriptor> disks::partitions(const disk_descriptor& disk){
std::unique_ptr<boot_record_t> boot_record(new boot_record_t());
if(!read_sectors(disk, 0, 1, boot_record.get())){
k_print_line("Read Boot Record failed");
@ -143,7 +143,7 @@ unique_heap_array<disks::partition_descriptor> disks::partitions(const disk_desc
}
}
unique_heap_array<partition_descriptor> partitions(n);
std::unique_heap_array<partition_descriptor> partitions(n);
uint64_t p = 0;
for(uint64_t i = 0; i < 4; ++i){
@ -210,7 +210,7 @@ const disks::partition_descriptor* disks::mounted_partition(){
return _mounted_partition;
}
vector<disks::file> disks::ls(){
std::vector<disks::file> disks::ls(){
if(!_mounted_disk || !_mounted_partition){
return {};
}
@ -226,7 +226,7 @@ uint64_t disks::free_size(){
return fat32::free_size(*_mounted_disk, *_mounted_partition);
}
vector<std::string>& disks::current_directory(){
std::vector<std::string>& disks::current_directory(){
return pwd;
}

View File

@ -85,7 +85,7 @@ fat_bs_t* fat_bs = nullptr;
fat_is_t* fat_is = nullptr;
void cache_bs(fat32::dd disk, const disks::partition_descriptor& partition){
unique_ptr<fat_bs_t> fat_bs_tmp(new fat_bs_t());
std::unique_ptr<fat_bs_t> fat_bs_tmp(new fat_bs_t());
if(read_sectors(disk, partition.start, 1, fat_bs_tmp.get())){
fat_bs = fat_bs_tmp.release();
@ -100,7 +100,7 @@ void cache_bs(fat32::dd disk, const disks::partition_descriptor& partition){
void cache_is(fat32::dd disk, const disks::partition_descriptor& partition){
auto fs_information_sector = partition.start + static_cast<uint64_t>(fat_bs->fs_information_sector);
unique_ptr<fat_is_t> fat_is_tmp(new fat_is_t());
std::unique_ptr<fat_is_t> fat_is_tmp(new fat_is_t());
if(read_sectors(disk, fs_information_sector, 1, fat_is_tmp.get())){
fat_is = fat_is_tmp.release();
@ -132,8 +132,8 @@ inline bool is_long_name(const cluster_entry& entry){
return entry.attrib == 0x0F;
}
vector<disks::file> files(const unique_heap_array<cluster_entry>& cluster){
vector<disks::file> files;
std::vector<disks::file> files(const std::unique_heap_array<cluster_entry>& cluster){
std::vector<disks::file> files;
bool end_reached = false;
@ -177,8 +177,8 @@ vector<disks::file> files(const unique_heap_array<cluster_entry>& cluster){
return std::move(files);
}
vector<disks::file> files(fat32::dd disk, uint64_t cluster_addr){
unique_heap_array<cluster_entry> cluster(16 * fat_bs->sectors_per_cluster);
std::vector<disks::file> files(fat32::dd disk, uint64_t cluster_addr){
std::unique_heap_array<cluster_entry> cluster(16 * fat_bs->sectors_per_cluster);
if(read_sectors(disk, cluster_lba(cluster_addr), fat_bs->sectors_per_cluster, cluster.get())){
return files(cluster);
@ -228,10 +228,10 @@ bool cache_disk_partition(fat32::dd disk, const disks::partition_descriptor& par
return fat_bs && fat_is;
}
pair<bool, unique_heap_array<cluster_entry>> find_cluster(fat32::dd disk, const vector<std::string>& path){
std::pair<bool, std::unique_heap_array<cluster_entry>> find_cluster(fat32::dd disk, const std::vector<std::string>& path){
auto cluster_addr = cluster_lba(fat_bs->root_directory_cluster_start);
unique_heap_array<cluster_entry> current_cluster(16 * fat_bs->sectors_per_cluster);
std::unique_heap_array<cluster_entry> current_cluster(16 * fat_bs->sectors_per_cluster);
if(read_sectors(disk, cluster_addr, fat_bs->sectors_per_cluster, current_cluster.get())){
for(auto& p : path){
@ -248,7 +248,7 @@ pair<bool, unique_heap_array<cluster_entry>> find_cluster(fat32::dd disk, const
//entry.name is not a real c_string, cannot be compared
//directly
if(filename_equals(entry.name, p)){
unique_heap_array<cluster_entry> cluster(16 * fat_bs->sectors_per_cluster);
std::unique_heap_array<cluster_entry> cluster(16 * fat_bs->sectors_per_cluster);
if(read_sectors(disk, cluster_lba(entry.cluster_low + (entry.cluster_high << 16)),
fat_bs->sectors_per_cluster, cluster.get())){
@ -257,7 +257,7 @@ pair<bool, unique_heap_array<cluster_entry>> find_cluster(fat32::dd disk, const
break;
} else {
return make_pair(false, unique_heap_array<cluster_entry>());
return std::make_pair(false, std::unique_heap_array<cluster_entry>());
}
}
}
@ -266,14 +266,14 @@ pair<bool, unique_heap_array<cluster_entry>> find_cluster(fat32::dd disk, const
if(!found){
//TODO If not end_reached, read the next cluster
return make_pair(false, unique_heap_array<cluster_entry>());
return std::make_pair(false, std::unique_heap_array<cluster_entry>());
}
}
return make_pair(true, std::move(current_cluster));
return std::make_pair(true, std::move(current_cluster));
}
return make_pair(false, unique_heap_array<cluster_entry>());
return std::make_pair(false, std::unique_heap_array<cluster_entry>());
}
} //end of anonymous namespace
@ -286,7 +286,7 @@ uint64_t fat32::free_size(dd disk, const disks::partition_descriptor& partition)
return fat_is->free_clusters * fat_bs->sectors_per_cluster * 512;
}
vector<disks::file> fat32::ls(dd disk, const disks::partition_descriptor& partition, const vector<std::string>& path){
std::vector<disks::file> fat32::ls(dd disk, const disks::partition_descriptor& partition, const std::vector<std::string>& path){
if(!cache_disk_partition(disk, partition)){
return {};
}
@ -300,7 +300,7 @@ vector<disks::file> fat32::ls(dd disk, const disks::partition_descriptor& partit
}
}
std::string fat32::read_file(dd disk, const disks::partition_descriptor& partition, const vector<std::string>& path, const std::string& file){
std::string fat32::read_file(dd disk, const disks::partition_descriptor& partition, const std::vector<std::string>& path, const std::string& file){
if(!cache_disk_partition(disk, partition)){
return {};
}
@ -321,7 +321,7 @@ std::string fat32::read_file(dd disk, const disks::partition_descriptor& partiti
if(entry_used(entry) && !is_long_name(entry) && !(entry.attrib & 0x10)){
if(filename_equals(entry.name, file)){
unique_heap_array<char> sector(512 * fat_bs->sectors_per_cluster);
std::unique_heap_array<char> sector(512 * fat_bs->sectors_per_cluster);
if(read_sectors(disk, cluster_lba(entry.cluster_low + (entry.cluster_high << 16)),
fat_bs->sectors_per_cluster, sector.get())){

View File

@ -32,37 +32,37 @@ static constexpr const bool History = true;
static constexpr const bool History = false;
#endif
vector<std::string> history;
std::vector<std::string> history;
uint64_t history_index = 0;
bool shift = false;
//Declarations of the different functions
void reboot_command(const vector<std::string>& params);
void help_command(const vector<std::string>& params);
void uptime_command(const vector<std::string>& params);
void clear_command(const vector<std::string>& params);
void date_command(const vector<std::string>& params);
void sleep_command(const vector<std::string>& params);
void echo_command(const vector<std::string>& params);
void mmap_command(const vector<std::string>& params);
void memory_command(const vector<std::string>& params);
void memorydebug_command(const vector<std::string>& params);
void disks_command(const vector<std::string>& params);
void partitions_command(const vector<std::string>& params);
void mount_command(const vector<std::string>& params);
void unmount_command(const vector<std::string>& params);
void ls_command(const vector<std::string>& params);
void cd_command(const vector<std::string>& params);
void pwd_command(const vector<std::string>& params);
void free_command(const vector<std::string>& params);
void cat_command(const vector<std::string>& params);
void shutdown_command(const vector<std::string>& params);
void reboot_command(const std::vector<std::string>& params);
void help_command(const std::vector<std::string>& params);
void uptime_command(const std::vector<std::string>& params);
void clear_command(const std::vector<std::string>& params);
void date_command(const std::vector<std::string>& params);
void sleep_command(const std::vector<std::string>& params);
void echo_command(const std::vector<std::string>& params);
void mmap_command(const std::vector<std::string>& params);
void memory_command(const std::vector<std::string>& params);
void memorydebug_command(const std::vector<std::string>& params);
void disks_command(const std::vector<std::string>& params);
void partitions_command(const std::vector<std::string>& params);
void mount_command(const std::vector<std::string>& params);
void unmount_command(const std::vector<std::string>& params);
void ls_command(const std::vector<std::string>& params);
void cd_command(const std::vector<std::string>& params);
void pwd_command(const std::vector<std::string>& params);
void free_command(const std::vector<std::string>& params);
void cat_command(const std::vector<std::string>& params);
void shutdown_command(const std::vector<std::string>& params);
struct command_definition {
const char* name;
void (*function)(const vector<std::string>&);
void (*function)(const std::vector<std::string>&);
};
command_definition commands[21] = {
@ -206,17 +206,17 @@ void exec_command(){
k_printf("The command \"%s\" does not exist\n", current_input.c_str());
}
void clear_command(const vector<std::string>&){
void clear_command(const std::vector<std::string>&){
wipeout();
}
void __attribute__((noreturn)) reboot_command(const vector<std::string>&){
void __attribute__((noreturn)) reboot_command(const std::vector<std::string>&){
__asm__ __volatile__("mov al, 0x64; or al, 0xFE; out 0x64, al; mov al, 0xFE; out 0x64, al; " : : );
__builtin_unreachable();
}
void help_command(const vector<std::string>&){
void help_command(const std::vector<std::string>&){
k_print("Available commands:\n");
for(auto& command : commands){
@ -225,7 +225,7 @@ void help_command(const vector<std::string>&){
}
}
void uptime_command(const vector<std::string>&){
void uptime_command(const std::vector<std::string>&){
k_printf("Uptime: %ds\n", timer_seconds());
}
@ -243,7 +243,7 @@ uint8_t get_RTC_register(int reg) {
return in_byte(cmos_data);
}
void date_command(const vector<std::string>&){
void date_command(const std::vector<std::string>&){
uint64_t second;
uint64_t minute;
uint64_t hour;
@ -321,11 +321,11 @@ void date_command(const vector<std::string>&){
k_printf("%d.%d.%d %d:%.2d:%.2d\n", day, month, year, hour, minute, second);
}
void sleep_command(const vector<std::string>& params){
void sleep_command(const std::vector<std::string>& params){
sleep_ms(parse(params[1]) * 1000);
}
void echo_command(const vector<std::string>& params){
void echo_command(const std::vector<std::string>& params){
for(uint64_t i = 1; i < params.size(); ++i){
k_print(params[i]);
k_print(' ');
@ -333,7 +333,7 @@ void echo_command(const vector<std::string>& params){
k_print_line();
}
void mmap_command(const vector<std::string>&){
void mmap_command(const std::vector<std::string>&){
if(e820::mmap_failed()){
k_print_line("The mmap was not correctly loaded from e820");
} else {
@ -349,7 +349,7 @@ void mmap_command(const vector<std::string>&){
}
}
void memory_command(const vector<std::string>&){
void memory_command(const std::vector<std::string>&){
if(e820::mmap_failed()){
k_print_line("The mmap was not correctly loaded from e820");
} else {
@ -360,11 +360,11 @@ void memory_command(const vector<std::string>&){
}
}
void memorydebug_command(const vector<std::string>&){
void memorydebug_command(const std::vector<std::string>&){
memory_debug();
}
void disks_command(const vector<std::string>&){
void disks_command(const std::vector<std::string>&){
k_print_line("UUID Type");
for(uint64_t i = 0; i < disks::detected_disks(); ++i){
@ -374,7 +374,7 @@ void disks_command(const vector<std::string>&){
}
}
void partitions_command(const vector<std::string>& params){
void partitions_command(const std::vector<std::string>& params){
auto uuid = parse(params[1]);
if(disks::disk_exists(uuid)){
@ -394,7 +394,7 @@ void partitions_command(const vector<std::string>& params){
}
}
void mount_command(const vector<std::string>& params){
void mount_command(const std::vector<std::string>& params){
if(params.size() == 1){
auto md = disks::mounted_disk();
auto mp = disks::mounted_partition();
@ -421,7 +421,7 @@ void mount_command(const vector<std::string>& params){
}
}
void unmount_command(const vector<std::string>& ){
void unmount_command(const std::vector<std::string>& ){
if(!disks::mounted_partition() || !disks::mounted_disk()){
k_print_line("Nothing is mounted");
@ -431,7 +431,7 @@ void unmount_command(const vector<std::string>& ){
disks::unmount();
}
void ls_command(const vector<std::string>& params){
void ls_command(const std::vector<std::string>& params){
if(!disks::mounted_partition() || !disks::mounted_disk()){
k_print_line("Nothing is mounted");
@ -477,7 +477,7 @@ void ls_command(const vector<std::string>& params){
}
}
void free_command(const vector<std::string>&){
void free_command(const std::vector<std::string>&){
if(!disks::mounted_partition() || !disks::mounted_disk()){
k_print_line("Nothing is mounted");
@ -487,7 +487,7 @@ void free_command(const vector<std::string>&){
k_printf("Free size: %m\n", disks::free_size());
}
void pwd_command(const vector<std::string>&){
void pwd_command(const std::vector<std::string>&){
if(!disks::mounted_partition() || !disks::mounted_disk()){
k_print_line("Nothing is mounted");
@ -506,7 +506,7 @@ void pwd_command(const vector<std::string>&){
k_print_line();
}
optional<disks::file> find_file(const std::string& name){
std::optional<disks::file> find_file(const std::string& name){
auto files = disks::ls();
for(auto& file : files){
@ -518,7 +518,7 @@ optional<disks::file> find_file(const std::string& name){
return {};
}
void cd_command(const vector<std::string>& params){
void cd_command(const std::vector<std::string>& params){
if(!disks::mounted_partition() || !disks::mounted_disk()){
k_print_line("Nothing is mounted");
@ -551,7 +551,7 @@ void cd_command(const vector<std::string>& params){
}
}
void cat_command(const vector<std::string>& params){
void cat_command(const std::vector<std::string>& params){
if(!disks::mounted_partition() || !disks::mounted_disk()){
k_print_line("Nothing is mounted");
@ -578,7 +578,7 @@ void cat_command(const vector<std::string>& params){
}
}
void shutdown_command(const vector<std::string>&){
void shutdown_command(const std::vector<std::string>&){
if(!acpi::init()){
k_print_line("Unable to init ACPI");
}

View File

@ -52,8 +52,8 @@ uint64_t std::str_len(const char* a){
return length;
}
vector<std::string> std::split(const string& s){
vector<string> parts;
std::vector<std::string> std::split(const string& s){
std::vector<string> parts;
string current(s.size());

View File

@ -341,7 +341,7 @@ void get_base_info(){
} //end of anonymous namespace
void sysinfo_command(const vector<std::string>&){
void sysinfo_command(const std::vector<std::string>&){
get_base_info();
get_vendor_id();
get_brand_string();