summaryrefslogtreecommitdiff
path: root/source/dphierarchies.cxx
blob: 2d0f67c643bdf4f7fc468ff2459515fe288f43af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

#include "dphierarchies.hxx"
#include "dphierarchy.hxx"
#include "global.hxx"

#include <com/sun/star/container/XNamed.hpp>

using ::com::sun::star::container::NoSuchElementException;
using ::com::sun::star::container::XNameAccess;
using ::com::sun::star::container::XNamed;
using ::com::sun::star::lang::IndexOutOfBoundsException;
using ::com::sun::star::lang::WrappedTargetException;
using ::com::sun::star::uno::Any;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::RuntimeException;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::Type;
using ::rtl::OUString;


#include <stdio.h>
#include <string>
#include <sys/time.h>

namespace {

class StackPrinter
{
public:
    explicit StackPrinter(const char* msg) :
        msMsg(msg)
    {
        fprintf(stdout, "%s: --begin\n", msMsg.c_str());
        mfStartTime = getTime();
    }

    ~StackPrinter()
    {
        double fEndTime = getTime();
        fprintf(stdout, "%s: --end (duration: %g sec)\n", msMsg.c_str(), (fEndTime-mfStartTime));
    }

private:
    double getTime() const
    {
        timeval tv;
        gettimeofday(&tv, NULL);
        return tv.tv_sec + tv.tv_usec / 1000000.0;
    }

    ::std::string msMsg;
    double mfStartTime;
};

}

namespace dpsource {

DPHierarchies::DPHierarchies(DPDimension* pDim) :
    mpDim(pDim)
{
    init();
}

DPHierarchies::~DPHierarchies()
{
}

void DPHierarchies::init()
{
    maHierarchies.clear();

    // For now, only create a 'flat' hierarchy.
    OUString aName = OUString::createFromAscii("flat");
    Reference<XNamed> xFlatHier(new DPHierarchy(mpDim));
    xFlatHier->setName(aName);
    maHierarchies.insert(
        NamedObjMapType::value_type(aName, xFlatHier));
}

Any DPHierarchies::getByName(const OUString& aName) 
    throw (NoSuchElementException, WrappedTargetException, RuntimeException)
{
    StackPrinter __stack_printer__("dpsource/DPHierarchies::getByName");
    fprintf(stdout, "DPHierarchies::getByName:   name = '%s'\n", rtl::OUStringToOString(aName, RTL_TEXTENCODING_UTF8).getStr());
    NamedObjMapType::const_iterator itr = maHierarchies.find(aName);
    if (itr != maHierarchies.end())
    {
        Any any;
        any <<= itr->second;
        return any;
    }
    throw NoSuchElementException();
    return Any();
}

Sequence<OUString> DPHierarchies::getElementNames() throw (RuntimeException)
{
    Sequence<OUString> aNames(1);
    aNames[0] = OUString::createFromAscii("flat");
    return aNames;
}

sal_Bool DPHierarchies::hasByName(const OUString& aName) throw (RuntimeException)
{
    return maHierarchies.count(aName) > 0;
}

Type DPHierarchies::getElementType() throw (RuntimeException)
{
    return getCppuType(static_cast< Reference<XNamed>* >(NULL));
}

sal_Bool DPHierarchies::hasElements() throw (RuntimeException)
{
    return !maHierarchies.empty();
}

sal_Int32 DPHierarchies::getCount() throw (RuntimeException)
{
    return maHierarchies.size();
}

Any DPHierarchies::getByIndex(sal_Int32 nIndex) 
    throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
{
    StackPrinter __stack_printer__("dpsource/DPHierarchies::getByIndex");
    return Any();
}

}