You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/03/02 08:28:33 UTC
svn commit: r1296069 - in /incubator/etch/trunk/binding-cpp/runtime:
include/util/EtchResources.h src/main/util/EtchResources.cpp
src/test/util/EtchResourcesTest.cpp
Author: veithm
Date: Fri Mar 2 07:28:32 2012
New Revision: 1296069
URL: http://svn.apache.org/viewvc?rev=1296069&view=rev
Log:
ETCH-174 EtchResources Implementation Improvement of EtchResources
Change-Id: I19092b4fc7507f970b0b229a7696cacad68e07fc
Modified:
incubator/etch/trunk/binding-cpp/runtime/include/util/EtchResources.h
incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchResources.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchResourcesTest.cpp
Modified: incubator/etch/trunk/binding-cpp/runtime/include/util/EtchResources.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/util/EtchResources.h?rev=1296069&r1=1296068&r2=1296069&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/util/EtchResources.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/util/EtchResources.h Fri Mar 2 07:28:32 2012
@@ -23,7 +23,6 @@
#include "capu/util/SmartPointer.h"
#include "common/EtchString.h"
-
class EtchResources {
public:
@@ -33,6 +32,12 @@ public:
EtchResources();
/**
+ * Constructs the Resources.
+ * @param related another EtchResources which has
+ */
+ EtchResources(EtchResources * related);
+
+ /**
* Destructor
*/
~EtchResources();
@@ -43,7 +48,7 @@ public:
* @return true if this Resources has the key
* false otherwise.
*/
- capu::bool_t containsKey(const EtchString& key);
+ capu::bool_t containsKey(EtchString& key);
/**
* Returns the named resource from this Resources
@@ -52,7 +57,7 @@ public:
* @return a pointer to the object with given key
* if there is no element with given key return a NULL pointer
*/
- status_t get(const EtchString& key, EtchObject** result);
+ status_t get(EtchString& key, EtchObject*& result);
/**
* Puts the named resource into this Resources.
@@ -61,7 +66,7 @@ public:
* @return a pointer to the overwritten element
* if there is no existing element with same key returns a NULL pointer
*/
- status_t put(const EtchString& key, EtchObject *value, EtchObject** result);
+ status_t put(EtchString& key, EtchObject *value, EtchObject*& result);
/**
* Removes the named resource from this Resources only.
@@ -69,10 +74,15 @@ public:
* @return a pointer to the removed element
* if there is no element with given key return a NULL pointer
*/
- status_t remove(const EtchString& key, EtchObject** result);
+ status_t remove(EtchString& key, EtchObject*& result);
+ /**
+ * @return related EtchResources
+ */
+ EtchResources* getRelated();
private:
+ EtchResources *mRelated;
EtchHashTable <EtchString, EtchObject*> res;
};
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchResources.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchResources.cpp?rev=1296069&r1=1296068&r2=1296069&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchResources.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/util/EtchResources.cpp Fri Mar 2 07:28:32 2012
@@ -18,7 +18,13 @@
#include "util/EtchResources.h"
-EtchResources::EtchResources() {
+EtchResources::EtchResources()
+: mRelated(NULL) {
+
+}
+
+EtchResources::EtchResources(EtchResources * related)
+: mRelated(related) {
}
@@ -26,23 +32,42 @@ EtchResources::~EtchResources() {
}
-capu::bool_t EtchResources::containsKey(const EtchString& key) {
+capu::bool_t EtchResources::containsKey(EtchString& key) {
EtchObject* ptr = NULL;
if (res.get(key, &ptr) == ETCH_OK)
return true;
- else
+ else {
+ if (mRelated == NULL)
+ return false;
+
+ if (mRelated->containsKey(key) == ETCH_OK) {
+ return true;
+ }
return false;
+ }
}
-status_t EtchResources::get(const EtchString& key, EtchObject** result) {
- return res.get(key, result);
+status_t EtchResources::get(EtchString& key, EtchObject*& result) {
+ if (res.get(key, &result) != ETCH_OK) {
+
+ if (mRelated == NULL)
+ return ETCH_ENOT_EXIST;
+ if (mRelated->get(key, result) == ETCH_OK)
+ return ETCH_OK;
+ return ETCH_ENOT_EXIST;
+ }
+ return ETCH_OK;
}
-status_t EtchResources::put(const EtchString& key, EtchObject* value, EtchObject** result) {
- return res.put(key, value, result);
+status_t EtchResources::put(EtchString& key, EtchObject* value, EtchObject*& result) {
+ return res.put(key, value, &result);
}
-status_t EtchResources::remove(const EtchString& key, EtchObject** result) {
+status_t EtchResources::remove(EtchString& key, EtchObject*& result) {
- return res.remove(key, result);
+ return res.remove(key, &result);
}
+
+EtchResources* EtchResources::getRelated() {
+ return mRelated;
+}
\ No newline at end of file
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchResourcesTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchResourcesTest.cpp?rev=1296069&r1=1296068&r2=1296069&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchResourcesTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/util/EtchResourcesTest.cpp Fri Mar 2 07:28:32 2012
@@ -35,10 +35,10 @@ TEST(EtchResources, putTest) {
EtchString key1("key1");
EtchString key2("key2");
- EXPECT_TRUE(res->put(key1, &value1, &result) == ETCH_OK);
- EXPECT_TRUE(res->put(key2, &value2, &result) == ETCH_OK);
+ EXPECT_TRUE(res->put(key1, &value1, result) == ETCH_OK);
+ EXPECT_TRUE(res->put(key2, &value2, result) == ETCH_OK);
- res->put(key2, &value1, &result);
+ res->put(key2, &value1, result);
EXPECT_TRUE(((EtchFloat*) result)->get() == 12.1f);
delete res;
}
@@ -52,18 +52,18 @@ TEST(EtchResources, getTest) {
EtchString key1("key1");
EtchString key2("key2");
- EXPECT_TRUE(res->put(key1, &value1, &result) == ETCH_OK);
- EXPECT_TRUE(res->put(key2, &value2, &result) == ETCH_OK);
+ EXPECT_TRUE(res->put(key1, &value1, result) == ETCH_OK);
+ EXPECT_TRUE(res->put(key2, &value2, result) == ETCH_OK);
EtchObject* ptr1;
- EXPECT_TRUE(res->get(key1, &ptr1) == ETCH_OK);
+ EXPECT_TRUE(res->get(key1, ptr1) == ETCH_OK);
EtchObject* ptr2;
- EXPECT_TRUE(res->get(key2, &ptr2) == ETCH_OK);
+ EXPECT_TRUE(res->get(key2, ptr2) == ETCH_OK);
EXPECT_TRUE(((EtchInt32*) ptr1)->get() == 12);
EXPECT_TRUE(((EtchFloat*) ptr2)->get() == 12.1f);
- EXPECT_TRUE(res->put(key2, &value1, &result) == ETCH_OK);
+ EXPECT_TRUE(res->put(key2, &value1, result) == ETCH_OK);
EXPECT_TRUE(((EtchFloat*) result)->get() == 12.1f);
delete res;
}
@@ -78,8 +78,8 @@ TEST(EtchResources, containsKeyTest) {
EtchString key2("key2");
EtchString key3("key3");
- EXPECT_TRUE(res->put(key1, &value1, &result) == ETCH_OK);
- EXPECT_TRUE(res->put(key2, &value2, &result) == ETCH_OK);
+ EXPECT_TRUE(res->put(key1, &value1, result) == ETCH_OK);
+ EXPECT_TRUE(res->put(key2, &value2, result) == ETCH_OK);
EXPECT_TRUE(res->containsKey(key1) == true);
EXPECT_TRUE(res->containsKey(key2) == true);
@@ -97,12 +97,12 @@ TEST(EtchResources, removeTest) {
EtchString key1("key1");
EtchString key2("key2");
- EXPECT_TRUE(res->put(key1, &value1, &result) == ETCH_OK);
- EXPECT_TRUE(res->put(key2, &value2, &result) == ETCH_OK);
+ EXPECT_TRUE(res->put(key1, &value1, result) == ETCH_OK);
+ EXPECT_TRUE(res->put(key2, &value2, result) == ETCH_OK);
EtchObject* ptr1;
EtchObject* ptr2;
- EXPECT_TRUE(res->remove(key1, &ptr1) == ETCH_OK);
- EXPECT_TRUE(res->remove(key2, &ptr2) == ETCH_OK);
+ EXPECT_TRUE(res->remove(key1, ptr1) == ETCH_OK);
+ EXPECT_TRUE(res->remove(key2, ptr2) == ETCH_OK);
EXPECT_TRUE(((EtchInt32*) ptr1)->get() == 12);
EXPECT_TRUE(((EtchFloat*) ptr2)->get() == 12.1f);