summaryrefslogtreecommitdiff
path: root/Source/Kernel/Library
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-09-13 18:27:42 +0200
committerAlexis211 <alexis211@gmail.com>2009-09-13 18:27:42 +0200
commit668bbfdaea7e8cba8233ebffe2a9d46a66e257cd (patch)
treec698b0f1a0baa98f6a2ec6f7aa0d3bd97021f376 /Source/Kernel/Library
parent708765621ede3541037fb822cc032b9feb2ea43e (diff)
downloadMelon-668bbfdaea7e8cba8233ebffe2a9d46a66e257cd.tar.gz
Melon-668bbfdaea7e8cba8233ebffe2a9d46a66e257cd.zip
We now can navigate in the VFS using the integrated shell.
Diffstat (limited to 'Source/Kernel/Library')
-rw-r--r--Source/Kernel/Library/String.class.cpp16
-rw-r--r--Source/Kernel/Library/String.class.h18
-rw-r--r--Source/Kernel/Library/Vector.class.cpp29
-rw-r--r--Source/Kernel/Library/Vector.class.h4
4 files changed, 42 insertions, 25 deletions
diff --git a/Source/Kernel/Library/String.class.cpp b/Source/Kernel/Library/String.class.cpp
index b8e01d5..5ee216c 100644
--- a/Source/Kernel/Library/String.class.cpp
+++ b/Source/Kernel/Library/String.class.cpp
@@ -116,7 +116,7 @@ void String::operator= (const char* string) {
m_string[m_length] = 0;
}
-bool String::operator== (const String &other) {
+bool String::operator== (const String &other) const {
if (m_length != other.m_length) return false;
for (u32int i = 0; i < m_length; i++) {
if (m_string[i] != other.m_string[i]) return false;
@@ -124,7 +124,7 @@ bool String::operator== (const String &other) {
return true;
}
-bool String::operator== (const char* string) {
+bool String::operator== (const char* string) const {
if (m_length != WChar::utf8len(string)) return false;
int i = 0, l = strlen(string), c = 0;
WChar tmp;
@@ -181,22 +181,22 @@ String& String::operator+= (WChar other) {
return *this;
}
-String& String::operator+ (const String &other) { //Can be optimized
+String& String::operator+ (const String &other) const { //Can be optimized
String ret(*this);
return (ret += other);
}
-String& String::operator+ (const char* other) { //Can be optimized
+String& String::operator+ (const char* other) const { //Can be optimized
String ret(*this);
return (ret += other);
}
-String& String::operator+ (WChar other) {
+String& String::operator+ (WChar other) const {
String ret(*this);
return (ret += other);
}
-s32int String::toInt() {
+s32int String::toInt() const {
if (m_string == 0) return 0;
s32int pos = 0, number = 0;
bool negative = false;
@@ -213,7 +213,7 @@ s32int String::toInt() {
return number;
}
-u32int String::toInt16() {
+u32int String::toInt16() const {
if (m_string == 0) return 0;
u32int pos = 0, number = 0;
if (m_string[0].value == '0' && m_string[1].value == 'x') pos = 2;
@@ -254,7 +254,7 @@ bool String::empty() const {
return (m_length == 0);
}
-Vector<String> String::split(WChar c) {
+Vector<String> String::split(WChar c) const {
Vector<String> ret;
ret.push(String(""));
for (u32int i = 0; i < m_length; i++) {
diff --git a/Source/Kernel/Library/String.class.h b/Source/Kernel/Library/String.class.h
index 6b48a30..01cc6a8 100644
--- a/Source/Kernel/Library/String.class.h
+++ b/Source/Kernel/Library/String.class.h
@@ -23,23 +23,25 @@ class String {
void operator= (const String &other);
void operator= (const char* string);
- bool operator== (const String &other);
- bool operator== (const char* string);
+ bool operator== (const String &other) const;
+ bool operator== (const char* string) const;
+ bool operator!= (const String &other) { return !(operator== (other)); }
+ bool operator!= (const char* other) { return !(operator== (other)); }
String &operator+= (const String &other);
String &operator+= (const char* other);
String &operator+= (WChar other);
- String &operator+ (const String &other);
- String &operator+ (const char* other);
- String &operator+ (WChar other);
- s32int toInt();
- u32int toInt16(); //From HEX
+ String &operator+ (const String &other) const;
+ String &operator+ (const char* other) const;
+ String &operator+ (WChar other) const;
+ s32int toInt() const;
+ u32int toInt16() const; //From HEX
WChar& operator[] (int index) const;
u32int size() const;
void clear();
bool empty() const;
- Vector<String> split(WChar c);
+ Vector<String> split(WChar c) const;
String substr(s32int start, s32int size);
};
diff --git a/Source/Kernel/Library/Vector.class.cpp b/Source/Kernel/Library/Vector.class.cpp
index 91196b8..8b032ca 100644
--- a/Source/Kernel/Library/Vector.class.cpp
+++ b/Source/Kernel/Library/Vector.class.cpp
@@ -1,5 +1,12 @@
using namespace CMem; //strlen and memcpy
+#define DELDATA if (m_data != NULL and m_size != 0) { \
+ for (u32int i = 0; i < m_size; i++) { \
+ m_data[i].~T(); \
+ } \
+ Mem::kfree(m_data); \
+}
+
template <typename T>
Vector<T>::Vector() {
//DEBUG_HEX((u32int)this); DEBUG(" NEW EMPTY");
@@ -16,11 +23,14 @@ Vector<T>::Vector(u32int size) {
}
template <typename T>
-Vector<T>::Vector(u32int size, T value) {
+Vector<T>::Vector(u32int size, const T& value) {
//DEBUG_HEX((u32int)this); DEBUG(" NEW FILLED");
//m_data = (T*)Mem::kalloc(size * sizeof(T));
- m_data = new T[size](value);
+ m_data = new T[size];
m_size = size;
+ for (u32int i = 0; i < m_size; i++) {
+ new (&m_data[i]) T(value);
+ }
/*for (u32int i = 0; i < size; i++) {
m_data[i] = new(&m_data[i]) T(value);
}*/
@@ -39,18 +49,20 @@ Vector<T>::Vector(const Vector<T> &other) {
template <typename T>
Vector<T>& Vector<T>::operator= (const Vector<T> &other) {
//DEBUG_HEX((u32int)this); DEBUG(" COPY EQ");
- if (m_data != 0) delete[] m_data;
+ DELDATA;
m_size = other.m_size;
m_data = (T*)Mem::kalloc(m_size * sizeof(T));
for (u32int i = 0; i < m_size; i++) {
new(&m_data[i]) T(other.m_data[i]);
}
+ return *this;
}
template <typename T>
Vector<T>::~Vector() {
//DEBUG_HEX((u32int)this); DEBUG(" DELETE");
- if (m_data != 0) delete[] m_data;
+ DELDATA;
+ //if (m_data != 0) delete[] m_data;
}
template <typename T>
@@ -59,10 +71,13 @@ T& Vector<T>::operator[] (u32int index) {
}
template <typename T>
-void Vector<T>::push(T element) {
+void Vector<T>::push(const T& element) {
T* newdata = (T*)Mem::kalloc((m_size + 1) * sizeof(T));
- memcpy((u8int*)newdata, (const u8int*) m_data, m_size * sizeof(T));
+ if (m_size != 0 and m_data != 0) {
+ memcpy((u8int*)newdata, (const u8int*) m_data, m_size * sizeof(T));
+ }
new(&newdata[m_size]) T(element); //Construct by copy
+ //newdata[m_size] = element;
m_size++;
Mem::kfree(m_data);
m_data = newdata;
@@ -114,7 +129,7 @@ bool Vector<T>::empty() {
template <typename T>
void Vector<T>::clear() {
if (empty()) return;
- delete [] m_data;
+ DELDATA
m_data = 0;
m_size = 0;
}
diff --git a/Source/Kernel/Library/Vector.class.h b/Source/Kernel/Library/Vector.class.h
index f16303b..ca86c2a 100644
--- a/Source/Kernel/Library/Vector.class.h
+++ b/Source/Kernel/Library/Vector.class.h
@@ -12,14 +12,14 @@ class Vector {
public:
Vector();
Vector(u32int size);
- Vector(u32int size, T value);
+ Vector(u32int size, const T& value);
Vector(const Vector<T> &other);
Vector<T>& operator= (const Vector<T> &other);
~Vector();
T& operator[] (u32int index);
- void push(T element);
+ void push(const T& element);
//void push(T& element);
void pop();